iommufd: viommu: free memory allocated by kvcalloc() using kvfree()
PATCH 1/1 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.
--- drivers/iommu/iommufd/viommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/iommufd/viommu.c +2 -2
@@ -339,7 +339,7 @@ iommufd_hw_queue_alloc_phys(struct iommu_hw_queue_alloc *cmd, } *base_pa = (page_to_pfn (pages[0 ]) <<PAGE_SHIFT ) + offset; -kfree (pages); +kvfree (pages);return access; out_unpin:
@@ -349,7 +349,7 @@ iommufd_hw_queue_alloc_phys(struct iommu_hw_queue_alloc *cmd, out_destroy:iommufd_access_destroy_internal (viommu->ictx, access); out_free: -kfree (pages); +kvfree (pages);return ERR_PTR (rc); }
Signature · 1 line
2.34.1
Quoted 7 lines · Akhilesh Patil
Use
kvfree()instead ofkfree()to free pages allocated bykvcalloc()iniommufs_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 2238ddc2b056 ("iommufd/viommu: Add IOMMUFD_CMD_HW_QUEUE_ALLOC ioctl")Signed-off-by Akhilesh Patil <[email protected]>
Thanks!
Quoted 11 lines
From: Akhilesh Patil <[email protected]>
Sent: Sunday, August 10, 2025 9:34 PMUse
kvfree()instead ofkfree()to free pages allocated bykvcalloc()iniommufs_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 2238ddc2b056 ("iommufd/viommu: Add
IOMMUFD_CMD_HW_QUEUE_ALLOCioctl")Signed-off-by Akhilesh Patil <[email protected]>
Quoted 7 lines · Akhilesh Patil
Use
kvfree()instead ofkfree()to free pages allocated bykvcalloc()iniommufs_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 2238ddc2b056 ("iommufd/viommu: Add IOMMUFD_CMD_HW_QUEUE_ALLOC ioctl")Signed-off-by Akhilesh Patil <[email protected]>
Thanks,
Praan
Quoted 4 lines
Use
kvfree()instead ofkfree()to free pages allocated bykvcalloc()iniommufs_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.
Will another bit of background information become helpful for an improved change description?
Test command example:
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> /usr/bin/spatch -D report scripts/coccinelle/api/kfree_mismatch.cocci drivers/iommu/iommufd/viommu.c …
Regards,
Markus
Quoted 7 lines · Markus Elfring
Quoted 4 lines
Use
kvfree()instead ofkfree()to free pages allocated bykvcalloc()iniommufs_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.Will another bit of background information become helpful for an improved change description?
No it will not. Please stop pointlessly nitpicking. A thing that is allocated with kv*alloc() must be freed with kvfree(); that alone is all that needs to be said to explain and justify any patch fixing this particular bug.
Thanks,
Robin.
Quoted 4 lines
Quoted 2 lines
Will another bit of background information become helpful for an improved change description?
No it will not. Please stop pointlessly nitpicking. …
Do you care for help and further influence of automatic source code analysis tools?
Regards,
Markus
Quoted 10 lines · Akhilesh Patil
Use
kvfree()instead ofkfree()to free pages allocated bykvcalloc()iniommufs_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 2238ddc2b056 ("iommufd/viommu: Add IOMMUFD_CMD_HW_QUEUE_ALLOC ioctl")Signed-off-by Akhilesh Patil <[email protected]>--- drivers/iommu/iommufd/viommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Applied to for-rc
Thanks,
Jason