[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stable-9.1.3 15/58] tests/9p: add 'use-after-unlink' test
From: |
Michael Tokarev |
Subject: |
[Stable-9.1.3 15/58] tests/9p: add 'use-after-unlink' test |
Date: |
Mon, 27 Jan 2025 23:25:01 +0300 |
After removing a file from the file system, we should still be able to
work with the file if we already had it open before removal.
As a first step we verify that it is possible to write to an unlinked
file, as this is what already works. This test is extended later on
after having fixed other use cases after unlink that are not working
yet.
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Message-Id:
<3d6449d4df25bcdd3e807eff169f46f1385e5257.1732465720.git.qemu_oss@crudebyte.com>
(cherry picked from commit 462db8fb1d405391b83a0d3099fdb9bfb85c2d92)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
(Mjt: pick it to stable so the next commit in this place applies too)
diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c
index 3c8cd235cf..f6d7400a87 100644
--- a/tests/qtest/virtio-9p-test.c
+++ b/tests/qtest/virtio-9p-test.c
@@ -693,6 +693,45 @@ static void fs_unlinkat_hardlink(void *obj, void *data,
g_assert(stat(real_file, &st_real) == 0);
}
+static void fs_use_after_unlink(void *obj, void *data,
+ QGuestAllocator *t_alloc)
+{
+ QVirtio9P *v9p = obj;
+ v9fs_set_allocator(t_alloc);
+ static const uint32_t write_count = P9_MAX_SIZE / 2;
+ g_autofree char *real_file = virtio_9p_test_path("09/doa_file");
+ g_autofree char *buf = g_malloc0(write_count);
+ struct stat st_file;
+ uint32_t fid_file;
+ uint32_t count;
+
+ tattach({ .client = v9p });
+
+ /* create a file "09/doa_file" and make sure it exists and is regular */
+ tmkdir({ .client = v9p, .atPath = "/", .name = "09" });
+ tlcreate({ .client = v9p, .atPath = "09", .name = "doa_file" });
+ g_assert(stat(real_file, &st_file) == 0);
+ g_assert((st_file.st_mode & S_IFMT) == S_IFREG);
+
+ /* request a FID for that regular file that we can work with next */
+ fid_file = twalk({
+ .client = v9p, .fid = 0, .path = "09/doa_file"
+ }).newfid;
+ g_assert(fid_file != 0);
+
+ /* now first open the file in write mode before ... */
+ tlopen({ .client = v9p, .fid = fid_file, .flags = O_WRONLY });
+ /* ... removing the file from file system */
+ tunlinkat({ .client = v9p, .atPath = "09", .name = "doa_file" });
+
+ /* file is removed, but we still have it open, so this should succeed */
+ count = twrite({
+ .client = v9p, .fid = fid_file, .offset = 0, .count = write_count,
+ .data = buf
+ }).count;
+ g_assert_cmpint(count, ==, write_count);
+}
+
static void cleanup_9p_local_driver(void *data)
{
/* remove previously created test dir when test is completed */
@@ -758,6 +797,8 @@ static void register_virtio_9p_test(void)
qos_add_test("local/hardlink_file", "virtio-9p", fs_hardlink_file, &opts);
qos_add_test("local/unlinkat_hardlink", "virtio-9p", fs_unlinkat_hardlink,
&opts);
+ qos_add_test("local/use_after_unlink", "virtio-9p", fs_use_after_unlink,
+ &opts);
}
libqos_init(register_virtio_9p_test);
--
2.39.5
- [Stable-9.1.3 05/58] virtio-net: Fix size check in dhclient workaround, (continued)
- [Stable-9.1.3 05/58] virtio-net: Fix size check in dhclient workaround, Michael Tokarev, 2025/01/28
- [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 <=
- [Stable-9.1.3 17/58] 9pfs: fix 'Tgetattr' after unlink, Michael Tokarev, 2025/01/28
- [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