]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iommufd: Propagate allocation failure in iommufd_veventq_deliver_fetch()
authorNicolin Chen <nicolinc@nvidia.com>
Mon, 1 Jun 2026 20:42:34 +0000 (13:42 -0700)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 5 Jun 2026 14:07:12 +0000 (11:07 -0300)
When the kzalloc_obj() fails in iommufd_veventq_deliver_fetch(), it returns
NULL, falsely advertising to userspace that the queue is empty.

Propagate the -ENOMEM properly to the caller.

Fixes: e36ba5ab808e ("iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC")
Link: https://patch.msgid.link/r/25d29feac909e36f78c145fa99ef2d4cb7a415da.1780343944.git.nicolinc@nvidia.com
Cc: stable@vger.kernel.org
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Pranjal Shrivastava <praan@google.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/iommufd/eventq.c

index ac485d010a439c84954b8de66184626e40ba643b..f55d173c59f6141b23506a896131d0333fcf1b23 100644 (file)
@@ -264,8 +264,10 @@ iommufd_veventq_deliver_fetch(struct iommufd_veventq *veventq)
                /* Make a copy of the lost_events_header for copy_to_user */
                if (next == &veventq->lost_events_header) {
                        vevent = kzalloc_obj(*vevent, GFP_ATOMIC);
-                       if (!vevent)
+                       if (!vevent) {
+                               vevent = ERR_PTR(-ENOMEM);
                                goto out_unlock;
+                       }
                }
                list_del(&next->node);
                if (vevent)
@@ -315,6 +317,12 @@ static ssize_t iommufd_veventq_fops_read(struct file *filep, char __user *buf,
                return -EINVAL;
 
        while ((cur = iommufd_veventq_deliver_fetch(veventq))) {
+               if (IS_ERR(cur)) {
+                       if (done == 0)
+                               rc = PTR_ERR(cur);
+                       break;
+               }
+
                /* Validate the remaining bytes against the header size */
                if (done >= count || sizeof(*hdr) > count - done) {
                        iommufd_veventq_deliver_restore(veventq, cur);