[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stable-9.1.3 17/58] 9pfs: fix 'Tgetattr' after unlink
From: |
Michael Tokarev |
Subject: |
[Stable-9.1.3 17/58] 9pfs: fix 'Tgetattr' after unlink |
Date: |
Mon, 27 Jan 2025 23:25:03 +0300 |
With a valid file ID (FID) of an open file, it should be possible to send
a 'Tgettattr' 9p request and successfully receive a 'Rgetattr' response,
even if the file has been removed in the meantime. Currently this would
fail with ENOENT.
I.e. this fixes the following misbehaviour with a 9p Linux client:
open("/home/tst/filename", O_RDWR|O_CREAT|O_EXCL, 0600) = 3
unlink("/home/tst/filename") = 0
fstat(3, 0x23aa1a8) = -1 ENOENT (No such file or directory)
Expected results:
open("/home/tst/filename", O_RDWR|O_CREAT|O_EXCL, 0600) = 3
unlink("/home/tst/filename") = 0
fstat(3, {st_mode=S_IFREG|0600, st_size=0, ...}) = 0
This is because 9p server is always using a path name based lstat() call
which fails as soon as the file got removed. So to fix this, use fstat()
whenever we have an open file descriptor already.
Fixes: 00ede4c2529b ("virtio-9p: getattr server implementation...")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/103
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Message-Id:
<4c41ad47f449a5cc8bfa9285743e029080d5f324.1732465720.git.qemu_oss@crudebyte.com>
(cherry picked from commit c81e7219e0736f80bfd3553676a19e2992cff41d)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 851e36b9a1..578517739a 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -1596,7 +1596,13 @@ static void coroutine_fn v9fs_getattr(void *opaque)
retval = -ENOENT;
goto out_nofid;
}
- retval = v9fs_co_lstat(pdu, &fidp->path, &stbuf);
+ if ((fidp->fid_type == P9_FID_FILE && fidp->fs.fd != -1) ||
+ (fidp->fid_type == P9_FID_DIR && fidp->fs.dir.stream))
+ {
+ retval = v9fs_co_fstat(pdu, fidp, &stbuf);
+ } else {
+ retval = v9fs_co_lstat(pdu, &fidp->path, &stbuf);
+ }
if (retval < 0) {
goto out;
}
--
2.39.5
- [Stable-9.1.3 06/58] qdev: Fix set_pci_devfn() to visit option only once, (continued)
- [Stable-9.1.3 06/58] qdev: Fix set_pci_devfn() to visit option only once, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 07/58] ssh: Do not switch session to non-blocking mode, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 08/58] plugins: add missing export for qemu_plugin_num_vcpus, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 10/58] virtio-net: Add queues before loading them, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 11/58] ppc/spapr: fix drc index mismatch for partially enabled vcpus, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 12/58] scsi: megasas: Internal cdbs have 16-byte length, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 13/58] tests/9p: fix Rreaddir response name, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 14/58] tests/9p: add missing Rgetattr response name, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 16/58] 9pfs: remove obsolete comment in v9fs_getattr(), Michael Tokarev, 2025/01/28
- [Stable-9.1.3 15/58] tests/9p: add 'use-after-unlink' test, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 17/58] 9pfs: fix 'Tgetattr' after unlink,
Michael Tokarev <=
- [Stable-9.1.3 18/58] tests/9p: also check 'Tgetattr' in 'use-after-unlink' test, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 20/58] target/ppc: Fix THREAD_SIBLING_FOREACH for multi-socket, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 21/58] hw/nvme: fix msix_uninit with exclusive bar, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 19/58] target/ppc: Fix non-maskable interrupt while halted, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 24/58] target/riscv: Avoid bad shift in riscv_cpu_do_interrupt(), Michael Tokarev, 2025/01/28
- [Stable-9.1.3 26/58] tcg: Reset free_temps before tcg_optimize, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 25/58] 9pfs: fix regression regarding CVE-2023-2861, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 30/58] pc-bios: add missing riscv64 descriptor, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 27/58] tcg/riscv: Fix StoreStore barrier generation, Michael Tokarev, 2025/01/28
- [Stable-9.1.3 31/58] hw/intc/arm_gicv3_its: Zero initialize local DTEntry etc structs, Michael Tokarev, 2025/01/28