[PATCH v2 0/7] fs/9p: Reuse inode based on path (in addition to qid)
Mickaël Salaün
mic at digikod.net
Wed Sep 17 15:00:22 UTC 2025
On Wed, Sep 17, 2025 at 11:52:35AM +0200, Christian Schoenebeck wrote:
> On Wednesday, September 17, 2025 1:59:21 AM CEST Tingmao Wang wrote:
> > On 9/16/25 20:22, Christian Schoenebeck wrote:
> > > On Tuesday, September 16, 2025 4:01:40 PM CEST Tingmao Wang wrote:
> [...]
> > > I see that you are proposing an option for your proposed qid based
> > > re-using of dentries. I don't think it should be on by default though,
> > > considering what we already discussed (e.g. inodes recycled by ext4, but
> > > also not all 9p servers handling inode collisions).
> >
> > Just to be clear, this approach (Landlock holding a fid reference, then
> > using the qid as a key to search for rules when a Landlocked process
> > accesses the previously remembered file, possibly after the file has been
> > moved on the server) would only be in Landlock, and would only affect
> > Landlock, not 9pfs (so not sure what you meant by "re-using of dentries").
> >
> > The idea behind holding a fid reference within Landlock is that, because
> > we have the file open, the inode would not get recycled in ext4, and thus
> > no other file will reuse the qid, until we close that reference (when the
> > Landlock domain terminates, or when the 9p filesystem is unmounted)
>
> So far I only had a glimpse on your kernel patches and had the impression that
> they are changing behaviour for all users, since you are touching dentry
> lookup.
I think we should not hold dentries because:
- they reference other dentries (i.e. a file hierarchy),
- they block umount and I'm convinced the VFS (and users) are not going
to like long-lived dentries,
- Landlock and inotify don't need dentries, just inodes.
I'm wondering why fid are referenced by dentries instead of inodes.
The need for Landlock is to be able to match an inode with a previously
seen one. Not all LSM hooks (nor VFS internals) always have access to
dentries, but they do have access to inodes.
>
> > > For all open FIDs QEMU retains a descriptor to the file/directory.
> > >
> > > Which 9p message do you see sent to server, Trename or Trenameat?
> > >
> > > Does this always happen to you or just sometimes, i.e. under heavy load?
> >
> > Always happen, see log: (no Trename since the rename is done on the host)
> [...]
> > Somehow if I rename in the guest, it all works, even though it's using the
> > same fid 2 (and it didn't ask QEMU to walk the new path)
>
> Got it. Even though QEMU *should* hold a file descriptor (or a DIR* stream,
It's reasonable to assume that QEMU and other should hold opened fid In
practice, this might not always be the case, but let's move on and
consider that a 9p server bug.
Landlock and fanotify need some guarantees on opened files, and we
cannot consider every server bug. For Landlock, inode may get an
"ephemeral tag" (with the Landlock object mechanism) to match previously
seen inodes. In a perfect world, Landlock could keep a reference on 9p
inodes (as for other filesystems) and these inodes would always match
the same file. In practice this is not the case, but the 9p client
requirements and the Landlock requirements are not exactly the same.
A 9p client (the kernel) wants to safely deal with duplicated qid, which
should not happen but still happen in practice as explained before.
On the other side, Landlock wants to not deny access to allowed files
(currently identified by their inodes), but I think it would be
reasonable to allow access theoretically denied (i.e. not allowed to be
precise, because of the denied by default mechanism) files because of a
9p server bug mishandling qid (e.g. mapping them to recycled ext4
inodes).
All that to say that it looks reasonable for Landlock to trust the
filesystem, and by that I mean all its dependencies, including the 9p
server, to not have bugs.
Another advantage to rely on qid and server-side opened files is that we
get (in theory) the same semantic as when Landlock is used with local
filesystems (e.g. files moved on the server should still be correctly
identified by Landlock on the client).
> which should imply a file descriptor), there is still a path string stored at
> V9fsFidState and that path being processed at some places, probably because
> there are path based and FID based variants (e.g Trename vs. Trenameat). Maybe
> that clashes somewhere, not sure. So I fear you would need to debug this.
Good to know that it is not a legitimate behavior for a 9p client.
More information about the Linux-security-module-archive
mailing list