Re: [PATCH -next -v4 02/17] LSM: pass struct path to the inode_setsecctx hook
From: Al Viro
Date: Tue Nov 17 2026 - 19:17:11 EST
On Tue, Nov 17, 2026 at 06:43:42PM +0000, Al Viro wrote:
> On Tue, Nov 17, 2026 at 11:05:27PM +0800, Cai Xinchen wrote:
> > The inode_setsecctx hook and its security_inode_setsecctx() caller in
> > fs/nfsd operate on a dentry even though both have a struct path
> > available. Pass a const struct path so that the coming conversion of the
> > xattr helpers can be reflected in the implementations; for now SELinux
> > and Smack keep passing path->dentry and &nop_mnt_idmap to
> > __vfs_setxattr_locked().
> >
> > Also document in lsm_hook_defs.h what a struct path argument may be used
> > for: it can be passed to VFS helpers taking a struct path, but nothing is
> > guaranteed about path->mnt.
>
> No, with the side of Hell, No.
>
> > + * Hooks that take a struct path argument: the VFS only sanctions passing
> > + * the path to VFS helpers that take a struct path (e.g. notify_change());
> > + * it makes no guarantees with regard to path->mnt, whose layout and
> > + * implementation details are subject to change. Implementations must
> > + * not rely on its properties.
>
> NAKed-by: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
>
> If that kind of stuff actually does get passed to any existing hooks, we need
> to fix that ASAP. If not, consider that a blanket NAK on any patch series
> that would introduce such.
>
> We are not going there. At all. "Must not rely on its properties" ==
> "must make sure that no existing functions with struct path * arguments
> ever have such malformed instances passed to them". Which is not going
> to be feasible to enforce. And yes, that very much includes any VFS helpers.
To elaborate a bit: correctness of quite a few places does depend upon the
following invaraint:
path->mnt->mnt_sb == path->dentry->d_sb (1)
for all struct path pointers they might possibly run into. _Some_
functions might _currently_ be safe to call with that constraint violated;
there's neither a list of such functions nor any promise whatsoever that
call that is currently safe in such conditions will remain safe at any
later point.
_IF_ you can guarantee that (1) is not violated, we have something to
talk about; otherwise, don't call your object struct path and don't
pass it to anything that expects to deal with struct path.