* [PULL 2/5] tests/9p: reduce xattr size to 1k
2026-07-25 11:05 [PULL 0/5] 9p queue 2026-07-25 Christian Schoenebeck
@ 2026-07-25 11:05 ` Christian Schoenebeck
2026-07-25 11:05 ` [PULL 4/5] hw/9pfs/virtio: drain in-flight PDUs before virtio-9p unrealize Christian Schoenebeck
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Christian Schoenebeck @ 2026-07-25 11:05 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-stable, Greg Kurz, Peter Maydell, Pierrick Bouvier
On host systems with ext4 and ea_inode capability not enabled, the max. size
for xattr values is slightly below 4k, which caused the new xattr tests to
fail on such host systems.
Reduce the xattr size for our tests to 1k to prevent them to fail on such
host systems.
Reported-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Fixes: 04a62cdfe8 ("tests/9p: add 3 xattr FID limit test cases (local fs driver)")
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Tested-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Link: https://lore.kernel.org/qemu-devel/E1wffqw-001Sc8-I9@kylie.crudebyte.com
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
tests/qtest/virtio-9p-test.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index 692a0e8e3f..22302bd2f8 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -38,11 +38,17 @@
/*
* xattr size to be used for xattr tests
*
- * 64k is the max. xattr size supported by the Linux kernel, However btrfs
- * for instance supports only 16219 bytes. So let's be conservative and
- * just use 8k for the xattr tests.
+ * 64k is the max. xattr size supported by the Linux kernel on high-level VFS
+ * layer. However filesystems impose their own limits:
+ *
+ * - btrfs: 16219 bytes
+ *
+ * - ext4: blocksize - 56 bytes (~4KB) if no ea_inode capability enabled,
+ * 64k if ea_inode enabled
+ *
+ * So let's be conservative and just use 1k for the xattr tests.
*/
-#define TEST_XATTR_SIZE (8 * 1024)
+#define TEST_XATTR_SIZE (1 * 1024)
static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc)
{
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PULL 4/5] hw/9pfs/virtio: drain in-flight PDUs before virtio-9p unrealize
2026-07-25 11:05 [PULL 0/5] 9p queue 2026-07-25 Christian Schoenebeck
2026-07-25 11:05 ` [PULL 2/5] tests/9p: reduce xattr size to 1k Christian Schoenebeck
@ 2026-07-25 11:05 ` Christian Schoenebeck
2026-07-25 11:05 ` [PULL 3/5] hw/9pfs: fix O_TRUNC bypass on read-only export Christian Schoenebeck
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Christian Schoenebeck @ 2026-07-25 11:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Greg Kurz, Peter Maydell,
Philippe Mathieu-Daudé, Jia Jia
From: Jia Jia <physicalmtea@gmail.com>
A guest can trigger a heap-use-after-free in the virtio transport
unrealize path by submitting a Treaddir request and immediately
ejecting the device via ACPI PCI hotplug. The unrealize path frees
struct LocalData while a worker thread still holds a reference
on it, causing a UAF in local_open_nofollow().
Fix this by draining all in-flight 9p PDUs by calling v9fs_reset()
before final server cleanup. This ensures all coroutines completed,
all FIDs are closed, and no worker thread still holds references
on 9p server state when it is freed.
Fixes: 6cecf09373 ("virtio-9p-device: add minimal unrealize handler")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3937
Signed-off-by: Jia Jia <physicalmtea@gmail.com>
[ Christian Schoenebeck: add commit log message. ]
Link: https://lore.kernel.org/qemu-devel/bc503aefffd20b1806941b3ef708afbd92f0aef2.1784809978.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
hw/9pfs/virtio-9p-device.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 50dc93091d..576a794ea4 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -243,6 +243,7 @@ static void virtio_9p_device_unrealize(DeviceState *dev)
V9fsVirtioState *v = VIRTIO_9P(dev);
V9fsState *s = &v->state;
+ v9fs_reset(s); /* cancel all in-flight PDUs to prevent UAF */
virtio_delete_queue(v->vq);
virtio_cleanup(vdev);
v9fs_device_unrealize_common(s);
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PULL 3/5] hw/9pfs: fix O_TRUNC bypass on read-only export
2026-07-25 11:05 [PULL 0/5] 9p queue 2026-07-25 Christian Schoenebeck
2026-07-25 11:05 ` [PULL 2/5] tests/9p: reduce xattr size to 1k Christian Schoenebeck
2026-07-25 11:05 ` [PULL 4/5] hw/9pfs/virtio: drain in-flight PDUs before virtio-9p unrealize Christian Schoenebeck
@ 2026-07-25 11:05 ` Christian Schoenebeck
2026-07-25 11:05 ` [PULL 1/5] tests/9p: prevent potential error in do_local_xattr_limit() Christian Schoenebeck
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Christian Schoenebeck @ 2026-07-25 11:05 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-stable, Greg Kurz, Peter Maydell, Daniel P. Berrangé
Guest 9p client opening a file with O_TRUNC on a read-only 9p file
system using 9p2000.u protocol version, allowed to bypass 9p
server's read-only check, eventually causing file(s) being
truncated to empty file(s) on host's read-only export.
Root cause is that 9p server's read-only check is using Linux open
flags like O_WRONLY, O_RDWR, O_TRUNC, but checking them against
the 9p Topen request's "mode" parameter, which has a different
encoding (Otrunc = 0x10 vs. O_TRUNC = 0x200).
Fix this by checking against the "flags" variable instead of the
protocol's "mode" option. Because the "flags" variable is already
converted to Linux encoding by omode_to_uflags() for 9p2000.u and
by get_dotl_openflags() for 9p2000.L protocol version.
Only 9p2000.u was affected by this bypass, 9p2000.L uses the Linux
format on protocol level already.
Fixes: 2c74c2cb4b ("hw/9pfs: Read-only support for 9p export")
Fixes: CVE-2026-63318
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4000
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Link: https://lore.kernel.org/qemu-devel/E1wk2Dq-0019kY-JK@kylie.crudebyte.com
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
hw/9pfs/9p.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 3119f01117..474ac6cc40 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -2181,8 +2181,8 @@ static void coroutine_fn v9fs_open(void *opaque)
flags = omode_to_uflags(mode);
}
if (is_ro_export(&s->ctx)) {
- if (mode & O_WRONLY || mode & O_RDWR ||
- mode & O_APPEND || mode & O_TRUNC) {
+ if (flags & O_WRONLY || flags & O_RDWR ||
+ flags & O_APPEND || flags & O_TRUNC) {
err = -EROFS;
goto out;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PULL 1/5] tests/9p: prevent potential error in do_local_xattr_limit()
2026-07-25 11:05 [PULL 0/5] 9p queue 2026-07-25 Christian Schoenebeck
` (2 preceding siblings ...)
2026-07-25 11:05 ` [PULL 3/5] hw/9pfs: fix O_TRUNC bypass on read-only export Christian Schoenebeck
@ 2026-07-25 11:05 ` Christian Schoenebeck
2026-07-25 11:05 ` [PULL 5/5] hw/9pfs/xen: drain in-flight PDUs before xen-9p disconnect Christian Schoenebeck
2026-07-26 19:45 ` [PULL 0/5] 9p queue 2026-07-25 Stefan Hajnoczi
5 siblings, 0 replies; 7+ messages in thread
From: Christian Schoenebeck @ 2026-07-25 11:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Greg Kurz, Peter Maydell,
Philippe Mathieu-Daudé, Pierrick Bouvier
The local fs backend driver tests require that a dummy file is
created on the host side before running the xattr limit tests,
otherwise the test will fail because the file is expected to exist.
The original call of g_file_set_contents() didn't check its
return value, which might cause subsequent test checks to fail,
making it harder to identify the root cause.
Fix this by simply wrapping the call into a g_assert().
Fixes: 04a62cdfe873 ("tests/9p: add 3 xattr FID limit test cases (local fs driver)")
CID: 1660926
Tested-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Link: https://lore.kernel.org/qemu-devel/E1wfg2F-001Sfn-Rr@kylie.crudebyte.com
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
tests/qtest/virtio-9p-test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index cfd3c02da4..692a0e8e3f 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -402,7 +402,7 @@ static void do_local_xattr_limit(QVirtio9P *v9p, int max_xattr)
/*
* this file must be created for the test to work with the 'local' fs driver
*/
- g_file_set_contents(test_file, "", 0, NULL);
+ g_assert(g_file_set_contents(test_file, "", 0, NULL));
/* the actual test code shared with the 'synth' fs driver tests */
do_xattr_limit(v9p, max_xattr, false);
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PULL 5/5] hw/9pfs/xen: drain in-flight PDUs before xen-9p disconnect
2026-07-25 11:05 [PULL 0/5] 9p queue 2026-07-25 Christian Schoenebeck
` (3 preceding siblings ...)
2026-07-25 11:05 ` [PULL 1/5] tests/9p: prevent potential error in do_local_xattr_limit() Christian Schoenebeck
@ 2026-07-25 11:05 ` Christian Schoenebeck
2026-07-26 19:45 ` [PULL 0/5] 9p queue 2026-07-25 Stefan Hajnoczi
5 siblings, 0 replies; 7+ messages in thread
From: Christian Schoenebeck @ 2026-07-25 11:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-stable, Greg Kurz, Peter Maydell,
Philippe Mathieu-Daudé, Stefano Stabellini
The xen-9p disconnect path has two issues:
1. It frees the Xen9pfsRing structures while in-flight PDUs may still
reference them via pdu->tag to index rings[]. This causes a UAF
in xen_9pfs_push_and_notify() when worker threads resume after
completing filesystem operations.
2. It never calls v9fs_device_unrealize_common(), which means server
state (struct LocalData, mountfd, FIDs) is never cleaned up on
disconnect, causing a resource leak on every guest-initiated
disconnect.
Fix both by draining in-flight PDUs via v9fs_reset() before tearing
down rings, and calling v9fs_device_unrealize_common() to clean up
server state.
Additionally, explicit calls of xen_9pfs_disconnect() in the error
paths of xen_9pfs_pdu_vmarshal() and xen_9pfs_pdu_vunmarshal() must
be deferred (via aio_bh_schedule_oneshot()), because
xen_9pfs_pdu_v(un)marshal() are running within a coroutine context
which makes them unsafe [1] for calling v9fs_reset() directly, as
the latter e.g. has a loop like:
while (!QLIST_EMPTY(&s->active_list)) {
aio_poll(qemu_get_aio_context(), true);
}
which would a) never terminate (as the coroutine is on the
active_list) and b) aio_poll() is marked as no_coroutine_fn.
[1] https://lore.kernel.org/qemu-devel/3351181.5fSG56mABF@weasel/
And finally, add an idempotent guard to xen_9pfs_disconnect()
for the v9fs_reset(s) and v9fs_device_unrealize_common(s) calls
specifically [2], just to be sure.
[2] https://lore.kernel.org/qemu-devel/alpine.DEB.2.22.394.2607221815520.5295@ubuntu-linux-20-04-desktop/
Fixes: b37eeb0201 ("xen/9pfs: introduce Xen 9pfs backend")
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Link: https://lore.kernel.org/qemu-devel/82bc736158e827e05d4b55da27c39d42e2062e96.1784809978.git.qemu_oss@crudebyte.com
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
---
hw/9pfs/9p.c | 1 +
hw/9pfs/xen-9p-backend.c | 17 +++++++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 474ac6cc40..1c61e6b3e7 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -4530,6 +4530,7 @@ void v9fs_device_unrealize_common(V9fsState *s)
qp_table_destroy(&s->qpp_table);
qp_table_destroy(&s->qpf_table);
g_free(s->ctx.fs_root);
+ s->transport = NULL;
}
typedef struct VirtfsCoResetData {
diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c
index 24c90d97ec..d44fa8d61e 100644
--- a/hw/9pfs/xen-9p-backend.c
+++ b/hw/9pfs/xen-9p-backend.c
@@ -68,6 +68,11 @@ typedef struct Xen9pfsDev {
static void xen_9pfs_disconnect(struct XenLegacyDevice *xendev);
+static void xen_9pfs_disconnect_bh(void *opaque)
+{
+ xen_9pfs_disconnect(opaque);
+}
+
static void xen_9pfs_in_sg(Xen9pfsRing *ring,
struct iovec *in_sg,
int *num,
@@ -150,7 +155,8 @@ static ssize_t xen_9pfs_pdu_vmarshal(V9fsPDU *pdu,
"Failed to encode VirtFS reply type %d\n",
pdu->id + 1);
xen_be_set_state(&xen_9pfs->xendev, XenbusStateClosing);
- xen_9pfs_disconnect(&xen_9pfs->xendev);
+ aio_bh_schedule_oneshot(qemu_get_aio_context(),
+ xen_9pfs_disconnect_bh, &xen_9pfs->xendev);
}
return ret;
}
@@ -173,7 +179,8 @@ static ssize_t xen_9pfs_pdu_vunmarshal(V9fsPDU *pdu,
xen_pv_printf(&xen_9pfs->xendev, 0,
"Failed to decode VirtFS request type %d\n", pdu->id);
xen_be_set_state(&xen_9pfs->xendev, XenbusStateClosing);
- xen_9pfs_disconnect(&xen_9pfs->xendev);
+ aio_bh_schedule_oneshot(qemu_get_aio_context(),
+ xen_9pfs_disconnect_bh, &xen_9pfs->xendev);
}
return ret;
}
@@ -368,10 +375,16 @@ static void xen_9pfs_evtchn_event(void *opaque)
static void xen_9pfs_disconnect(struct XenLegacyDevice *xendev)
{
Xen9pfsDev *xen_9pdev = container_of(xendev, Xen9pfsDev, xendev);
+ V9fsState *s = &xen_9pdev->state;
int i;
trace_xen_9pfs_disconnect(xendev->name);
+ if (s->transport) {
+ v9fs_reset(s); /* cancel all in-flight PDUs to prevent UAF */
+ v9fs_device_unrealize_common(s);
+ }
+
for (i = 0; i < xen_9pdev->num_rings; i++) {
if (xen_9pdev->rings[i].evtchndev != NULL) {
qemu_set_fd_handler(qemu_xen_evtchn_fd(xen_9pdev->rings[i].evtchndev),
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PULL 0/5] 9p queue 2026-07-25
2026-07-25 11:05 [PULL 0/5] 9p queue 2026-07-25 Christian Schoenebeck
` (4 preceding siblings ...)
2026-07-25 11:05 ` [PULL 5/5] hw/9pfs/xen: drain in-flight PDUs before xen-9p disconnect Christian Schoenebeck
@ 2026-07-26 19:45 ` Stefan Hajnoczi
5 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2026-07-26 19:45 UTC (permalink / raw)
To: Christian Schoenebeck
Cc: qemu-devel, qemu-stable, Greg Kurz, Peter Maydell,
Philippe Mathieu-Daudé, Pierrick Bouvier,
Daniel P. Berrangé, Jia Jia, Stefano Stabellini
[-- Attachment #1: Type: text/plain, Size: 116 bytes --]
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/11.1 for any user-visible changes.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread