]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iommufd: Rewind header length in done if iommufd_veventq_fops_read() fails
authorNicolin Chen <nicolinc@nvidia.com>
Mon, 1 Jun 2026 20:42:32 +0000 (13:42 -0700)
committerJason Gunthorpe <jgg@nvidia.com>
Fri, 5 Jun 2026 14:07:11 +0000 (11:07 -0300)
When the first event copy fails, rc = -EFAULT will not be reported as done
is set to the length of the copied header.

Rewind it to report rc correctly.

Fixes: e36ba5ab808e ("iommufd: Add IOMMUFD_OBJ_VEVENTQ and IOMMUFD_CMD_VEVENTQ_ALLOC")
Link: https://patch.msgid.link/r/78f8caeb6a5d667a26b870e3068cec47dd4b5be1.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 1f1e415285b1a0722b452ae7172dc7b497c07e6c..896f45be0d2eef19e085eb72a46a3dab38947fa9 100644 (file)
@@ -336,6 +336,7 @@ static ssize_t iommufd_veventq_fops_read(struct file *filep, char __user *buf,
                if (cur->data_len &&
                    copy_to_user(buf + done, cur->event_data, cur->data_len)) {
                        iommufd_veventq_deliver_restore(veventq, cur);
+                       done -= sizeof(*hdr);
                        rc = -EFAULT;
                        break;
                }