Skip to contentSkip to conversation

9p queue 2026-07-25

GIT PULL Applied Christian Schoenebeck 2 participants 7 messages Jul 25 – Jul 27

lore
Share & tools
lore
#1 lore raw

[PULL 3/5] hw/9pfs: fix O_TRUNC bypass on read-only export

In reply to Christian Schoenebeck

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

---
 hw/9pfs/9p.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/9pfs/9p.c +2 -2
index 3119f01117..474ac6cc40 100644
@@ -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;
             }
Signature · 1 line
2.47.3
#2 lore raw

[PULL 5/5] hw/9pfs/xen: drain in-flight PDUs before xen-9p disconnect

In reply to Christian Schoenebeck

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/

---
 hw/9pfs/9p.c             |  1 +
 hw/9pfs/xen-9p-backend.c | 17 +++++++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)
hw/9pfs/9p.c +1 -0
index 474ac6cc40..1c61e6b3e7 100644
@@ -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 {
hw/9pfs/xen-9p-backend.c +15 -2
index 24c90d97ec..d44fa8d61e 100644
@@ -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),
Signature · 1 line
2.47.3
#3 lore raw

[PULL 4/5] hw/9pfs/virtio: drain in-flight PDUs before virtio-9p unrealize

In reply to Christian Schoenebeck

From: Jia Jia <[email protected]>

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

---
 hw/9pfs/virtio-9p-device.c | 1 +
 1 file changed, 1 insertion(+)
hw/9pfs/virtio-9p-device.c +1 -0
index 50dc93091d..576a794ea4 100644
@@ -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);
Signature · 1 line
2.47.3
#0 lore raw

The following changes since commit 300438ffbb8d9430cac2fcc15cba6f482b2c0587:

Merge tag 'pull-trivial-patches' of https://gitlab.com/mjt0k/qemu into staging (2026-07-24 09:13:49 -0400)

are available in the Git repository at:

https://github.com/cschoenebeck/qemu.git tags/pull-9p-20260725

for you to fetch changes up to 1de8aea061b9d5bc7aaed182e2eebe9554debd68:

hw/9pfs/xen: drain in-flight PDUs before xen-9p disconnect (2026-07-25 12:35:25 +0200)

----------------------------------------------------------------
9pfs changes:

- Fix O_TRUNC bypass on read-only export (CVE-2026-63318).

- Fix guest-triggered Treaddir/ACPI eject UAF (#3937).

- Tests: fix "slow" type test errors on certain host systems.

- Tests: fix CID 1660926.

----------------------------------------------------------------
Christian Schoenebeck (4):
tests/9p: prevent potential error in do_local_xattr_limit() tests/9p: reduce xattr size to 1k
hw/9pfs: fix O_TRUNC bypass on read-only export hw/9pfs/xen: drain in-flight PDUs before xen-9p disconnect

Jia Jia (1):
hw/9pfs/virtio: drain in-flight PDUs before virtio-9p unrealize

 hw/9pfs/9p.c                 |  5 +++--
 hw/9pfs/virtio-9p-device.c   |  1 +
 hw/9pfs/xen-9p-backend.c     | 17 +++++++++++++++--
 tests/qtest/virtio-9p-test.c | 16 +++++++++++-----
 4 files changed, 30 insertions(+), 9 deletions(-)
#4 lore raw

[PULL 2/5] tests/9p: reduce xattr size to 1k

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.

---
 tests/qtest/virtio-9p-test.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
tests/qtest/virtio-9p-test.c +10 -4
index 692a0e8e3f..22302bd2f8 100644
@@ -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)
 {
Signature · 1 line
2.47.3
#5 lore raw

[PULL 1/5] tests/9p: prevent potential error in do_local_xattr_limit()

In reply to Christian Schoenebeck

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

---
 tests/qtest/virtio-9p-test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/virtio-9p-test.c +1 -1
index cfd3c02da4..692a0e8e3f 100644
@@ -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);
Signature · 1 line
2.47.3