Skip to content

Commit d7be74e

Browse files
committed
iommufd: Fix struct iommu_hwpt_pgfault init and padding
JIRA: https://issues.redhat.com/browse/RHEL-75942 commit e721f61 Author: Nicolin Chen <nicolinc@nvidia.com> Date: Mon Jan 20 11:50:51 2025 -0800 iommufd: Fix struct iommu_hwpt_pgfault init and padding The iommu_hwpt_pgfault is used to report IO page fault data to userspace, but iommufd_fault_fops_read was never zeroing its padding. This leaks the content of the kernel stack memory to userspace. Also, the iommufd uAPI requires explicit padding and use of __aligned_u64 to ensure ABI compatibility's with 32 bit. pahole result, before: struct iommu_hwpt_pgfault { __u32 flags; /* 0 4 */ __u32 dev_id; /* 4 4 */ __u32 pasid; /* 8 4 */ __u32 grpid; /* 12 4 */ __u32 perm; /* 16 4 */ /* XXX 4 bytes hole, try to pack */ __u64 addr; /* 24 8 */ __u32 length; /* 32 4 */ __u32 cookie; /* 36 4 */ /* size: 40, cachelines: 1, members: 8 */ /* sum members: 36, holes: 1, sum holes: 4 */ /* last cacheline: 40 bytes */ }; pahole result, after: struct iommu_hwpt_pgfault { __u32 flags; /* 0 4 */ __u32 dev_id; /* 4 4 */ __u32 pasid; /* 8 4 */ __u32 grpid; /* 12 4 */ __u32 perm; /* 16 4 */ __u32 __reserved; /* 20 4 */ __u64 addr __attribute__((__aligned__(8))); /* 24 8 */ __u32 length; /* 32 4 */ __u32 cookie; /* 36 4 */ /* size: 40, cachelines: 1, members: 9 */ /* forced alignments: 1 */ /* last cacheline: 40 bytes */ } __attribute__((__aligned__(8))); Fixes: c714f15 ("iommufd: Add fault and response message definitions") Link: https://patch.msgid.link/r/20250120195051.2450-1-nicolinc@nvidia.com Cc: stable@vger.kernel.org Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Eder Zulian <ezulian@redhat.com>
1 parent 800194f commit d7be74e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

drivers/iommu/iommufd/fault.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static ssize_t iommufd_fault_fops_read(struct file *filep, char __user *buf,
258258
{
259259
size_t fault_size = sizeof(struct iommu_hwpt_pgfault);
260260
struct iommufd_fault *fault = filep->private_data;
261-
struct iommu_hwpt_pgfault data;
261+
struct iommu_hwpt_pgfault data = {};
262262
struct iommufd_device *idev;
263263
struct iopf_group *group;
264264
struct iopf_fault *iopf;

include/uapi/linux/iommufd.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ enum iommu_hwpt_pgfault_perm {
737737
* @pasid: Process Address Space ID
738738
* @grpid: Page Request Group Index
739739
* @perm: Combination of enum iommu_hwpt_pgfault_perm
740+
* @__reserved: Must be 0.
740741
* @addr: Fault address
741742
* @length: a hint of how much data the requestor is expecting to fetch. For
742743
* example, if the PRI initiator knows it is going to do a 10MB
@@ -752,7 +753,8 @@ struct iommu_hwpt_pgfault {
752753
__u32 pasid;
753754
__u32 grpid;
754755
__u32 perm;
755-
__u64 addr;
756+
__u32 __reserved;
757+
__aligned_u64 addr;
756758
__u32 length;
757759
__u32 cookie;
758760
};

0 commit comments

Comments
 (0)