From: sashiko-bot@kernel.org
To: "Peiyang He" <peiyang_he@smail.nju.edu.cn>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/virtio: fix memory leak of fence event on execbuffer failure
Date: Tue, 08 Sep 2026 12:34:40 +0000 [thread overview]
Message-ID: <20260908123440.84D501F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <D320EAB5680C1411+20260908121323.2405044-1-peiyang_he@smail.nju.edu.cn>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] The return value of virtio_gpu_fence_alloc() is not checked for NULL, leading to a NULL pointer dereference on memory allocation failure.
- [High] Silent command submission failures ignore error returns, bypassing error cleanup and leaking memory, GEM object references, and the fence event.
--
commit 93a0baf42622f4c32d5d66c718e042ee250da557
Author: Peiyang He <peiyang_he@smail.nju.edu.cn>
drm/virtio: fix memory leak of fence event on execbuffer failure
This patch fixes a memory leak in the virtio GPU driver by cancelling
and freeing the DRM event on the execbuffer error path before dropping
the out-fence. It ensures the fence's event pointer is cleared after
cancellation to prevent dangling pointers.
> diff --git a/drivers/gpu/drm/virtio/virtgpu_submit.c b/drivers/gpu/drm/virtio/virtgpu_submit.c
> index 32cb1e4aa4258..734b1e976a75c 100644
> --- a/drivers/gpu/drm/virtio/virtgpu_submit.c
> +++ b/drivers/gpu/drm/virtio/virtgpu_submit.c
> @@ -538,6 +538,10 @@ int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
> virtio_gpu_process_post_deps(&submit);
> virtio_gpu_complete_submit(&submit);
[Severity: High]
This isn't a bug introduced by this patch, but does this code silently absorb
submission errors and leak resources?
In the current code just above this hunk, we have:
virtio_gpu_submit(&submit);
...
virtio_gpu_complete_submit(&submit);
cleanup:
If the underlying queue functions fail (e.g., vmalloc_to_sgt() returning
-ENOMEM in virtio_gpu_queue_fenced_ctrl_buffer()), they return an error code:
drivers/gpu/drm/virtio/virtgpu_vq.c:virtio_gpu_queue_fenced_ctrl_buffer() {
...
sgt = vmalloc_to_sgt(vbuf->data_buf, vbuf->data_size, &sg_ents);
if (!sgt) {
if (fence && vbuf->objs)
virtio_gpu_array_unlock_resv(vbuf->objs);
return -ENOMEM;
}
...
}
However, the wrapper functions like virtio_gpu_cmd_submit() return void,
dropping this error:
drivers/gpu/drm/virtio/virtgpu_vq.c:virtio_gpu_cmd_submit() {
...
virtio_gpu_queue_fenced_ctrl_buffer(vgdev, vbuf, fence);
}
Because the error is dropped, virtio_gpu_execbuffer_ioctl() proceeds as if
successful, calls virtio_gpu_complete_submit() to clear pointers, and
skips the error cleanup path.
Does this permanently leak GEM object references, memory buffers, and the
fence event when command submission fails under memory pressure?
[Severity: High]
This is another pre-existing issue, but is it possible for
virtio_gpu_fence_alloc() to fail and cause a NULL pointer dereference
earlier in the submission path?
Looking at virtio_gpu_init_submit() called earlier in this ioctl, it does
not check the return value of virtio_gpu_fence_alloc():
drivers/gpu/drm/virtio/virtgpu_submit.c:virtio_gpu_init_submit() {
...
out_fence = virtio_gpu_fence_alloc(vgdev, fence_ctx, ring_idx);
else
out_fence = NULL;
if (drm_fence_event) {
err = virtio_gpu_fence_event_create(dev, file, out_fence, ring_idx);
...
}
And in virtio_gpu_fence_event_create():
drivers/gpu/drm/virtio/virtgpu_submit.c:virtio_gpu_fence_event_create() {
...
fence->e = e;
...
}
If kzalloc_obj() inside virtio_gpu_fence_alloc() fails due to memory pressure,
it returns NULL, which is then unconditionally dereferenced.
Can unprivileged userspace trigger this by invoking the execbuffer ioctl
under constrained memory conditions?
> cleanup:
> + if (ret && submit.out_fence && submit.out_fence->e) {
> + drm_event_cancel_free(dev, &submit.out_fence->e->base);
> + submit.out_fence->e = NULL;
> + }
> virtio_gpu_cleanup_submit(&submit);
>
> return ret;
--
Sashiko AI review · https://sashiko.dev/#/patchset/D320EAB5680C1411+20260908121323.2405044-1-peiyang_he@smail.nju.edu.cn?part=1
next prev parent reply other threads:[~2026-09-08 12:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 12:13 [PATCH] drm/virtio: fix memory leak of fence event on execbuffer failure Peiyang He
2026-09-08 12:34 ` sashiko-bot [this message]
2026-09-09 3:42 ` Peiyang He
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260908123440.84D501F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=peiyang_he@smail.nju.edu.cn \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox