Skip to content

Commit b80fab2

Browse files
committed
iommufd/selftest: Do not leak the hwpt if IOMMU_TEST_OP_MD_CHECK_MAP fails
If the input validation fails it returned without freeing the hwpt refcount causing a leak. This triggers a WARN_ON when closing the fd: WARNING: drivers/iommu/iommufd/main.c:369 at iommufd_fops_release+0x385/0x430, CPU#1: repro/724 Found by szykaller. Fixes: e93d594 ("iommufd: Change the selftest to use iommupt instead of xarray") Link: https://patch.msgid.link/r/0-v1-c8ed57e24380+44ae-iommufd_selftest_hwpt_leak_jgg@nvidia.com Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com> Reported-by: "Lai, Yi" <yi1.lai@linux.intel.com> Closes: https://lore.kernel.org/r/aTJGMaqwQK0ASj0G@ly-workstation Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 5b244b0 commit b80fab2

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
@@ -1215,8 +1215,10 @@ static int iommufd_test_md_check_pa(struct iommufd_ucmd *ucmd,
12151215
page_size = 1 << __ffs(mock->domain.pgsize_bitmap);
12161216
if (iova % page_size || length % page_size ||
12171217
(uintptr_t)uptr % page_size ||
1218-
check_add_overflow((uintptr_t)uptr, (uintptr_t)length, &end))
1219-
return -EINVAL;
1218+
check_add_overflow((uintptr_t)uptr, (uintptr_t)length, &end)) {
1219+
rc = -EINVAL;
1220+
goto out_put;
1221+
}
12201222

12211223
for (; length; length -= page_size) {
12221224
struct page *pages[1];

0 commit comments

Comments
 (0)