qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] 9pfs: local: read native symlinks when security-model=mapped
@ 2025-11-22 20:19 Andrey Erokhin
  2025-11-25 14:04 ` Greg Kurz
  2025-11-28 10:23 ` Christian Schoenebeck
  0 siblings, 2 replies; 8+ messages in thread
From: Andrey Erokhin @ 2025-11-22 20:19 UTC (permalink / raw)
  To: qemu-devel; +Cc: Greg Kurz, Christian Schoenebeck

Directories attached using virtfs with security-model=mapped
may contain native symlinks

This can happen e.g. when booting from a rootfs directory tree
(usually with a writable overlay set up on the host side)

Currently, when security-model=mapped[-xattr|-file],
QEMU assumes that host-side "symlinks" are in the mapped format,
i.e. are regular files storing the linked path,
so it tries to open with O_NOFOLLOW
and fails with ELOOP on native symlinks

This patch introduces a fallback for such cases:
reuse security-model=[none|passthrough] else if branch logic
where readlink will be called for the path basename

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/173

Signed-off-by: Andrey Erokhin <language.lawyer@gmail.com>
---
 hw/9pfs/9p-local.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index 6230466de1..ddf111b674 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -474,12 +474,16 @@ static ssize_t local_readlink(FsContext *fs_ctx, V9fsPath *fs_path,
 
         fd = local_open_nofollow(fs_ctx, fs_path->data, O_RDONLY, 0);
         if (fd == -1) {
+            if (errno == ELOOP) {
+                goto native_symlink;
+            }
             return -1;
         }
         tsize = RETRY_ON_EINTR(read(fd, (void *)buf, bufsz));
         close_preserve_errno(fd);
     } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
                (fs_ctx->export_flags & V9FS_SM_NONE)) {
+    native_symlink:;
         char *dirpath = g_path_get_dirname(fs_path->data);
         char *name = g_path_get_basename(fs_path->data);
         int dirfd;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-11-28 10:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-22 20:19 [PATCH v2] 9pfs: local: read native symlinks when security-model=mapped Andrey Erokhin
2025-11-25 14:04 ` Greg Kurz
2025-11-25 14:21   ` Andrey Erokhin
2025-11-25 18:58     ` Greg Kurz
2025-11-25 19:31       ` Christian Schoenebeck
2025-11-25 20:40         ` Andrey Erokhin
2025-11-26 12:26           ` Christian Schoenebeck
2025-11-28 10:23 ` Christian Schoenebeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).