From: sashiko-bot@kernel.org
To: "Karl Mehltretter" <kmehltretter@gmail.com>
Cc: linux-s390@vger.kernel.org,
"Christian Borntraeger" <borntraeger@linux.ibm.com>,
"Heiko Carstens" <hca@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
kvm@vger.kernel.org, linux-input@vger.kernel.org,
dmitry.torokhov@gmail.com, "Vasily Gorbik" <gor@linux.ibm.com>
Subject: Re: [PATCH v2 2/3] virtio_input: stop callbacks before unregistering input device
Date: Sat, 05 Sep 2026 15:33:57 +0000 [thread overview]
Message-ID: <20260905153357.7FE5E1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260905152059.89560-3-kmehltretter@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing `virtio_reset_device()` in the error path of `virtinput_probe()` before deleting virtqueues, potentially leading to use-after-free or memory corruption by the active hardware/hypervisor.
- [High] The driver leaks DMA mappings for unconsumed buffers in the event virtqueue (`vi->evt`) upon device removal or suspend/freeze.
--
commit 71bbbcca0b03e3c67fa905a8357e9d3ad23e7fe4
Author: Karl Mehltretter <kmehltretter@gmail.com>
virtio_input: stop callbacks before unregistering input device
virtinput_remove() unregisters the input device before resetting the
virtio device. virtinput_recv_events() drops vi->lock around input_event(),
so clearing vi->ready does not stop a callback that passed the entry check.
It can still use vi->idev, requeue buffers and kick the queue.
> diff --git a/drivers/virtio/virtio_input.c b/drivers/virtio/virtio_input.c
> index deec24e8e6828..7b654af0a42cb 100644
> --- a/drivers/virtio/virtio_input.c
> +++ b/drivers/virtio/virtio_input.c
[ ... ]
> @@ -350,8 +353,9 @@ static void virtinput_remove(struct virtio_device *vdev)
> vi->ready = false;
> spin_unlock_irqrestore(&vi->lock, flags);
>
> - input_unregister_device(vi->idev);
> + /* Callbacks use vi->idev. */
> virtio_reset_device(vdev);
> + input_unregister_device(vi->idev);
> while ((buf = virtqueue_detach_unused_buf(vi->sts)) != NULL)
> kfree(buf);
> vdev->config->del_vqs(vdev);
[Severity: High]
This is a pre-existing issue, but does this cleanup leak DMA mappings for
the event virtqueue (vi->evt)?
The cleanup loop correctly detaches and unmaps vi->sts using
virtqueue_detach_unused_buf(), but it ignores vi->evt. Since
virtinput_fill_evt() populates vi->evt with buffers using
virtqueue_add_inbuf_cache_clean(), which establishes DMA mappings under
the hood, omitting the detachment step leaves these mappings active.
Does this result in a persistent DMA mapping leak every time the device is
unbound? Furthermore, since the memory for these buffers (vi->evts) is freed,
does this leave active DMA mappings pointing to freed memory, posing a memory
corruption risk if delayed DMA occurs?
Does this exact same DMA mapping leak also occur during the power management
suspend cycle in virtinput_freeze() which performs the same cleanup?
[Severity: High]
This is also a pre-existing issue, but is there a missing
virtio_reset_device() in the error path of virtinput_probe()?
Looking at virtinput_probe(), the device is marked as ready:
drivers/virtio/virtio_input.c:virtinput_probe() {
...
virtio_device_ready(vdev);
vi->ready = true;
err = input_register_device(vi->idev);
if (err)
goto err_input_register;
...
}
If input_register_device() fails, the error path deletes the virtqueues:
drivers/virtio/virtio_input.c:virtinput_probe() {
...
err_input_alloc:
vdev->config->del_vqs(vdev);
...
}
Since virtio_device_ready() sets the device status to DRIVER_OK and enables
the host/hardware to start processing virtqueues, does deleting the active
virtqueue structures without first calling virtio_reset_device() to halt
the device risk a use-after-free or memory corruption by the host backend
if it continues to access the freed vring memory?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260905152059.89560-1-kmehltretter@gmail.com?part=2
next prev parent reply other threads:[~2026-09-05 15:34 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-05 15:20 [PATCH v2 0/3] virtio: synchronize callbacks during device reset Karl Mehltretter
2026-09-05 15:20 ` [PATCH v2 1/3] " Karl Mehltretter
2026-09-05 15:35 ` sashiko-bot
2026-09-06 6:49 ` Michael S. Tsirkin
2026-09-07 21:36 ` Michael S. Tsirkin
2026-09-05 15:20 ` [PATCH v2 2/3] virtio_input: stop callbacks before unregistering input device Karl Mehltretter
2026-09-05 15:33 ` sashiko-bot [this message]
2026-09-07 21:19 ` Michael S. Tsirkin
2026-09-06 6:51 ` Michael S. Tsirkin
2026-09-07 21:46 ` Michael S. Tsirkin
2026-09-07 22:15 ` Karl Mehltretter
2026-09-07 22:22 ` Michael S. Tsirkin
2026-09-07 22:32 ` Karl Mehltretter
2026-09-05 15:20 ` [PATCH v2 3/3] virtio: implement synchronize_cbs for remaining transports Karl Mehltretter
2026-09-05 15:35 ` sashiko-bot
2026-09-06 18:59 ` Michael S. Tsirkin
2026-09-06 6:43 ` [PATCH v2 0/3] virtio: synchronize callbacks during device reset Michael S. Tsirkin
2026-09-06 6:53 ` Michael S. Tsirkin
2026-09-06 16:32 ` Karl Mehltretter
2026-09-06 18:56 ` Michael S. Tsirkin
2026-09-07 13:13 ` Michael S. Tsirkin
2026-09-07 21:23 ` Karl Mehltretter
2026-09-07 21:41 ` Michael S. Tsirkin
2026-09-11 12:39 ` Michael S. Tsirkin
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=20260905153357.7FE5E1F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=dmitry.torokhov@gmail.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=kmehltretter@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.