[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 5/6] 9pfs: fix 'Tgetattr' after unlink
From: |
Christian Schoenebeck |
Subject: |
Re: [PATCH 5/6] 9pfs: fix 'Tgetattr' after unlink |
Date: |
Sun, 24 Nov 2024 20:44:10 +0100 |
On Sunday, November 24, 2024 4:50:03 PM CET Christian Schoenebeck wrote:
> 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 stat() call
> which fails as soon as the file got removed. So to fix this, use fstat()
> whenever we have an open file descriptor already.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/103
> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
> ---
Fixes: 00ede4c2529b ('virtio-9p: getattr server implementation...')
> hw/9pfs/9p.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> 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;
> }
>
- [PATCH 3/6] tests/9p: add missing Rgetattr response name, (continued)
- [PATCH 3/6] tests/9p: add missing Rgetattr response name, Christian Schoenebeck, 2024/11/24
- [PATCH 1/6] tests/9p: add 'use-after-unlink' test, Christian Schoenebeck, 2024/11/24
- [PATCH 4/6] 9pfs: remove obsolete comment in v9fs_getattr(), Christian Schoenebeck, 2024/11/24
- [PATCH 5/6] 9pfs: fix 'Tgetattr' after unlink, Christian Schoenebeck, 2024/11/24
- [PATCH 2/6] tests/9p: fix Rreaddir response name, Christian Schoenebeck, 2024/11/24
- [PATCH 6/6] tests/9p: also check 'Tgetattr' in 'use-after-unlink' test, Christian Schoenebeck, 2024/11/24
- Re: [PATCH 0/6] 9pfs: fix fstat() after unlink() (with a Linux guest), Greg Kurz, 2024/11/25