mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 18:21:24 +02:00
iommufd: Propagate allocation failure in iommufd_veventq_deliver_fetch()
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: e36ba5ab80 ("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>
This commit is contained in:
parent
00203ca832
commit
489e63dd12
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user