Re: [PATCH -next -v4 02/17] LSM: pass struct path to the inode_setsecctx hook
From: Christian Brauner
Date: Wed Nov 18 2026 - 03:52:01 EST
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.
> > 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.
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 };
if (!dir->dot_dotdot[i]) { /* fill dot entry info */
if (i == 0) {
d_info->name = ".";
d_info->name_len = 1;
- dentry = dget(dir->filp->f_path.dentry);
+ path.dentry = dget(dir->filp->f_path.dentry);
} else {
d_info->name = "..";
d_info->name_len = 2;
- dentry = dget_parent(dir->filp->f_path.dentry);
+ /*
+ * The parent never leaves the superblock, so
+ * the directory's mount stays consistent with it.
+ */
+ path.dentry = dget_parent(dir->filp->f_path.dentry);
}
if (!match_pattern(d_info->name, d_info->name_len,
search_pattern)) {
dir->dot_dotdot[i] = 1;
- dput(dentry);
+ dput(path.dentry);
continue;
}
ksmbd_kstat.kstat = &kstat;
rc = ksmbd_vfs_fill_dentry_attrs(work,
idmap,
- dentry,
+ &path,
&ksmbd_kstat);
- dput(dentry);
+ dput(path.dentry);
if (rc)
break;
--- a/fs/smb/server/vfs.c
+++ b/fs/smb/server/vfs.c
@@ -1897,18 +1897,14 @@
int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work,
const struct mnt_idmap *idmap,
- struct dentry *dentry,
+ const struct path *path,
struct ksmbd_kstat *ksmbd_kstat)
{
- struct ksmbd_share_config *share_conf = work->tcon->share_conf;
+ struct dentry *dentry = path->dentry;
u64 time;
int rc;
- struct path path = {
- .mnt = share_conf->vfs_path.mnt,
- .dentry = dentry,
- };
- rc = vfs_getattr(&path, ksmbd_kstat->kstat,
+ rc = vfs_getattr(path, ksmbd_kstat->kstat,
STATX_BASIC_STATS | STATX_BTIME,
AT_STATX_SYNC_AS_STAT);
if (rc)
--- a/fs/smb/server/vfs.h
+++ b/fs/smb/server/vfs.h
@@ -154,7 +154,7 @@ void *ksmbd_vfs_init_kstat(char **p, struct ksmbd_kstat *ksmbd_kstat);
int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work,
const struct mnt_idmap *idmap,
const struct path *path,
struct ksmbd_kstat *ksmbd_kstat);