Skip to content

Commit 78b2381

Browse files
GustavoARSilvaawilliam
authored andcommitted
vfio/iommu_type1: Use struct_size() for kzalloc()
Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. This code was detected with the help of Coccinelle and, audited and fixed manually. Signed-off-by: Gustavo A. R. Silva <[email protected]> Message-Id: <20210513230155.GA217517@embeddedor> Signed-off-by: Alex Williamson <[email protected]>
1 parent 2a55ca3 commit 78b2381

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/vfio/vfio_iommu_type1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2795,7 +2795,7 @@ static int vfio_iommu_iova_build_caps(struct vfio_iommu *iommu,
27952795
return 0;
27962796
}
27972797

2798-
size = sizeof(*cap_iovas) + (iovas * sizeof(*cap_iovas->iova_ranges));
2798+
size = struct_size(cap_iovas, iova_ranges, iovas);
27992799

28002800
cap_iovas = kzalloc(size, GFP_KERNEL);
28012801
if (!cap_iovas)

0 commit comments

Comments
 (0)