Skip to content

Commit e721f61

Browse files
nicolincjgunthorpe
authored andcommitted
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/[email protected] Cc: [email protected] Reviewed-by: Jason Gunthorpe <[email protected]> Signed-off-by: Nicolin Chen <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 3d49020 commit e721f61

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
@@ -263,7 +263,7 @@ static ssize_t iommufd_fault_fops_read(struct file *filep, char __user *buf,
263263
{
264264
size_t fault_size = sizeof(struct iommu_hwpt_pgfault);
265265
struct iommufd_fault *fault = filep->private_data;
266-
struct iommu_hwpt_pgfault data;
266+
struct iommu_hwpt_pgfault data = {};
267267
struct iommufd_device *idev;
268268
struct iopf_group *group;
269269
struct iopf_fault *iopf;

include/uapi/linux/iommufd.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ enum iommu_hwpt_pgfault_perm {
868868
* @pasid: Process Address Space ID
869869
* @grpid: Page Request Group Index
870870
* @perm: Combination of enum iommu_hwpt_pgfault_perm
871+
* @__reserved: Must be 0.
871872
* @addr: Fault address
872873
* @length: a hint of how much data the requestor is expecting to fetch. For
873874
* example, if the PRI initiator knows it is going to do a 10MB
@@ -883,7 +884,8 @@ struct iommu_hwpt_pgfault {
883884
__u32 pasid;
884885
__u32 grpid;
885886
__u32 perm;
886-
__u64 addr;
887+
__u32 __reserved;
888+
__aligned_u64 addr;
887889
__u32 length;
888890
__u32 cookie;
889891
};

0 commit comments

Comments
 (0)