aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gunthorpe <jgg@nvidia.com>2024-02-20 14:43:54 -0400
committerJason Gunthorpe <jgg@nvidia.com>2024-02-21 09:25:02 -0400
commit7adc0c1cfa7732b81bf7bf2ed16ffb99719ceebf (patch)
tree27ced4f77aefbf4236a28c2e1a5696f0be7f416a
parent4bbcbc6ea2fa379632a24c14cfb47aa603816ac6 (diff)
downloadlinux-7adc0c1cfa7732b81bf7bf2ed16ffb99719ceebf.tar.gz
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") Link: https://lore.kernel.org/r/0-v1-9b1ea6869554+110c60-iommufd_ck_data_type_jgg@nvidia.com Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Notes
Fixes: bd529dbb661d ("iommufd: Add a nested HW pagetable object") # v6.7-rc1 Lore: https://lore.kernel.org/r/0-v1-9b1ea6869554+110c60-iommufd_ck_data_type_jgg@nvidia.com # linux-iommu, linux-patches Lore: https://lore.kernel.org/r/20240227131640.657548875@linuxfoundation.org # linux-patches, stable
-rw-r--r--drivers/iommu/iommufd/hw_pagetable.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c
index 3f3f1fa1a0a94..33d142f8057d7 100644
--- a/drivers/iommu/iommufd/hw_pagetable.c
+++ b/drivers/iommu/iommufd/hw_pagetable.c
@@ -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);