All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommufd: viommu: free memory allocated by kvcalloc() using kvfree()
@ 2025-08-10 13:34 Akhilesh Patil
  2025-08-10 17:53 ` Nicolin Chen
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Akhilesh Patil @ 2025-08-10 13:34 UTC (permalink / raw)
  To: jgg, kevin.tian, joro, will, robin.murphy, praan, baolu.lu,
	nicolinc, jgg
  Cc: iommu, linux-kernel, akhileshpatilvnit, skhan

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: 2238ddc2b056 ("iommufd/viommu: Add IOMMUFD_CMD_HW_QUEUE_ALLOC ioctl")
Signed-off-by: Akhilesh Patil <akhilesh@ee.iitb.ac.in>
---
 drivers/iommu/iommufd/viommu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c
index 2ca5809b238b..462b457ffd0c 100644
--- a/drivers/iommu/iommufd/viommu.c
+++ b/drivers/iommu/iommufd/viommu.c
@@ -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);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-08-18 14:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-10 13:34 [PATCH] iommufd: viommu: free memory allocated by kvcalloc() using kvfree() Akhilesh Patil
2025-08-10 17:53 ` Nicolin Chen
2025-08-15 10:06 ` Tian, Kevin
2025-08-15 10:45 ` Pranjal Shrivastava
2025-08-15 13:42 ` Markus Elfring
2025-08-15 14:15   ` Robin Murphy
2025-08-15 14:52     ` Markus Elfring
2025-08-18 14:14 ` Jason Gunthorpe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.