From: sashiko-bot@kernel.org
To: "Stjepan Poljak" <stjepan.poljak@gmail.com>
Cc: virtualization@lists.linux.dev,
"Michael S. Tsirkin" <mst@redhat.com>,
"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH] virtio: Remove debugfs entries when device_add() fails
Date: Mon, 30 Nov 2026 19:24:21 +0000 [thread overview]
Message-ID: <sashiko-outbox-241907@kernel.org> (raw)
In-Reply-To: <20261130192040.1931044-1-stjepan.poljak@gmail.com>
> register_virtio_device() creates the device's debugfs directory before
> calling device_add(), but the device_add() error path does not remove
> it. The files in that directory keep the virtio device as their private
> data, and the caller is required to drop its reference with put_device()
> on failure, which frees the device. Reading any of the leftover files
> afterwards dereferences freed memory.
>
> The device index is also returned to the IDA, so the next device to
> reuse it fails to create its "virtioN" debugfs directory because the
> stale one still exists.
>
> Commit 3f9a0fceb730 ("virtio: fix use-after-free in
> unregister_virtio_device()") fixed the same kind of lifetime problem on
> the unregister side. Remove the debugfs entries on the device_add()
> failure path as well, before the caller can free the device.
>
> Reproduced on x86_64 with CONFIG_KASAN and CONFIG_VIRTIO_DEBUG by
> rebinding a virtio-mmio balloon device with fail-nth slab fault
> injection: once an allocation inside device_add() fails, the stale
> debugfs directory remains, and reading its device_features file
> triggers a slab-use-after-free in vm_get_features(). With this patch
> applied, no directory is left behind and no report occurs.
>
> Fixes: 96a8326d69ff ("virtio: add debugfs infrastructure to allow to debug virtio features")
> Cc: stable@vger.kernel.org
> Signed-off-by: Stjepan Poljak <stjepan.poljak@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130192040.1931044-1-stjepan.poljak@gmail.com?part=1
prev parent reply other threads:[~2026-11-30 19:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 19:20 [PATCH] virtio: Remove debugfs entries when device_add() fails Stjepan Poljak
2026-11-30 19:24 ` sashiko-bot [this message]
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=sashiko-outbox-241907@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=eperezma@redhat.com \
--cc=mst@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=stjepan.poljak@gmail.com \
--cc=virtualization@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