[PATCH -next -v4 02/17] LSM: pass struct path to the inode_setsecctx hook

Cai Xinchen caixinchen1 at huawei.com
Wed Nov 18 08:59:29 UTC 2026


Sorry, this is a major issue. I checked the current state of the patchset

- fs/attr.c, fs/open.c, fs/inode.c, fs/utimes.c, fs/namei.c,
fs/coredump.c, drivers/block/loop.c: nd->path or file->f_path (in loop.c:
the f_path of the backing file, where file == NULL is intentional).

- drivers/base/devtmpfs.c: the mount point of the parent directory, 
which contains a directory entry that was just created or is about to be 
deleted.

- fs/cachefiles/xattr.c: cache->mnt, under which a directory entry is 
searched.

- fs/ecryptfs: ecryptfs_lower_path(), which is the mount point of the 
lower-level directory entry itself.

- fs/nfsd: exp->ex_path.mnt, which contains fh_dentry, a value decoded via
exportfs_decode_fh_raw(exp->ex_path.mnt,...), or exp->ex_path.dentry.

- fs/overlayfs: ovl_upper_mnt(ofs), which contains the actual 
upper-level directory entry.

There are two places that violate (1), both introduced by this series of 
patches in ksmbd:

smb2_parent_compressed() and smb_inherit_dacl() pair the directory entry 
returned by dget_parent()

with path->mnt, and problems arise once that directory entry becomes the 
root of its mount point.

I will fix these issues in v5 and ensure this invariant.

If you find any place where (1) still does not hold, please point it 
out, and I
will fix it.

On 11/18/2026 8:16 AM, Al Viro wrote:
> 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 at zeniv.linux.org.uk>
>>
>> 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.



More information about the Linux-security-module-archive mailing list