Skip to contentSkip to conversation

iommufd: Reject non-zero data_type if no data_len is provided

PATCH In review Jason Gunthorpe 2 participants 3 messages Feb 20, 2024 – Feb 21, 2024

Subsystems (2)
lore
Share & tools
lore

Jason Gunthorpe

author maintainer
#0 lore raw

PATCH 1/1 iommufd: Reject non-zero data_type if no data_len is provided

Since the current design doesn't forward the data_type to the driver to check unless there is a data_len/uptr for a driver specific struct we should check and ensure that data_type is 0 if data_len is 0. Otherwise any value is permitted.

Fixes bd529dbb661d ("iommufd: Add a nested HW pagetable object")
---
 drivers/iommu/iommufd/hw_pagetable.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iommu/iommufd/hw_pagetable.c +2 -1
index 3f3f1fa1a0a946..33d142f8057d70 100644
@@ -263,7 +263,8 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd)
 
 	if (cmd->__reserved)
 		return -EOPNOTSUPP;
-	if (cmd->data_type == IOMMU_HWPT_DATA_NONE && cmd->data_len)
+	if ((cmd->data_type == IOMMU_HWPT_DATA_NONE && cmd->data_len) ||
+	    (cmd->data_type != IOMMU_HWPT_DATA_NONE && !cmd->data_len))
 		return -EINVAL;
 
 	idev = iommufd_get_device(ucmd, cmd->dev_id);

base-commit: 4bbcbc6ea2fa379632a24c14cfb47aa603816ac6

Signature · 1 line
2.43.2
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines

From: Jason Gunthorpe <[email protected]>
Sent: Wednesday, February 21, 2024 2:44 AM

Since the current design doesn't forward the data_type to the driver to check unless there is a data_len/uptr for a driver specific struct we should check and ensure that data_type is 0 if data_len is 0. Otherwise any value is permitted.

Fixes bd529dbb661d ("iommufd: Add a nested HW pagetable object")
author maintainer Applied
#2 lore raw
Quoted 8 lines · Kevin
Quoted 8 lines

From: Jason Gunthorpe <[email protected]>
Sent: Wednesday, February 21, 2024 2:44 AM

Since the current design doesn't forward the data_type to the driver to check unless there is a data_len/uptr for a driver specific struct we should check and ensure that data_type is 0 if data_len is 0. Otherwise any value is permitted.

Quoted 4 lines
Quoted 2 lines
Fixes bd529dbb661d ("iommufd: Add a nested HW pagetable object")

Applied to for-rc

Jason