Re: [PATCH -next -v4 02/17] LSM: pass struct path to the inode_setsecctx hook
From: Al Viro
Date: Thu Nov 19 2026 - 00:51:52 EST
On Wed, Nov 18, 2026 at 09:51:27AM +0100, Christian Brauner wrote:
> On Wed, Nov 18, 2026 at 12:16:41AM +0000, Al Viro wrote:
> > On Tue, Nov 17, 2026 at 06:43:42PM +0000, Al Viro wrote:
> > > > + * 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.
>
> That comment is a garbled version of an earlier review. It meant that
> LSMs get no guarantees about struct vfsmount internals and don't get to
> poke at them. I'm not sure how this can be read as path->mnt being a
> random mount.
"no guarantees with regard to path->mnt" is easy to parse that way when one
is stuck with a caller that needs to be converted to new API with no relevant
mount reference in sight.
> > > If that kind of stuff actually does get passed to any existing hooks, we need
> > > to fix that ASAP.
>
> Of course there is one...
>
> dent = lookup_one_unlocked(idmap, &QSTR_LEN(...),
> priv->dir_fp->filp->f_path.dentry);
> [...].
> rc = ksmbd_vfs_fill_dentry_attrs(priv->work, idmap, dent, &ksmbd_kstat);
>
> It passes only the bare dentry, and ksmbd_vfs_fill_dentry_attrs() then
> makes up a path from the share's root mount:
>
> struct path path = {
> .mnt = share_conf->vfs_path.mnt, /* mount the share is exported from */
> .dentry = dentry, /* entry inside the listed dir */
> };
> rc = vfs_getattr(&path, ...);
>
> since 5614c8c487f6 ("ksmbd: replace generic_fillattr with vfs_getattr").
>
> So a client that lists a directory on a submount below the share then
> that dentry belongs to another superblock. So security_inode_getattr()
> and ->getattr() get a mixed path.
So e.g. apparmor hits
vfsuid_t vfsuid = i_uid_into_vfsuid(mnt_idmap(path->mnt),
d_backing_inode(path->dentry));
with path->mnt having nothing to do with path->dentry there? Fun...
> The third patch in this series fixes this. But we should make this a
> Fixes: patch really... Something like [1].
>
> > 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.
> >
> > _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.
>
> Every struct path the series constructs:
>
> - devtmpfs
> - nfsd
> - cachefiles
> - ecryptfs
> - overlayfs
> - ksmbd
>
> doesn't have this bug.
>
> [1]:
>
> --- a/fs/smb/server/smb2pdu.c
> +++ b/fs/smb/server/smb2pdu.c
> @@ -6375,13 +6375,14 @@ static int process_query_dir_entries(struct smb2_query_dir_private *priv)
> continue;
> }
>
> + path.mnt = priv->dir_fp->filp->f_path.mnt;
> + path.dentry = dent;
> +
> if (test_share_config_flag(priv->work->tcon->share_conf,
> KSMBD_SHARE_FLAG_HIDE_UNREADABLE)) {
> __le32 daccess = FILE_READ_DATA_LE | FILE_READ_EA_LE |
> FILE_READ_ATTRIBUTES_LE;
>
> - path.mnt = priv->dir_fp->filp->f_path.mnt;
> - path.dentry = dent;
> rc = smb_check_perm_dacl(priv->work->conn, &path,
> &daccess, daccess,
> priv->work->sess->user->uid,
> @@ -6397,7 +6398,7 @@ static int process_query_dir_entries(struct smb2_query_dir_private *priv)
> @@ -6397,7 +6398,7 @@ static int process_query_dir_entries(struct smb2_query_dir_private *priv)
> if (priv->info_level != FILE_NAMES_INFORMATION) {
> rc = ksmbd_vfs_fill_dentry_attrs(priv->work,
> idmap,
> - dent,
> + &path,
> &ksmbd_kstat);
> if (rc) {
> dput(dent);
> --- a/fs/smb/server/smb_common.c
> +++ b/fs/smb/server/smb_common.c
> @@ -472,32 +472,36 @@ int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work, int info_level,
> for (i = 0; i < 2; i++) {
> struct kstat kstat;
> struct ksmbd_kstat ksmbd_kstat;
> - struct dentry *dentry;
> + struct path path = { .mnt = dir->filp->f_path.mnt };
That's just asking for breakage down the road. Just pass it
the address of ->f_path for "." and
&(struct path){.mnt = dir->filp->f_path.mnt, .dentry = dentry}
for ".." (and sod the dentry = dget(...) for "." - just have it NULL there)