Linux IOMMU Development
 help / color / mirror / Atom feed
* [PATCH] iommu: Honor iommufd uapi for zero entry_num args
@ 2026-09-02 12:43 Pranjal Shrivastava
  2026-09-02 15:13 ` Nicolin Chen
  0 siblings, 1 reply; 3+ messages in thread
From: Pranjal Shrivastava @ 2026-09-02 12:43 UTC (permalink / raw)
  To: iommu
  Cc: Joerg Roedel, Will Deacon, Jason Gunthorpe, Kevin Tian,
	Nicolin Chen, Samiullah Khawaja, Peter Shier, Pranjal Shrivastava

The IOMMU_HWPT_INVALIDATE ioctl uAPI explicitly allows an empty
invalidation request array by setting entry_num == 0. The uAPI
documentation in include/uapi/linux/iommufd.h mentions:

  " An empty invalidation request array by setting @entry_num==0
    is allowed, and @entry_len and @data_uptr would be ignored in
    this case."

While the core iommufd_hwpt_invalidate() handler honors this by
skipping its bounds checks, the generic array copy helper
iommu_copy_struct_from_full_user_array() incorrectly rejects it
by returning -EINVAL, breaking the uAPI.

Fix this by returning 0 instead of -EINVAL when entry_num is 0.

Fixes: 4f2e59ccb698 ("iommu: Add iommu_copy_struct_from_full_user_array helper")
Signed-off-by: Pranjal Shrivastava <praan@google.com>
---
 include/linux/iommu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index ac43b8b93f14..cf16f9649645 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -569,7 +569,7 @@ iommu_copy_struct_from_full_user_array(void *kdst, size_t kdst_entry_size,
 	if (user_array->type != data_type)
 		return -EINVAL;
 	if (!user_array->entry_num)
-		return -EINVAL;
+		return 0;
 	if (likely(user_array->entry_len == kdst_entry_size)) {
 		if (copy_from_user(kdst, user_array->uptr,
 				   user_array->entry_num *
-- 
2.55.0.966.g6673acef38-goog


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

end of thread, other threads:[~2026-09-02 16:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-02 12:43 [PATCH] iommu: Honor iommufd uapi for zero entry_num args Pranjal Shrivastava
2026-09-02 15:13 ` Nicolin Chen
2026-09-02 16:04   ` Pranjal Shrivastava

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox