Skip to content

Commit 79ea4a4

Browse files
committed
iommufd/selftest: Fix buffer read overrrun in the dirty test
test_bit() is used to read the memory storing the bitmap, however test_bit() always uses a unsigned long 8 byte access. If the bitmap is not an aligned size of 64 bits this will now trigger a KASAN warning reading past the end of the buffer. Properly round the buffer allocation to an unsigned long size. Continue to copy_from_user() using a byte granularity. Fixes: 9560393 ("iommufd/selftest: Fix iommufd_test_dirty() to handle <u8 bitmaps") Link: https://patch.msgid.link/r/[email protected] Reviewed-by: Joao Martins <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 1d4684f commit 79ea4a4

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/iommu/iommufd/selftest.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ static int iommufd_test_dirty(struct iommufd_ucmd *ucmd, unsigned int mockpt_id,
13431343
unsigned long page_size, void __user *uptr,
13441344
u32 flags)
13451345
{
1346-
unsigned long bitmap_size, i, max;
1346+
unsigned long i, max;
13471347
struct iommu_test_cmd *cmd = ucmd->cmd;
13481348
struct iommufd_hw_pagetable *hwpt;
13491349
struct mock_iommu_domain *mock;
@@ -1364,15 +1364,14 @@ static int iommufd_test_dirty(struct iommufd_ucmd *ucmd, unsigned int mockpt_id,
13641364
}
13651365

13661366
max = length / page_size;
1367-
bitmap_size = DIV_ROUND_UP(max, BITS_PER_BYTE);
1368-
1369-
tmp = kvzalloc(bitmap_size, GFP_KERNEL_ACCOUNT);
1367+
tmp = kvzalloc(DIV_ROUND_UP(max, BITS_PER_LONG) * sizeof(unsigned long),
1368+
GFP_KERNEL_ACCOUNT);
13701369
if (!tmp) {
13711370
rc = -ENOMEM;
13721371
goto out_put;
13731372
}
13741373

1375-
if (copy_from_user(tmp, uptr, bitmap_size)) {
1374+
if (copy_from_user(tmp, uptr,DIV_ROUND_UP(max, BITS_PER_BYTE))) {
13761375
rc = -EFAULT;
13771376
goto out_free;
13781377
}

0 commit comments

Comments
 (0)