Skip to content

Commit 2e22aac

Browse files
jpemartinsjgunthorpe
authored andcommitted
iommufd/selftest: Fix page-size check in iommufd_test_dirty()
iommufd_test_dirty()/IOMMU_TEST_OP_DIRTY sets the dirty bits in the mock domain implementation that the userspace side validates against what it obtains via the UAPI. However in introducing iommufd_test_dirty() it forgot to validate page_size being 0 leading to two possible divide-by-zero problems: one at the beginning when calculating @max and while calculating the IOVA in the XArray PFN tracking list. While at it, validate the length to require non-zero value as well, as we can't be allocating a 0-sized bitmap. Link: https://lore.kernel.org/r/20231030113446.7056-1-joao.m.martins@oracle.com Reported-by: syzbot+25dc7383c30ecdc83c38@syzkaller.appspotmail.com Closes: https://lore.kernel.org/linux-iommu/00000000000005f6aa0608b9220f@google.com/ Fixes: a9af47e ("iommufd/selftest: Test IOMMU_HWPT_GET_DIRTY_BITMAP") Signed-off-by: Joao Martins <joao.m.martins@oracle.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 361d744 commit 2e22aac

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

drivers/iommu/iommufd/selftest.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,14 +1195,15 @@ static int iommufd_test_dirty(struct iommufd_ucmd *ucmd, unsigned int mockpt_id,
11951195
unsigned long page_size, void __user *uptr,
11961196
u32 flags)
11971197
{
1198-
unsigned long bitmap_size, i, max = length / page_size;
1198+
unsigned long bitmap_size, i, max;
11991199
struct iommu_test_cmd *cmd = ucmd->cmd;
12001200
struct iommufd_hw_pagetable *hwpt;
12011201
struct mock_iommu_domain *mock;
12021202
int rc, count = 0;
12031203
void *tmp;
12041204

1205-
if (iova % page_size || length % page_size || !uptr)
1205+
if (!page_size || !length || iova % page_size || length % page_size ||
1206+
!uptr)
12061207
return -EINVAL;
12071208

12081209
hwpt = get_md_pagetable(ucmd, mockpt_id, &mock);
@@ -1214,6 +1215,7 @@ static int iommufd_test_dirty(struct iommufd_ucmd *ucmd, unsigned int mockpt_id,
12141215
goto out_put;
12151216
}
12161217

1218+
max = length / page_size;
12171219
bitmap_size = max / BITS_PER_BYTE;
12181220

12191221
tmp = kvzalloc(bitmap_size, GFP_KERNEL_ACCOUNT);

0 commit comments

Comments
 (0)