Skip to content

Commit 8fe8a09

Browse files
Akhilesh Patiljgunthorpe
authored andcommitted
iommufd: viommu: free memory allocated by kvcalloc() using kvfree()
Use kvfree() instead of kfree() to free pages allocated by kvcalloc() in iommufs_hw_queue_alloc_phys() to fix potential memory corruption. Ensure the memory is properly freed, as kvcalloc may internally use vmalloc or kmalloc depending on available memory in the system. Fixes: 2238ddc ("iommufd/viommu: Add IOMMUFD_CMD_HW_QUEUE_ALLOC ioctl") Link: https://patch.msgid.link/r/[email protected] Signed-off-by: Akhilesh Patil <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Nicolin Chen <[email protected]> Reviewed-by: Pranjal Shrivastava <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent c17b750 commit 8fe8a09

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/iommu/iommufd/viommu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ iommufd_hw_queue_alloc_phys(struct iommu_hw_queue_alloc *cmd,
339339
}
340340

341341
*base_pa = (page_to_pfn(pages[0]) << PAGE_SHIFT) + offset;
342-
kfree(pages);
342+
kvfree(pages);
343343
return access;
344344

345345
out_unpin:
@@ -349,7 +349,7 @@ iommufd_hw_queue_alloc_phys(struct iommu_hw_queue_alloc *cmd,
349349
out_destroy:
350350
iommufd_access_destroy_internal(viommu->ictx, access);
351351
out_free:
352-
kfree(pages);
352+
kvfree(pages);
353353
return ERR_PTR(rc);
354354
}
355355

0 commit comments

Comments
 (0)