Re: [PATCH v6 3/3] iommufd: Add IOMMU_IOAS_RESERVE_IOVAS ioctl

From: Jason Gunthorpe

Date: Wed Nov 18 2026 - 14:18:22 EST


> [ ... 56 lines skipped ... ]
> @@ -183,6 +183,57 @@ int iommufd_ioas_allow_iovas(struct iommufd_ucmd *ucmd)
> return rc;
> }
>
> +int iommufd_ioas_reserve_iovas(struct iommufd_ucmd *ucmd)
> +{
> + struct iommu_ioas_reserve_iovas *cmd = ucmd->cmd;
> + struct iommu_iova_range __user *ranges;
> + struct iommufd_ioas *ioas;
> + u32 i;
> + int rc;
> +
> + if (cmd->flags)
> + return -EOPNOTSUPP;
> +
> + ioas = iommufd_get_ioas(ucmd->ictx, cmd->ioas_id);
> + if (IS_ERR(ioas))
> + return PTR_ERR(ioas);
> +
> + ranges = u64_to_user_ptr(cmd->ranges);
> +
> + down_write(&ioas->iopt.iova_rwsem);
> + for (i = 0; i < cmd->num_ranges; i++) {
> + struct iommu_iova_range range;
> +
> + rc = copy_from_user(&range, &ranges[i], sizeof(range));
> + if (rc) {
> + rc = -EFAULT;
> + goto out_unlock;
> + }
> + if (range.last < range.start) {
> + rc = -EINVAL;
> + goto out_unlock;
> + }
> + if (range.start >= ULONG_MAX || range.last >= ULONG_MAX) {
> + rc = -EOVERFLOW;
> + goto out_unlock;
> + }
[Severity: Medium]
Should the check in iommufd_ioas_reserve_iovas() in
drivers/iommu/iommufd/ioas.c use > ULONG_MAX instead of >= ULONG_MAX?

struct iommu_iova_range represents an inclusive [start, last] interval, and
iopt_reserve_iova() supports inclusive bounds up to ULONG_MAX, as seen in
drivers/iommu/iommufd/io_pagetable.c:iopt_table_add_domain():

if (geometry->aperture_end != ULONG_MAX) {
rc = iopt_reserve_iova(iopt, geometry->aperture_end + 1,
ULONG_MAX, domain);

The UAPI comment for struct iommu_ioas_reserve_iovas in
include/uapi/linux/iommufd.h also notes:

* A range with last < start fails with -EINVAL. On 32-bit kernels
* a range exceeding the native address width fails with -EOVERFLOW.

With >= ULONG_MAX, any range starting or ending at ULONG_MAX (such as a
32-bit PCI host bridge MMIO window ending at 0xffffffff on a 32-bit kernel,
or a reservation reaching U64_MAX on a 64-bit kernel) is rejected with
-EOVERFLOW.

Seems right, it should be > not >=, please send a V2.

Also, with this function I think you can remove the overlapping
selftest function IOMMU_TEST_OP_ADD_RESERVED as another patch. Then
you will have test coverage for this too.

The rest of the series looks OK to me, so send a v3 and I'll pick it
up

--
Jason