Skip to content

Commit f565297

Browse files
nicolincgregkh
authored andcommitted
iommufd: Set veventq_depth upper bound
commit 6ebf2eb upstream. iommufd_veventq_alloc() accepts any !0 veventq_depth from userspace, with an upper bound at U32_MAX. This leaves a vulnerability where userspace can allocate excessively large queues to exhaust kernel memory reserves. Cap the veventq_depth (maximum number of entries) to 1 << 19, matching the maximum number of entries in the SMMUv3 EVTQ (the largest use case today). Fixes: e36ba5a ("iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC") Link: https://patch.msgid.link/r/8426cbaa5e8294472ec7f076ef427cc473be5985.1779408671.git.nicolinc@nvidia.com Cc: stable@vger.kernel.org Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5c5f1b5 commit f565297

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

drivers/iommu/iommufd/eventq.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,9 @@ int iommufd_fault_iopf_handler(struct iopf_group *group)
473473
static const struct file_operations iommufd_veventq_fops =
474474
INIT_EVENTQ_FOPS(iommufd_veventq_fops_read, NULL);
475475

476+
/* An arbitrary upper bound for veventq_depth that fits all existing HWs */
477+
#define VEVENTQ_MAX_DEPTH (1U << 19)
478+
476479
int iommufd_veventq_alloc(struct iommufd_ucmd *ucmd)
477480
{
478481
struct iommu_veventq_alloc *cmd = ucmd->cmd;
@@ -484,7 +487,7 @@ int iommufd_veventq_alloc(struct iommufd_ucmd *ucmd)
484487
if (cmd->flags || cmd->__reserved ||
485488
cmd->type == IOMMU_VEVENTQ_TYPE_DEFAULT)
486489
return -EOPNOTSUPP;
487-
if (!cmd->veventq_depth)
490+
if (!cmd->veventq_depth || cmd->veventq_depth > VEVENTQ_MAX_DEPTH)
488491
return -EINVAL;
489492

490493
viommu = iommufd_get_viommu(ucmd, cmd->viommu_id);

0 commit comments

Comments
 (0)