The other Trename and Trenameat handlers already reject "." and ".."
as new name on rename requests by returning -EISDIR in this case.
The legacy Twstat rename handler is missing this validation. While passing
"." or ".." does not trigger a crash as fixed by the previous patch (since
the fs backend driver's system calls handle these gracefully), it creates
a behavioral inconsistency, as it is semantically meaningless to rename a
file to a directory reference in the first place.
Fix this by rejecting "." and ".." in Twstat rename handler with -EISDIR
to match behavior of Trename and Trenameat handlers.
Fixes: 8cf89e007a ("virtio-9p: Add P9_TWSTAT support")
Signed-off-by: Christian Schoenebeck <[email protected]>
---
hw/9pfs/9p.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
index 88fb28b318..a09f99537d 100644
--- a/hw/9pfs/9p.c
+++ b/hw/9pfs/9p.c
@@ -3621,6 +3621,10 @@ static void coroutine_fn v9fs_wstat(void *opaque)
err = -ENOENT;
goto out;
}
+ if (!strcmp(".", v9stat.name.data) || !strcmp("..", v9stat.name.data))
{
+ err = -EISDIR;
+ goto out;
+ }
v9fs_path_write_lock(s);
err = v9fs_complete_rename(pdu, fidp, -1, &v9stat.name);
--
2.47.3