[PATCH 0/2] 9pfs/local: allow exporting traversable but non-readable directories

Niklas Gollenstede posted 2 patches 1 week, 6 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20261109155503.2530430-1-gollenstede@ibr.cs.tu-bs.de
Maintainers: Christian Schoenebeck <qemu_oss@crudebyte.com>, Greg Kurz <groug@kaod.org>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
hw/9pfs/9p-local.c                       |   9 +-
tests/qtest/libqos/virtio-9p.c           |   4 +-
tests/qtest/virtio-9p-test.c             | 134 +++++++++++++++++++++++
5 files changed, 142 insertions(+), 5 deletions(-)
[PATCH 0/2] 9pfs/local: allow exporting traversable but non-readable directories
Posted by Niklas Gollenstede 1 week, 6 days ago
I often use (NixOS) qemu VMs with the hosts `/nix/store` mounted as `9p` share from the host.
This generally works fine, but stops working when the read permission on the `/nix/store` dir itself is not granted to the user running qemu.
Almost no application should have a reason to read the `/nix/store` directory itself, and since both a direct and especially a recursive listing can be huge, some programs misbehave if they can read it.
Nix itself recently gained support for having `/nix/store` with mode `1771`.

The solution seems pretty straightforward: open a few root-directory file descriptors with `O_PATH` instead of `O_RDONLY`, as they are only used to `*at` child FDs. Reads, if attempted, should then fail in the client/guest.

This is a problem for real users, and I knew/suspected that changing a few open flags to `O_PATH` would probably fix it (and I did a quick attempt at this myself).
But since it is much faster and honestly also more reliable ...
AI disclosure:
I had Claude analyse the problem, find the necessary sites to change, and write a test that shows the problem and the fix.
The (100% AI generated) test is included in a separate commit, so that it can hopefully be accepted or rejected independently of the actual fix.
This and the first commit's message I wrote myself.

Claude (1):
  tests/qtest/virtio-9p: test non-readable but traversable directories

Niklas Gollenstede (1):
  9pfs/local: allow exporting traversable but non-readable directories

 hw/9pfs/9p-local.c                       |   9 +-
 tests/qtest/libqos/virtio-9p.c           |   4 +-
 tests/qtest/virtio-9p-test.c             | 134 +++++++++++++++++++++++
 5 files changed, 142 insertions(+), 5 deletions(-)

--
2.54.0