Linux Security Modules development
 help / color / mirror / Atom feed
* Re: [PATCH -next -v4 02/17] LSM: pass struct path to the inode_setsecctx hook
  2026-11-17 15:05 ` [PATCH -next -v4 02/17] LSM: pass struct path to the inode_setsecctx hook Cai Xinchen
@ 2026-11-17 14:43   ` sashiko-bot
  2026-11-17 18:43   ` Al Viro
  1 sibling, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 14:43 UTC (permalink / raw)
  Cc: linux-security-module, selinux

> 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.
> 
> Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=2


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 04/17] fs: pass struct path to POSIX ACL helpers
  2026-11-17 15:05 ` [PATCH -next -v4 04/17] fs: pass struct path to POSIX ACL helpers Cai Xinchen
@ 2026-11-17 14:45   ` sashiko-bot
  0 siblings, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 14:45 UTC (permalink / raw)
  Cc: linux-security-module, selinux

> vfs_set_acl(), vfs_get_acl(), vfs_remove_acl() and the
> do_set_acl()/do_get_acl() helpers take a struct dentry even though their
> callers either hold a struct path (or a struct file).  Pass a struct path
> instead, with the idmap still as a separate first argument.
> 
> set_posix_acl() keeps taking a dentry, as it is called from
> inode_operations->set_acl.  ecryptfs_set_acl() keeps passing
> &nop_mnt_idmap because its ACLs have already been translated into global
> ids, while ecryptfs_get_acl() threads the upper idmap down.
> 
> Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=4


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 01/17] fs: pass struct path to notify_change()
  2026-11-17 15:05 ` [PATCH -next -v4 01/17] fs: pass struct path to notify_change() Cai Xinchen
@ 2026-11-17 14:48   ` sashiko-bot
  2026-11-17 18:30   ` Al Viro
  1 sibling, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 14:48 UTC (permalink / raw)
  Cc: linux-security-module, selinux

> notify_change() and do_truncate() take a struct dentry even though their
> callers either hold a struct path (or a struct file) or only need the
> mount they already use to build one.  Pass a struct path instead; the
> idmap stays a separate argument, as it must be taken from the mount when
> the path is checked and passed down unchanged.
> 
> The NTFS named stream support forwards a change to the base inode.  Add a
> notify_change_target() helper for it, and record the path the change was
> requested through in the new iattr.ia_path field, which is only valid for
> the duration of the notify_change() call and must not be stored.
> 
> Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=1


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 07/17] LSM: pass struct path and struct file to the inode fileattr hooks
  2026-11-17 15:05 ` [PATCH -next -v4 07/17] LSM: pass struct path and struct file to the inode fileattr hooks Cai Xinchen
@ 2026-11-17 14:51   ` sashiko-bot
  0 siblings, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 14:51 UTC (permalink / raw)
  Cc: linux-security-module, selinux

> Switch vfs_fileattr_get(), vfs_fileattr_set(), the inode_file_getattr and
> inode_file_setattr hooks and their SELinux implementations to take a
> const struct path, and pass the struct file through which the operation
> is requested when there is one.
> 
> vfs_fileattr_get() keeps checking i_op->fileattr_get before calling the
> hook, so the -ENOIOCTLCMD fallback used by the ioctls is unchanged.  Add
> an unchecked __vfs_fileattr_get() for the internal users: nfsd's casefold
> probe, and the read of the current attributes in do_vfs_fileattr_set(),
> which is authorized as a whole by the set hook.  ksmbd keeps using the
> checked helpers, passing the file it holds or NULL for path-only probes;
> stacking filesystems do the same, so overlayfs keeps its existing
> file:ioctl/file:open workaround until the LSM semantics are agreed on.
> 
> Add strong definitions of the two bpf_lsm_* stubs naming the file
> argument file__nullable.
> 
> Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=7


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 11/17] LSM: rename the inode posix acl hooks to path_*_acl hooks
  2026-11-17 15:05 ` [PATCH -next -v4 11/17] LSM: rename the inode posix acl hooks to path_*_acl hooks Cai Xinchen
@ 2026-11-17 14:55   ` sashiko-bot
  0 siblings, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 14:55 UTC (permalink / raw)
  To: Cai Xinchen
  Cc: bpf, linux-security-module, linux-trace-kernel, selinux, dsterba,
	Chuck Lever, Jeff Layton, Anna Schumaker

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] lsm: commit message inaccurately claims BPF selftests are
  updated
--

commit 98ec639d5946054ad6d9e19a8ef2e58b854df2a6
Author: Cai Xinchen <caixinchen1@huawei.com>

LSM: rename the inode posix acl hooks to path_*_acl hooks

This commit renames the inode_{set,get,remove}_acl LSM hooks, their
security_inode_*_acl() wrappers, and their LSM and BPF definitions to
path_{set,get,remove}_acl.

> Update the BPF selftests, the strong definitions in
> kernel/bpf/bpf_lsm_proto.c and the Smack audit function names.

[Severity: Low]
This isn't a bug, but no BPF selftests are modified in this commit (only
kernel/bpf/bpf_lsm_proto.c is updated for BPF). Should the mention of BPF
selftests be dropped from the commit message?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=11

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 10/17] LSM: rename the inode xattr hooks to path_xattr hooks
  2026-11-17 15:05 ` [PATCH -next -v4 10/17] LSM: rename the inode xattr hooks to path_xattr hooks Cai Xinchen
@ 2026-11-17 14:55   ` sashiko-bot
  0 siblings, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 14:55 UTC (permalink / raw)
  To: Cai Xinchen
  Cc: bpf, linux-security-module, linux-trace-kernel, selinux, dsterba,
	Chuck Lever, Jeff Layton, Anna Schumaker

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] selftests/bpf: multi-line comment style in
  test_set_remove_xattr()
--

commit 5a35ac0f5c000b29a6a994caacc2c58218d41cdf
Author: Cai Xinchen <caixinchen1@huawei.com>

LSM: rename the inode xattr hooks to path_xattr hooks

This commit renames the inode_{set,get,list,remove}xattr LSM hooks and
their security_inode_*xattr() wrappers to path_{set,get,list,remove}xattr
and security_path_*xattr(), updating LSM implementations, BPF LSM hooks,
and BPF selftests accordingly.

> diff --git a/tools/testing/selftests/bpf/prog_tests/fs_kfuncs.c b/tools/testing/selftests/bpf/prog_tests/fs_kfuncs.c
> index 43a26ec69a8e3..5145b1f03cac2 100644
> --- a/tools/testing/selftests/bpf/prog_tests/fs_kfuncs.c
> +++ b/tools/testing/selftests/bpf/prog_tests/fs_kfuncs.c

[ ... ]

> @@ -148,13 +148,13 @@ static void test_set_remove_xattr(void)
>  
>  	/* First, test not _locked version of the kfuncs with getxattr. */
>  
> -	/* Read security.bpf.foo and trigger test_inode_getxattr. This
> +	/* Read security.bpf.foo and trigger test_path_getxattr. This
>  	 * bpf program will set security.bpf.bar to "world".
>  	 */
>  	read_and_validate_foo(skel);
>  	validate_bar_match(skel);
>  
> -	/* Read security.bpf.foo and trigger test_inode_getxattr again.
> +	/* Read security.bpf.foo and trigger test_path_getxattr again.
>  	 * This will remove xattr security.bpf.bar.
>  	 */
>  	read_and_validate_foo(skel);
> @@ -167,13 +167,13 @@ static void test_set_remove_xattr(void)
>  
>  	/* Second, test _locked version of the kfuncs, with setxattr */
>  
> -	/* Set security.bpf.foo and trigger test_inode_setxattr. This
> +	/* Set security.bpf.foo and trigger test_path_setxattr. This
>  	 * bpf program will set security.bpf.bar to "world".
>  	 */
>  	set_foo(skel);
>  	validate_bar_match(skel);
>  
> -	/* Set security.bpf.foo and trigger test_inode_setxattr again.
> +	/* Set security.bpf.foo and trigger test_path_setxattr again.
>  	 * This will remove xattr security.bpf.bar.
>  	 */
>  	set_foo(skel);

[Severity: Low]
This isn't a bug, but BPF coding style puts the opening /* of a
multi-line comment on its own line, with the comment text starting on the
next line.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=10

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 03/17] fs: pass struct path to xattr helpers
  2026-11-17 15:05 ` [PATCH -next -v4 03/17] fs: pass struct path to xattr helpers Cai Xinchen
@ 2026-11-17 14:59   ` sashiko-bot
  0 siblings, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 14:59 UTC (permalink / raw)
  To: Cai Xinchen
  Cc: bpf, linux-security-module, linux-trace-kernel, selinux, dsterba,
	Chuck Lever, Jeff Layton, Anna Schumaker

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ksmbd: dotdot mount walk in
  ksmbd_populate_dot_dotdot_entries() escapes share_root
- [Low] nfsd: reverse Christmas tree order violated in nfsd_getxattr()
  and nfsd_listxattr()
--

commit 659e941625d287aa476faa3056e5fd5cc15c2d66
Author: Cai Xinchen <caixinchen1@huawei.com>

fs: pass struct path to xattr helpers

This commit updates vfs_setxattr(), vfs_getxattr(), vfs_listxattr(),
vfs_removexattr(), and the __vfs_*_locked() helpers along with their
callers in ksmbd, nfsd, overlayfs, cachefiles, ecryptfs, and LSMs to
pass a struct path instead of a struct dentry.

> diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
> index 1c686b82e70a0..aef4097e9ef37 100644
> --- a/fs/nfsd/vfs.c
> +++ b/fs/nfsd/vfs.c
[ ... ]
> @@ -2676,23 +2678,24 @@ __be32
>  nfsd_getxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name,
>  	      void **bufp, int *lenp)
>  {
> +	struct path path;
> +	struct inode *inode;
> +	char *buf;
>  	ssize_t len;
>  	__be32 err;
> -	char *buf;
> -	struct inode *inode;
> -	struct dentry *dentry;
[ ... ]
> @@ -2749,23 +2752,24 @@ __be32
>  nfsd_listxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char **bufp,
>  	       int *lenp)
>  {
> +	struct path path;
> +	struct inode *inode;
> +	char *buf;
>  	ssize_t len;
>  	__be32 err;
> -	char *buf;
> -	struct inode *inode;
> -	struct dentry *dentry;

[Severity: Low]
This isn't a bug, but NFSD keeps local variable declarations in reverse
Christmas tree order, so struct inode *inode; should come before struct
path path; in both nfsd_getxattr() and nfsd_listxattr().

> diff --git a/fs/smb/server/smb_common.c b/fs/smb/server/smb_common.c
> index e7a987af64ba5..a6da27a7d7cbb 100644
> --- a/fs/smb/server/smb_common.c
> +++ b/fs/smb/server/smb_common.c
> @@ -467,37 +467,82 @@ int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work, int info_level,
>  {
>  	int i, rc = 0;
>  	struct ksmbd_conn *conn = work->conn;
> -	const struct mnt_idmap *idmap = file_mnt_idmap(dir->filp);
> +	const struct path *const share_root = &work->tcon->share_conf->vfs_path;
>  
>  	for (i = 0; i < 2; i++) {
>  		struct kstat kstat;
>  		struct ksmbd_kstat ksmbd_kstat;
> -		struct dentry *dentry;
> +		struct path path = dir->filp->f_path;
> +		const struct mnt_idmap *idmap;
> +		struct dentry *parent;
>  
>  		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_get(&path);
>  			} else {
>  				d_info->name = "..";
>  				d_info->name_len = 2;
> -				dentry = dget_parent(dir->filp->f_path.dentry);
> +				path_get(&path);
> +				/*
> +				 * A ".." entry must not walk above the
> +				 * share root, so it designates the share
> +				 * root itself in that case.
> +				 */
> +				if (!path_equal(&path, share_root)) {
> +					/*
> +					 * The parent of a mount root dentry
> +					 * is not covered by the same mount,
> +					 * so follow the mount stack up like
> +					 * a ".." path walk would, to keep
> +					 * the path valid.
> +					 */
> +					while (path.dentry == path.mnt->mnt_root &&
> +					       follow_up(&path))
> +						;
> +					if (path.dentry == path.mnt->mnt_root) {
> +						/*
> +						 * The mount is detached, for
> +						 * example after a lazy umount
> +						 * which the open file pins
> +						 * down, so the parent would
> +						 * not be covered by path.mnt:
> +						 * report the share root
> +						 * instead, as for any other
> +						 * ".." above the share root.
> +						 */
> +						path_put(&path);
> +						path_get(share_root);
> +						path = *share_root;
> +					} else {
> +						parent = dget_parent(path.dentry);
> +						dput(path.dentry);
> +						path.dentry = parent;
> +					}
> +				}
>  			}

[Severity: Medium]
Can the ".." resolution walk above share_root when a mount is stacked on
top of share_root?

If a submount is mounted on share_root and entered via follow_down() when
KSMBD_SHARE_FLAG_CROSSMNT is enabled, dir->filp->f_path is the submount
root, so the initial path_equal(&path, share_root) check is false.
follow_up(&path) then steps onto share_root, but neither the while loop
nor the dget_parent() branch rechecks path_equal(&path, share_root).
If share_root is itself a mountpoint, the loop continues calling
follow_up(&path) into the parent mount; otherwise the else branch calls
dget_parent(path.dentry) and steps to the parent directory of share_root,
exposing host directory attributes and xattrs outside the share to the
SMB client via ksmbd_vfs_fill_dentry_attrs().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=3

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 13/17] LSM: rename inode_setsecctx to path_setsecctx
  2026-11-17 15:05 ` [PATCH -next -v4 13/17] LSM: rename inode_setsecctx to path_setsecctx Cai Xinchen
@ 2026-11-17 14:59   ` sashiko-bot
  0 siblings, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 14:59 UTC (permalink / raw)
  Cc: linux-security-module, selinux

> The inode_setsecctx hook receives a struct path, so rename it to
> path_setsecctx and rename security_inode_setsecctx() and the SELinux and
> Smack implementations accordingly.  The exported symbol is renamed as
> well, so out-of-tree modules calling security_inode_setsecctx() have to
> be updated.  Nothing under tools/ attaches to this hook.
> 
> Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=13


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 12/17] LSM: rename the inode fileattr hooks to path_file_* hooks
  2026-11-17 15:05 ` [PATCH -next -v4 12/17] LSM: rename the inode fileattr hooks to path_file_* hooks Cai Xinchen
@ 2026-11-17 15:02   ` sashiko-bot
  0 siblings, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 15:02 UTC (permalink / raw)
  To: Cai Xinchen
  Cc: bpf, linux-security-module, linux-trace-kernel, selinux, dsterba,
	Chuck Lever, Jeff Layton, Anna Schumaker

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] lsm: commit message inaccurately claims BPF selftests are
  updated
--

commit 27da61e3999728511dec6dab29db3e99aa1b60d3
Author: Cai Xinchen <caixinchen1@huawei.com>

LSM: rename the inode fileattr hooks to path_file_* hooks

This commit renames the inode_file_getattr and inode_file_setattr LSM hooks,
their security_*() wrappers, SELinux implementations, and BPF LSM strong
definitions to path_file_getattr and path_file_setattr.

> Update the BPF selftests and the strong definitions in
> kernel/bpf/bpf_lsm_proto.c.

[Severity: Low]
This isn't a bug, but no BPF selftests are modified by this commit, so the
reference to updating the BPF selftests in the commit message should be
dropped.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=12

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 05/17] LSM: pass struct path and struct file to the inode xattr hooks
  2026-11-17 15:05 ` [PATCH -next -v4 05/17] LSM: pass struct path and struct file to the inode xattr hooks Cai Xinchen
@ 2026-11-17 15:03   ` sashiko-bot
  0 siblings, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 15:03 UTC (permalink / raw)
  To: Cai Xinchen
  Cc: bpf, linux-security-module, linux-trace-kernel, selinux, dsterba,
	Chuck Lever, Jeff Layton, Anna Schumaker

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bpf: missing BTF_TYPE_SAFE_TRUSTED for struct path breaks
  xattr kfuncs
--

commit 8e13dee6fc4fbca67536485e5988ae543a847e9e
Author: Cai Xinchen <caixinchen1@huawei.com>

LSM: pass struct path and struct file to the inode xattr hooks

This commit converts the inode_setxattr, inode_getxattr, inode_listxattr,
and inode_removexattr LSM hooks and VFS xattr helpers to take a const
struct path * instead of a struct dentry *, and threads an optional struct
file * through them.

> diff --git a/tools/testing/selftests/bpf/progs/test_get_xattr.c b/tools/testing/selftests/bpf/progs/test_get_xattr.c
> index 54305f4c9f2dd..97361ff10e9f1 100644
> --- a/tools/testing/selftests/bpf/progs/test_get_xattr.c
> +++ b/tools/testing/selftests/bpf/progs/test_get_xattr.c
> @@ -56,7 +56,8 @@ int BPF_PROG(test_file_open, struct file *f)
>  }
>  
>  SEC("lsm.s/inode_getxattr")
> -int BPF_PROG(test_inode_getxattr, struct dentry *dentry, char *name)
> +int BPF_PROG(test_inode_getxattr, const struct path *path, char *name,
> +	     struct file *file)
>  {
>  	struct bpf_dynptr value_ptr;
>  	__u32 pid;
> @@ -69,7 +70,7 @@ int BPF_PROG(test_inode_getxattr, struct dentry *dentry, char *name)
>  	bpf_dynptr_from_mem(value2, sizeof(value2), 0, &value_ptr);
>  
>  	for (i = 0; i < ARRAY_SIZE(xattr_names); i++) {
> -		ret = bpf_get_dentry_xattr(dentry, xattr_names[i], &value_ptr);
> +		ret = bpf_get_dentry_xattr(path->dentry, xattr_names[i], &value_ptr);
>  		if (ret == sizeof(expected_value))
>  			break;
>  	}

[Severity: Medium]
Does the verifier reject passing path->dentry to bpf_get_dentry_xattr()
here and in test_set_remove_xattr.c?

Because struct path is not listed in BTF_TYPE_SAFE_TRUSTED in
type_is_trusted() at this commit, check_ptr_to_btf_access() drops
PTR_TRUSTED when dereferencing path->dentry, causing the xattr kfuncs to
reject the argument and breaking these BPF selftests across bisection.
A later patch in the series, commit "LSM: rename inode_setattr to
path_setattr and pass struct path and file", adds
BTF_TYPE_SAFE_TRUSTED(struct path); moving that verifier change to or
before this patch would keep these hooks and selftests working here.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=5

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 16/17] samples/landlock: Add metadata rights to sandboxer
  2026-11-17 15:05 ` [PATCH -next -v4 16/17] samples/landlock: Add metadata rights to sandboxer Cai Xinchen
@ 2026-11-17 15:04   ` sashiko-bot
  0 siblings, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 15:04 UTC (permalink / raw)
  Cc: linux-security-module, selinux

> Handle the two new access rights in the sandboxer: READ_METADATA joins
> the read-only set, WRITE_METADATA the read-write set, and both join
> ACCESS_FILE.  Bump LANDLOCK_ABI_LAST to 13 and remove the rights for
> ABI < 13 in the fallback switch.
> 
> Update the trace example in events-landlock.rst accordingly.
> 
> Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=16


^ permalink raw reply	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights
@ 2026-11-17 15:05 Cai Xinchen
  2026-11-17 15:05 ` [PATCH -next -v4 01/17] fs: pass struct path to notify_change() Cai Xinchen
                   ` (16 more replies)
  0 siblings, 17 replies; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

This series adds two new Landlock filesystem access rights,
LANDLOCK_ACCESS_FS_READ_METADATA and LANDLOCK_ACCESS_FS_WRITE_METADATA,
which control access to file and directory metadata such as inode
attributes (mode, ownership, timestamps), extended attributes, POSIX
ACLs and chattr(1)-style flags.  It picks up the work from the
"landlock: add chmod and chown support" series [1] and follows the
coarse-grained grouping discussed in that thread [2]: instead of
separate chmod/chown rights, metadata operations are grouped into one
read and one write right.

Landlock evaluates access rights on a per-path basis, but the
metadata related LSM hooks (inode_setattr, inode_setsecctx, the inode
xattr, POSIX ACL and fileattr hooks) only receive the dentry of the
accessed object.  Patches 1-8 therefore first pass struct path
instead of dentry through the metadata-related VFS helpers and LSM
hooks.  The hooks also receive a struct file argument, set by the
VFS to the file through which the operation is requested when there
is one (i.e. for the file descriptor-based system calls such as
fchmod(2), fchown(2), fgetxattr(2), utimensat(2) on an empty path,
and for the FS_IOC_* ioctls and file_[gs]etattr(2) with
AT_EMPTY_PATH), and NULL otherwise (i.e. for the path-based system
calls and for kernel-internal accesses).  This is a pure refactoring
with no behavior change for the other LSMs, which only have their
hook implementations' signatures updated; the file argument is only
consumed by Landlock (patch 14).  The series is split so that every
patch builds on its own:

  1: notify_change() and its callers
  2: inode_setsecctx hook (must come before 3: the SELinux and Smack
     implementations call __vfs_setxattr_locked internally)
  3: xattr helpers, which also drops a redundant EVM xattr size sanity
     check whose vfs_getxattr() call only has a dentry and therefore
     cannot be migrated to the new path-based signature
  4: POSIX ACL helpers
  5: inode xattr hooks, threaded through the xattr helpers so that
     the f[gs]etxattr(2) and io_uring flows pass their file
  6: inode POSIX ACL hooks, threaded through do_set_acl()/do_get_acl()
  7: inode fileattr hooks (FS_IOC_[GS]ETFLAGS, FS_IOC_FS[SG]ETXATTR,
     file_[gs]etattr(2)), which also adds a __vfs_fileattr_get()
     counterpart without security checks for the kernel-internal
     readers (nfsd), and removes the ovl_security_fileattr() hack by
     forwarding the real upper/lower path to the checked
     vfs_fileattr_get()/_set() from ecryptfs and overlayfs
  8: inode_setattr hook, which now receives the struct file held by
     the fd-based callers (fchmod(2), fchown(2), fchmodat2(2) and
     fchownat(2) with AT_EMPTY_PATH, utimensat(2) on an empty path);
     do_truncate() passes NULL because size changes are governed by
     the truncate hooks.  The hook is renamed to path_setattr in the
     same patch, so that a stale BPF LSM program attaching to
     lsm/inode_setattr fails to load instead of reading dentry->d_flags
     where it expects iattr->ia_valid (see below)

Three deliberate scoping decisions for this refactor:

- The hooks consistently take struct path rather than struct file as
  their primary object.  The VFS call sites involved (chmod(2),
  chown(2), utimensat(2), xattr(2) and ACL syscalls) operate on
  paths, and several of them (lstat(2), lchown(2), llistxattr(2),
  ...) have no struct file to begin with.  The optional struct file
  argument carries the open-time semantic described below.

- struct inode_operations->setattr still receives (idmap, dentry, attr).
  Only the VFS boundary (notify_change()) and the LSM hook layer see the
  path, which keeps the refactor contained to fs/attr.c and the LSM
  infrastructure instead of touching every filesystem.

- The path argument of the hooks is only meant to be handed to VFS
  helpers taking a struct path (e.g., notify_change(), the xattr
  helpers): the VFS makes no guarantees with regard to path->mnt,
  whose layout and implementation details are subject to change, and
  implementations must not rely on its properties.  The idmap, in
  contrast, is passed separately so that the VFS and the filesystem
  are guaranteed to see the same idmap.

Unlike what was done for LANDLOCK_ACCESS_FS_TRUNCATE, no new file_*
hooks are introduced for the file descriptor flows: the metadata
hooks are already consumed by other LSMs (SELinux, Smack, EVM, IMA,
AppArmor, TOMOYO) on these flows, and routing them to new hooks
would either silently remove the other LSMs' checks, or keep the
path_* hooks as well and check twice with Landlock.  Passing the
struct file to the existing path_* hooks instead keeps the pipeline
and the other LSMs' behavior unchanged, while giving Landlock the
information it needs to apply the open-time semantic below.

Since these hooks now operate on paths rather than inodes, patches
8-13 rename them to the path_* naming convention used by the other
hooks that take a struct path (path_chmod, path_chown, path_link,
...).  The inode_setattr hook is renamed in patch 8, in the same patch
that changes its ctx layout: BPF LSM program arguments are retyped
from the hook prototype at verification time and are not checked
against a versioned ABI, so leaving the old name in place for a few
patches would let a stale program read dentry->d_flags where it
expects iattr->ia_valid, silently inverting a deny rule.  The
inode_getattr hook, which already received a struct path, is renamed
to path_getattr as well; patch 9 also threads the struct file held by
the fd-based vfs_fstat() and vfs_statx_fd() callers through it, while
the many kernel-internal vfs_getattr() callers keep a wrapper which
passes NULL.  Apart from patch 8 and the file threading in patch 9,
these renames are purely mechanical and can be reviewed independently.

Patch 14 then adds the access rights and implements their
enforcement, and patches 15-17 add the selftests, the sandboxer
sample update and the documentation.

Patch 14 applies the LANDLOCK_ACCESS_FS_TRUNCATE mechanic to the
new rights, following Mickaël's confirmation [4]: for operations on
already opened files, it is the access rights at the time of open(2)
which decide whether a metadata operation is permitted, not the
rights of the current thread.  READ_METADATA and WRITE_METADATA are
looked up at open time, recorded in the opened file, and consumed by
the metadata hooks when they are called with a file.  As a
consequence:

- A file descriptor opened before sandboxing keeps allowing metadata
  operations whatever the current domain is, which resolves the
  "catch-22" raised by Justin [5]: an already opened file descriptor
  keeps working, it is not an escape hatch because its rights were
  fixed when it was legitimate to open the file.
- Conversely, a restricted file descriptor passed to another
  (possibly non-landlocked) process keeps denying metadata
  operations: the file descriptor carries the rights of the process
  which opened it.
- ioctl(FS_IOC_GETFLAGS) and friends on a file descriptor opened
  without READ_METADATA are now denied, which closes the metadata
  leak Justin was concerned about.
- O_PATH file descriptors are an exception: they are not opened
  through the open permission checks (cf. do_dentry_open()) and
  carry no recorded rights; metadata accesses through them are
  checked against the current domain, like path-based accesses.
- File descriptors obtained without going through the file_open
  hook (e.g. memfd_create(2), pipes, sockets) keep the full access
  rights granted at file allocation time, consistent with the
  truncate behavior.
- deny_masks_t is widened from u8 to u16 to keep tracking one
  nibble per optional access right for the audit logs.

The Landlock ABI version is incremented from 12 to 13; ABI 12 was
taken by the capability and namespace use restrictions that are
already in linux-next.

The series is based on linux-next commit 749a4de37040 ("Add linux-next
specific files for 20261116").

Changes since v3 [6]:

- The empty-path branch of do_fchmodat(), do_fchownat() and
  do_utimes_path() used fdget(), which rejects O_PATH file
  descriptors.  It now uses fd_raw, the same lookup path_init() uses
  for an empty path, so AT_EMPTY_PATH metadata operations work again
  on O_PATH descriptors; futimens(2) keeps rejecting O_PATH, and a
  NULL pathname returns -EFAULT instead of being turned into an empty
  path (patch 8).
- Every hook that gained a struct file argument is declared with a
  strong file__nullable definition in kernel/bpf/bpf_lsm_proto.c, so
  the verifier requires a NULL check before dereferencing it
  (patches 5-12).
- The ntfs named stream setattr no longer bypasses the hooks: it goes
  through notify_change_target(), which performs the path-based LSM
  checks on the caller-supplied path while the attributes land on the
  base inode, and the borrowed path is dropped from the caller-owned
  struct iattr before notify_change() returns (patch 1).
- ecryptfs and overlayfs run the fileattr hooks on the real
  upper/lower path instead of calling unchecked helpers, and the
  ksmbd xattr helper passes the file it was given instead of NULL
  (patches 5 and 7).
- Since a trusted struct path lets BPF LSM programs reach path->dentry
  and call the dentry xattr kfuncs, the sleepable path hooks that
  always run under i_rwsem use the _locked kfunc variants, while the
  hooks that can run either way (path_link, path_rename, path_rmdir,
  path_unlink and path_getattr, which nfsd reaches with the inode
  already locked) reject both variants (patch 8).
- fchmod(2) and fchown(2) are not O_PATH-capable metadata interfaces
  and are no longer listed as such in the UAPI header and in the
  userspace documentation (patches 14 and 17).
- The setattr hook rename is folded into the patch that changes its
  ctx layout, so that a stale BPF LSM program cannot be silently
  reinterpreted, and that patch now comes right before the getattr
  rename (patch 8).
- ksmbd reports the share root for the ".." entry when follow_up()
  cannot leave a mount that was detached, instead of using a parent
  which that mount does not cover (patch 3).
- The Landlock changelog states that kernel-internal getattr calls
  made under the caller's credentials, such as NFS localio's
  post-write attribute refresh, are subject to READ_METADATA too, and
  that localio discards the resulting error (patch 14).

[1]
https://lore.kernel.org/all/20220827111215.131442-1-xiujianfeng@huawei.com/
[2]
https://lore.kernel.org/all/abc960a1-e66e-792e-6869-cfd201c29dbe@digikod.net/
[3]
https://lore.kernel.org/all/20261015125425.3246251-1-caixinchen1@huawei.com/
[4] https://lore.kernel.org/all/20260929.Ahgoo4yeetai@digikod.net/
[5] https://lore.kernel.org/all/arvjb0HJYh1KyEBB@suesslenovo/
[6]
https://lore.kernel.org/all/20261027121151.1887650-1-caixinchen1@huawei.com/

Cai Xinchen (17):
  fs: pass struct path to notify_change()
  LSM: pass struct path to the inode_setsecctx hook
  fs: pass struct path to xattr helpers
  fs: pass struct path to POSIX ACL helpers
  LSM: pass struct path and struct file to the inode xattr hooks
  LSM: pass struct path and struct file to the inode posix acl hooks
  LSM: pass struct path and struct file to the inode fileattr hooks
  LSM: rename inode_setattr to path_setattr and pass struct path and
    file
  LSM: rename inode_getattr to path_getattr and pass struct file
  LSM: rename the inode xattr hooks to path_xattr hooks
  LSM: rename the inode posix acl hooks to path_*_acl hooks
  LSM: rename the inode fileattr hooks to path_file_* hooks
  LSM: rename inode_setsecctx to path_setsecctx
  landlock: Add READ_METADATA and WRITE_METADATA access rights
  selftests/landlock: Add tests for metadata access rights
  samples/landlock: Add metadata rights to sandboxer
  Documentation: Update landlock doc for metadata rights

 Documentation/admin-guide/LSM/landlock.rst    |   2 +
 Documentation/bpf/fs_kfuncs.rst               |   2 +-
 Documentation/filesystems/porting.rst         |  63 ++
 Documentation/trace/events-landlock.rst       |  18 +-
 Documentation/userspace-api/landlock.rst      | 148 ++-
 drivers/base/devtmpfs.c                       |   6 +-
 drivers/block/loop.c                          |  12 +-
 drivers/block/zloop.c                         |  23 +-
 fs/attr.c                                     | 119 ++-
 fs/bpf_fs_kfuncs.c                            |  58 +-
 fs/btrfs/volumes.c                            |   2 +-
 fs/cachefiles/xattr.c                         |  45 +-
 fs/coredump.c                                 |   2 +-
 fs/ecryptfs/inode.c                           |  48 +-
 fs/exfat/file.c                               |   5 +-
 fs/fat/file.c                                 |   5 +-
 fs/file_attr.c                                | 136 ++-
 fs/init.c                                     |   6 +-
 fs/inode.c                                    |   7 +-
 fs/internal.h                                 |  26 +-
 fs/namei.c                                    |   5 +-
 fs/nfsd/nfs4ctl.h                             |   5 +-
 fs/nfsd/nfs4state.c                           |  16 +-
 fs/nfsd/nfs4xdr.c                             |   2 +-
 fs/nfsd/state.h                               |   2 +-
 fs/nfsd/vfs.c                                 |  87 +-
 fs/ntfs/named_stream.c                        |  14 +-
 fs/open.c                                     |  77 +-
 fs/overlayfs/copy_up.c                        |   4 +-
 fs/overlayfs/inode.c                          |  27 +-
 fs/overlayfs/overlayfs.h                      |  44 +-
 fs/overlayfs/xattrs.c                         |  12 +-
 fs/posix_acl.c                                |  61 +-
 fs/smb/server/smb2pdu.c                       |  59 +-
 fs/smb/server/smb_common.c                    |  59 +-
 fs/smb/server/smbacl.c                        |  12 +-
 fs/smb/server/vfs.c                           | 101 +-
 fs/smb/server/vfs.h                           |  19 +-
 fs/stat.c                                     |  82 +-
 fs/utimes.c                                   |  38 +-
 fs/xattr.c                                    | 114 ++-
 fs/xfs/xfs_ioctl.c                            |   2 +-
 include/linux/fileattr.h                      |  10 +-
 include/linux/fs.h                            |  30 +-
 include/linux/landlock.h                      |   4 +-
 include/linux/lsm_hook_defs.h                 |  66 +-
 include/linux/posix_acl.h                     |  25 +-
 include/linux/security.h                      | 131 +--
 include/linux/xattr.h                         |  32 +-
 include/uapi/linux/landlock.h                 |  47 +-
 init/initramfs.c                              |   2 +-
 kernel/bpf/bpf_lsm.c                          |  10 +-
 kernel/bpf/bpf_lsm_proto.c                    | 108 ++
 kernel/bpf/verifier.c                         |  13 +
 kernel/trace/bpf_trace.c                      |   2 +-
 samples/landlock/sandboxer.c                  |  16 +-
 security/apparmor/lsm.c                       |   5 +-
 security/commoncap.c                          |  17 +-
 security/integrity/evm/evm_crypto.c           |   8 +-
 security/integrity/evm/evm_main.c             |  77 +-
 security/integrity/ima/ima_appraise.c         |  41 +-
 security/landlock/access.h                    |  13 +-
 security/landlock/fs.c                        | 235 ++++-
 security/landlock/limits.h                    |   2 +-
 security/landlock/syscalls.c                  |   2 +-
 security/security.c                           | 179 ++--
 security/selinux/hooks.c                      | 105 +-
 security/smack/smack_lsm.c                    | 128 ++-
 security/tomoyo/tomoyo.c                      |   8 +-
 .../testing/selftests/bpf/prog_tests/d_path.c |   2 +-
 .../selftests/bpf/prog_tests/fs_kfuncs.c      |  10 +-
 .../testing/selftests/bpf/progs/test_d_path.c |   5 +-
 .../bpf/progs/test_d_path_check_rdonly_mem.c  |   5 +-
 .../bpf/progs/test_d_path_check_types.c       |   5 +-
 .../selftests/bpf/progs/test_get_xattr.c      |   7 +-
 .../bpf/progs/test_set_remove_xattr.c         |  34 +-
 .../bpf/progs/verifier_lsm_init_xattr.c       |   8 +-
 .../selftests/bpf/progs/verifier_vfs_accept.c |   2 +-
 .../selftests/bpf/progs/verifier_vfs_reject.c |   2 +-
 tools/testing/selftests/landlock/base_test.c  |   2 +-
 tools/testing/selftests/landlock/fs_test.c    | 932 +++++++++++++++++-
 .../selftests/landlock/trace_fs_test.c        |   3 +-
 82 files changed, 3003 insertions(+), 905 deletions(-)

-- 
2.18.0.huawei.25


^ permalink raw reply	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 01/17] fs: pass struct path to notify_change()
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 14:48   ` sashiko-bot
  2026-11-17 18:30   ` Al Viro
  2026-11-17 15:05 ` [PATCH -next -v4 02/17] LSM: pass struct path to the inode_setsecctx hook Cai Xinchen
                   ` (15 subsequent siblings)
  16 siblings, 2 replies; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

notify_change() and do_truncate() take a struct dentry even though their
callers either hold a struct path (or a struct file) or only need the
mount they already use to build one.  Pass a struct path instead; the
idmap stays a separate argument, as it must be taken from the mount when
the path is checked and passed down unchanged.

The NTFS named stream support forwards a change to the base inode.  Add a
notify_change_target() helper for it, and record the path the change was
requested through in the new iattr.ia_path field, which is only valid for
the duration of the notify_change() call and must not be stored.

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 Documentation/filesystems/porting.rst |  12 +++
 drivers/base/devtmpfs.c               |   6 +-
 fs/attr.c                             | 109 +++++++++++++++++++-------
 fs/coredump.c                         |   2 +-
 fs/ecryptfs/inode.c                   |  15 ++--
 fs/inode.c                            |   7 +-
 fs/namei.c                            |   5 +-
 fs/nfsd/nfs4state.c                   |  16 ++--
 fs/nfsd/nfs4xdr.c                     |   2 +-
 fs/nfsd/state.h                       |   2 +-
 fs/nfsd/vfs.c                         |  15 +++-
 fs/ntfs/named_stream.c                |  13 ++-
 fs/open.c                             |  17 ++--
 fs/overlayfs/overlayfs.h              |   7 +-
 fs/smb/server/smb2pdu.c               |   2 +-
 fs/smb/server/smbacl.c                |   2 +-
 fs/utimes.c                           |   2 +-
 include/linux/fs.h                    |  20 ++++-
 18 files changed, 177 insertions(+), 77 deletions(-)

diff --git a/Documentation/filesystems/porting.rst b/Documentation/filesystems/porting.rst
index 8623731e6b48..82be56207772 100644
--- a/Documentation/filesystems/porting.rst
+++ b/Documentation/filesystems/porting.rst
@@ -1435,3 +1435,15 @@ directory has been created.  Filesystems that cannot do this, those
 that implement ->atomic_open() and those whose ->mkdir() drops the
 parent's i_rwsem, must set SB_I_NO_ATOMIC_MKDIR in sb->s_iflags, which
 makes that flag combination fail with -EOPNOTSUPP before any lookup.
+
+---
+
+**mandatory**
+
+notify_change() and do_truncate() now take a const struct path * instead
+of a struct dentry *.  They use path->dentry, so callers that only have a
+dentry must provide a struct path.  struct iattr has a new ia_path member,
+which notify_change() sets for the duration of the call; it must not be
+stored beyond that.  Filesystems that forward a change to another inode
+can use notify_change_target() to update the target dentry while keeping
+the caller-supplied path in ia_path.
diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
index 11c70888f38b..410906a66ee9 100644
--- a/drivers/base/devtmpfs.c
+++ b/drivers/base/devtmpfs.c
@@ -284,13 +284,14 @@ static int handle_create(const char *nodename, umode_t mode, kuid_t uid,
 			dev->devt, NULL);
 	if (!err) {
 		struct iattr newattrs;
+		struct path attr_path = { .mnt = path.mnt, .dentry = dentry };
 
 		newattrs.ia_mode = mode;
 		newattrs.ia_uid = uid;
 		newattrs.ia_gid = gid;
 		newattrs.ia_valid = ATTR_MODE|ATTR_UID|ATTR_GID;
 		inode_lock(d_inode(dentry));
-		notify_change(&nop_mnt_idmap, dentry, &newattrs, NULL);
+		notify_change(&nop_mnt_idmap, &attr_path, &newattrs, NULL);
 		inode_unlock(d_inode(dentry));
 
 		/* mark as kernel-created inode */
@@ -380,6 +381,7 @@ static int handle_remove(const char *nodename, struct device *dev)
 	inode = d_inode(dentry);
 	if (dev_mynode(dev, inode)) {
 		struct iattr newattrs;
+		struct path attr_path = { .mnt = parent.mnt, .dentry = dentry };
 		/*
 		 * before unlinking this node, reset permissions
 		 * of possible references like hardlinks
@@ -390,7 +392,7 @@ static int handle_remove(const char *nodename, struct device *dev)
 		newattrs.ia_valid =
 			ATTR_UID|ATTR_GID|ATTR_MODE;
 		inode_lock(d_inode(dentry));
-		notify_change(&nop_mnt_idmap, dentry, &newattrs, NULL);
+		notify_change(&nop_mnt_idmap, &attr_path, &newattrs, NULL);
 		inode_unlock(d_inode(dentry));
 		err = vfs_unlink(&nop_mnt_idmap, d_inode(parent.dentry),
 				 dentry, NULL);
diff --git a/fs/attr.c b/fs/attr.c
index 9706d370f34a..f8fd0f061612 100644
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -397,35 +397,11 @@ int may_setattr(const struct mnt_idmap *idmap, struct inode *inode,
 }
 EXPORT_SYMBOL(may_setattr);
 
-/**
- * notify_change - modify attributes of a filesystem object
- * @idmap:	idmap of the mount the inode was found from
- * @dentry:	object affected
- * @attr:	new attributes
- * @delegated_inode: returns inode, if the inode is delegated
- *
- * The caller must hold the i_rwsem exclusively on the affected object.
- *
- * If notify_change discovers a delegation in need of breaking,
- * it will return -EWOULDBLOCK and return a reference to the inode in
- * delegated_inode.  The caller should then break the delegation and
- * retry.  Because breaking a delegation may take a long time, the
- * caller should drop the i_rwsem before doing so.
- *
- * Alternatively, a caller may pass NULL for delegated_inode.  This may
- * be appropriate for callers that expect the underlying filesystem not
- * to be NFS exported.  Also, passing NULL is fine for callers holding
- * the file open for write, as there can be no conflicting delegation in
- * that case.
- *
- * If the inode has been found through an idmapped mount the idmap of
- * the vfsmount must be passed through @idmap. This function will then
- * take care to map the inode according to @idmap before checking
- * permissions. On non-idmapped mounts or if permission checking is to be
- * performed on the raw inode simply pass @nop_mnt_idmap.
- */
-int notify_change(const struct mnt_idmap *idmap, struct dentry *dentry,
-		  struct iattr *attr, struct delegated_inode *delegated_inode)
+static int do_notify_change(const struct path *const path,
+			    const struct mnt_idmap *const idmap,
+			    struct dentry *const dentry,
+			    struct iattr *attr,
+			    struct delegated_inode *delegated_inode)
 {
 	struct inode *inode = dentry->d_inode;
 	umode_t mode = inode->i_mode;
@@ -552,11 +528,21 @@ int notify_change(const struct mnt_idmap *idmap, struct dentry *dentry,
 			return error;
 	}
 
+	/*
+	 * Filesystems that forward the change to another inode (e.g. NTFS
+	 * named streams) can pass @ia_path back to notify_change_target()
+	 * instead of losing the path the change was requested through.
+	 */
+	attr->ia_path = path;
+
 	if (inode->i_op->setattr)
 		error = inode->i_op->setattr(idmap, dentry, attr);
 	else
 		error = simple_setattr(idmap, dentry, attr);
 
+	/* @attr is caller-owned: do not leave a borrowed path behind. */
+	attr->ia_path = NULL;
+
 	if (!error) {
 		fsnotify_change(dentry, ia_valid);
 		security_inode_post_setattr(idmap, dentry, ia_valid);
@@ -564,4 +550,69 @@ int notify_change(const struct mnt_idmap *idmap, struct dentry *dentry,
 
 	return error;
 }
+
+/**
+ * notify_change - modify attributes of a filesystem object
+ * @idmap:	idmap of the mount the inode was found from
+ * @path:	object affected
+ * @attr:	new attributes
+ * @delegated_inode: returns inode, if the inode is delegated
+ *
+ * The caller must hold the i_rwsem exclusively on the affected object.
+ *
+ * If notify_change discovers a delegation in need of breaking,
+ * it will return -EWOULDBLOCK and return a reference to the inode in
+ * delegated_inode.  The caller should then break the delegation and
+ * retry.  Because breaking a delegation may take a long time, the
+ * caller should drop the i_rwsem before doing so.
+ *
+ * Alternatively, a caller may pass NULL for delegated_inode.  This may
+ * be appropriate for callers that expect the underlying filesystem not
+ * to be NFS exported.  Also, passing NULL is fine for callers holding
+ * the file open for write, as there can be no conflicting delegation in
+ * that case.
+ *
+ * If the inode has been found through an idmapped mount the idmap of
+ * the vfsmount must be passed through @idmap. This function will then
+ * take care to map the inode according to @idmap before checking
+ * permissions. On non-idmapped mounts or if permission checking is to
+ * be performed on the raw inode simply pass @nop_mnt_idmap.
+ *
+ * Return: 0 on success, or a negative error on failure.
+ */
+int notify_change(const struct mnt_idmap *idmap, const struct path *path,
+		  struct iattr *attr, struct delegated_inode *delegated_inode)
+{
+	return do_notify_change(path, idmap, path->dentry, attr,
+				delegated_inode);
+}
 EXPORT_SYMBOL(notify_change);
+
+/**
+ * notify_change_target - change attributes of a target inode
+ * @idmap: idmap of the mount the inode was found from
+ * @path: path on which the change was requested
+ * @target: dentry of the inode whose attributes are changed
+ * @attr: attributes to change
+ * @delegated_inode: returns inode needing a delegation break
+ *
+ * This is for filesystems that apply a metadata change to an inode other
+ * than the one the caller named (e.g. NTFS named streams).  The path the
+ * change was requested through is recorded in @attr->ia_path so that the
+ * caller can pass it back when it forwards the change; @target supplies
+ * the inode to update.  @target must be the inode of the same file as
+ * @path, e.g. the base inode of a named stream.  The caller must hold the
+ * i_rwsem exclusively on @target.
+ *
+ * Return: 0 on success, or a negative error on failure.
+ */
+int notify_change_target(const struct mnt_idmap *idmap,
+			 const struct path *path, struct dentry *target,
+			 struct iattr *attr,
+			 struct delegated_inode *delegated_inode)
+{
+	if (WARN_ON_ONCE(!target))
+		return -EINVAL;
+	return do_notify_change(path, idmap, target, attr, delegated_inode);
+}
+EXPORT_SYMBOL_GPL(notify_change_target);
diff --git a/fs/coredump.c b/fs/coredump.c
index 82ef9d115999..3f6921e7fe60 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -1060,7 +1060,7 @@ static bool coredump_file(struct core_name *cn, struct coredump_params *cprm,
 	}
 	if (!(file->f_mode & FMODE_CAN_WRITE))
 		return false;
-	if (do_truncate(idmap, file->f_path.dentry, 0, 0, file))
+	if (do_truncate(idmap, &file->f_path, 0, 0, file))
 		return false;
 
 	cprm->file = no_free_ptr(file);
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index 48e520960d66..26967e4e4660 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -732,7 +732,8 @@ upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat,
  */
 static int __ecryptfs_truncate(struct dentry *dentry, const struct iattr *ia)
 {
-	struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
+	struct path lower_path = ecryptfs_lower_path(dentry);
+	struct dentry *lower_dentry = lower_path.dentry;
 	struct inode *inode = d_inode(dentry);
 	struct ecryptfs_crypt_stat *crypt_stat;
 	loff_t i_size = i_size_read(inode);
@@ -821,7 +822,7 @@ static int __ecryptfs_truncate(struct dentry *dentry, const struct iattr *ia)
 set_size:
 	lower_ia.ia_valid |= ATTR_SIZE;
 	inode_lock(d_inode(lower_dentry));
-	rc = notify_change(&nop_mnt_idmap, lower_dentry, &lower_ia, NULL);
+	rc = notify_change(&nop_mnt_idmap, &lower_path, &lower_ia, NULL);
 	inode_unlock(d_inode(lower_dentry));
 out:
 	ecryptfs_put_lower_file(inode);
@@ -873,7 +874,6 @@ static int ecryptfs_setattr(const struct mnt_idmap *idmap,
 			    struct dentry *dentry, struct iattr *ia)
 {
 	struct inode *inode = d_inode(dentry);
-	struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
 	struct inode *lower_inode = ecryptfs_inode_to_lower(inode);
 	struct ecryptfs_crypt_stat *crypt_stat;
 	int rc;
@@ -925,14 +925,15 @@ static int ecryptfs_setattr(const struct mnt_idmap *idmap,
 	if (ia->ia_valid & ATTR_SIZE) {
 		rc = __ecryptfs_truncate(dentry, ia);
 	} else {
+		struct path lower_path = ecryptfs_lower_path(dentry);
 		struct iattr lower_ia;
 
 		ecryptfs_iattr_to_lower(&lower_ia, ia);
 
-		inode_lock(d_inode(lower_dentry));
-		rc = notify_change(&nop_mnt_idmap, lower_dentry, &lower_ia,
-				NULL);
-		inode_unlock(d_inode(lower_dentry));
+		inode_lock(d_inode(lower_path.dentry));
+		rc = notify_change(&nop_mnt_idmap, &lower_path, &lower_ia,
+				   NULL);
+		inode_unlock(d_inode(lower_path.dentry));
 	}
 out:
 	fsstack_copy_attr_all(inode, lower_inode);
diff --git a/fs/inode.c b/fs/inode.c
index f2003ae75374..e4af8a44932b 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -2379,7 +2379,7 @@ int dentry_needs_remove_privs(const struct mnt_idmap *idmap,
 }
 
 static int __remove_privs(const struct mnt_idmap *idmap,
-			  struct dentry *dentry, int kill)
+			  const struct path *path, int kill)
 {
 	struct iattr newattrs;
 
@@ -2388,7 +2388,7 @@ static int __remove_privs(const struct mnt_idmap *idmap,
 	 * Note we call this on write, so notify_change will not
 	 * encounter any conflicting delegations:
 	 */
-	return notify_change(idmap, dentry, &newattrs, NULL);
+	return notify_change(idmap, path, &newattrs, NULL);
 }
 
 static int file_remove_privs_flags(struct file *file, unsigned int flags)
@@ -2409,7 +2409,8 @@ static int file_remove_privs_flags(struct file *file, unsigned int flags)
 		if (flags & IOCB_NOWAIT)
 			return -EAGAIN;
 
-		error = __remove_privs(file_mnt_idmap(file), dentry, kill);
+		error = __remove_privs(file_mnt_idmap(file), &file->f_path,
+				       kill);
 	}
 
 	if (!error)
diff --git a/fs/namei.c b/fs/namei.c
index f573fd0aacaf..03d3d20b64e1 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -4391,9 +4391,8 @@ static int handle_truncate(const struct mnt_idmap *idmap, struct file *filp)
 
 	error = security_file_truncate(filp);
 	if (!error) {
-		error = do_truncate(idmap, path->dentry, 0,
-				    ATTR_MTIME|ATTR_CTIME|ATTR_OPEN,
-				    filp);
+		error = do_truncate(idmap, path, 0,
+				    ATTR_MTIME|ATTR_CTIME|ATTR_OPEN, filp);
 	}
 	put_write_access(inode);
 	return error;
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 85da5776c0df..b89898fe6323 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -10517,8 +10517,10 @@ bool nfsd4_vet_deleg_time(struct timespec64 *req, const struct timespec64 *orig,
 	return true;
 }
 
-static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_delegation *dp)
+static int cb_getattr_update_times(const struct path *path,
+				   struct nfs4_delegation *dp)
 {
+	struct dentry *dentry = path->dentry;
 	struct inode *inode = d_inode(dentry);
 	struct nfs4_cb_fattr *ncf = &dp->dl_cb_fattr;
 	struct iattr attrs = { };
@@ -10548,7 +10550,7 @@ static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_delegation
 
 	attrs.ia_valid |= ATTR_DELEG;
 	inode_lock(inode);
-	ret = notify_change(&nop_mnt_idmap, dentry, &attrs, NULL);
+	ret = notify_change(&nop_mnt_idmap, path, &attrs, NULL);
 	inode_unlock(inode);
 	return ret;
 }
@@ -10556,7 +10558,7 @@ static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_delegation
 /**
  * nfsd4_deleg_getattr_conflict - Recall if GETATTR causes conflict
  * @rqstp: RPC transaction context
- * @dentry: dentry of inode to be checked for a conflict
+ * @path: path of inode to be checked for a conflict
  * @pdp: returned WRITE delegation, if one was found
  *
  * This function is called when there is a conflict between a write
@@ -10571,7 +10573,7 @@ static int cb_getattr_update_times(struct dentry *dentry, struct nfs4_delegation
  * caller must put the reference.
  */
 __be32
-nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry,
+nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, const struct path *path,
 			     struct nfs4_delegation **pdp)
 {
 	struct nfsd_thread_local_info *ntli = rqstp->rq_private;
@@ -10579,7 +10581,7 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry,
 	struct nfs4_delegation *dp = NULL;
 	struct file_lease *fl;
 	struct nfs4_cb_fattr *ncf;
-	struct inode *inode = d_inode(dentry);
+	struct inode *inode = d_inode(path->dentry);
 	__be32 status;
 
 	ctx = locks_inode_context(inode);
@@ -10643,7 +10645,7 @@ nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp, struct dentry *dentry,
 		 * not update the file's metadata with the client's
 		 * modified size
 		 */
-		err = cb_getattr_update_times(dentry, dp);
+		err = cb_getattr_update_times(path, dp);
 		if (err) {
 			status = nfserrno(err);
 			goto out_status;
@@ -10829,7 +10831,7 @@ void nfsd_update_cmtime_attr(struct file *f, unsigned int flags)
 	};
 
 	inode_lock(inode);
-	ret = notify_change(&nop_mnt_idmap, f->f_path.dentry, &attr, NULL);
+	ret = notify_change(&nop_mnt_idmap, &f->f_path, &attr, NULL);
 	inode_unlock(inode);
 	if (ret)
 		pr_notice_ratelimited("nfsd: Unable to update timestamps on "
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index c4fd840da4d9..e32d69bd06d9 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -4083,7 +4083,7 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,
 	    (attrmask[1] & (FATTR4_WORD1_TIME_ACCESS |
 			    FATTR4_WORD1_TIME_MODIFY |
 			    FATTR4_WORD1_TIME_METADATA))) {
-		status = nfsd4_deleg_getattr_conflict(rqstp, dentry, &dp);
+		status = nfsd4_deleg_getattr_conflict(rqstp, &path, &dp);
 		if (status)
 			goto out;
 	}
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index 79dfa47b82db..a38943688ce2 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -1019,7 +1019,7 @@ static inline bool try_to_expire_client(struct nfs4_client *clp)
 }
 
 extern __be32 nfsd4_deleg_getattr_conflict(struct svc_rqst *rqstp,
-		struct dentry *dentry, struct nfs4_delegation **pdp);
+		const struct path *path, struct nfs4_delegation **pdp);
 
 struct nfsd4_get_dir_delegation;
 struct nfs4_delegation *nfsd_get_dir_deleg(struct nfsd4_compound_state *cstate,
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index cf6c81d04df4..359277716fe8 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -455,7 +455,7 @@ nfsd_get_write_access(struct svc_fh *fhp)
 	return nfserrno(get_write_access(d_inode(fhp->fh_dentry)));
 }
 
-static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)
+static int __nfsd_setattr(const struct path *path, struct iattr *iap)
 {
 	int host_err;
 
@@ -475,7 +475,8 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)
 		if (iap->ia_size < 0)
 			return -EFBIG;
 
-		host_err = notify_change(&nop_mnt_idmap, dentry, &size_attr, NULL);
+		host_err = notify_change(&nop_mnt_idmap, path, &size_attr,
+					  NULL);
 		if (host_err)
 			return host_err;
 		iap->ia_valid &= ~ATTR_SIZE;
@@ -501,7 +502,7 @@ static int __nfsd_setattr(struct dentry *dentry, struct iattr *iap)
 	if (!(iap->ia_valid & ATTR_DELEG))
 		iap->ia_valid |= ATTR_CTIME;
 
-	return notify_change(&nop_mnt_idmap, dentry, iap, NULL);
+	return notify_change(&nop_mnt_idmap, path, iap, NULL);
 }
 
 /**
@@ -522,6 +523,7 @@ __be32
 nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	     struct nfsd_attrs *attr, const struct timespec64 *guardtime)
 {
+	struct path	path;
 	struct dentry	*dentry;
 	struct inode	*inode;
 	struct iattr	*iap = attr->na_iattr;
@@ -569,6 +571,11 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
 	dentry = fhp->fh_dentry;
 	inode = d_inode(dentry);
 
+	path = (struct path){
+		.mnt	= fhp->fh_export->ex_path.mnt,
+		.dentry	= dentry,
+	};
+
 	nfsd_sanitize_attrs(inode, iap);
 
 	/*
@@ -612,7 +619,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
 		 * copy for every loop iteration.
 		 */
 		attrs = *iap;
-		host_err = __nfsd_setattr(dentry, &attrs);
+		host_err = __nfsd_setattr(&path, &attrs);
 		if (host_err != -EAGAIN || !retries--)
 			break;
 		if (!nfsd_wait_for_delegreturn(rqstp, inode))
diff --git a/fs/ntfs/named_stream.c b/fs/ntfs/named_stream.c
index 70c589207713..1c55588df5ba 100644
--- a/fs/ntfs/named_stream.c
+++ b/fs/ntfs/named_stream.c
@@ -896,11 +896,16 @@ static int ntfs_stream_setattr_common(const struct mnt_idmap *idmap,
 			inode_unlock(base_vi);
 			goto out;
 		}
-		if (base_attr.ia_valid)
-			err = notify_change(idmap, base_dentry, &base_attr,
-					NULL);
-		else
+		if (base_attr.ia_valid) {
+			if (WARN_ON_ONCE(!attr->ia_path)) {
+				err = -EINVAL;
+			} else {
+				err = notify_change_target(idmap, attr->ia_path,
+							   base_dentry, &base_attr, NULL);
+			}
+		} else {
 			err = 0;
+		}
 		if (!err)
 			ntfs_stream_inode_refresh(inode);
 		inode_unlock(base_vi);
diff --git a/fs/open.c b/fs/open.c
index 4dfbe87e7775..a96d490915f6 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -36,10 +36,11 @@
 
 #include "internal.h"
 
-int do_truncate(const struct mnt_idmap *idmap, struct dentry *dentry,
+int do_truncate(const struct mnt_idmap *idmap, const struct path *path,
 		loff_t length, unsigned int time_attrs, struct file *filp)
 {
 	int ret;
+	struct dentry *dentry = path->dentry;
 	struct iattr newattrs;
 
 	/* Not pretty: "inode->i_size" shouldn't really be signed. But it is. */
@@ -65,7 +66,7 @@ int do_truncate(const struct mnt_idmap *idmap, struct dentry *dentry,
 		return ret;
 
 	/* Note any delegations or leases have already been broken: */
-	ret = notify_change(idmap, dentry, &newattrs, NULL);
+	ret = notify_change(idmap, path, &newattrs, NULL);
 	inode_unlock(dentry->d_inode);
 	return ret;
 }
@@ -115,7 +116,7 @@ int vfs_truncate(const struct path *path, loff_t length)
 
 	error = security_path_truncate(path);
 	if (!error)
-		error = do_truncate(idmap, path->dentry, length, 0, NULL);
+		error = do_truncate(idmap, path, length, 0, NULL);
 
 put_write_and_out:
 	put_write_access(inode);
@@ -191,8 +192,8 @@ int do_ftruncate(struct file *file, loff_t length, unsigned int flags)
 		return error;
 
 	scoped_guard(super_write, inode->i_sb)
-		return do_truncate(file_mnt_idmap(file), dentry, length,
-				   ATTR_MTIME | ATTR_CTIME, file);
+		return do_truncate(file_mnt_idmap(file), &file->f_path,
+				   length, ATTR_MTIME | ATTR_CTIME, file);
 }
 
 int ksys_ftruncate(unsigned int fd, loff_t length, unsigned int flags)
@@ -683,8 +684,8 @@ int chmod_common(const struct path *path, umode_t mode)
 		goto out_unlock;
 	newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
 	newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
-	error = notify_change(mnt_idmap(path->mnt), path->dentry,
-			      &newattrs, &delegated_inode);
+	error = notify_change(mnt_idmap(path->mnt), path, &newattrs,
+			      &delegated_inode);
 out_unlock:
 	inode_unlock(inode);
 	if (is_delegated(&delegated_inode)) {
@@ -822,7 +823,7 @@ int chown_common(const struct path *path, uid_t user, gid_t group)
 		from_vfsuid(idmap, fs_userns, newattrs.ia_vfsuid),
 		from_vfsgid(idmap, fs_userns, newattrs.ia_vfsgid));
 	if (!error)
-		error = notify_change(idmap, path->dentry, &newattrs,
+		error = notify_change(idmap, path, &newattrs,
 				      &delegated_inode);
 	inode_unlock(inode);
 	if (is_delegated(&delegated_inode)) {
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index 646f8ffc40ae..c6f67672460d 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -214,7 +214,12 @@ static inline int ovl_do_notify_change(struct ovl_fs *ofs,
 				       struct dentry *upperdentry,
 				       struct iattr *attr)
 {
-	return notify_change(ovl_upper_mnt_idmap(ofs), upperdentry, attr, NULL);
+	struct path path = {
+		.mnt = ovl_upper_mnt(ofs),
+		.dentry = upperdentry,
+	};
+
+	return notify_change(ovl_upper_mnt_idmap(ofs), &path, attr, NULL);
 }
 
 static inline int ovl_do_rmdir(struct ovl_fs *ofs,
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index b74dafe6a307..4832decf6478 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -9080,7 +9080,7 @@ static int set_file_basic_info(struct ksmbd_file *fp,
 		}
 
 		inode_lock(inode);
-		rc = notify_change(idmap, dentry, &attrs, NULL);
+		rc = notify_change(idmap, &filp->f_path, &attrs, NULL);
 		inode_unlock(inode);
 	}
 out:
diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c
index 9aac87ff3b4a..c2863b9f92ba 100644
--- a/fs/smb/server/smbacl.c
+++ b/fs/smb/server/smbacl.c
@@ -1973,7 +1973,7 @@ int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon,
 	}
 
 	inode_lock(inode);
-	rc = notify_change(idmap, path->dentry, &newattrs, NULL);
+	rc = notify_change(idmap, path, &newattrs, NULL);
 	inode_unlock(inode);
 	if (get_write)
 		mnt_drop_write(path->mnt);
diff --git a/fs/utimes.c b/fs/utimes.c
index e22664e4115f..5193d504d289 100644
--- a/fs/utimes.c
+++ b/fs/utimes.c
@@ -64,7 +64,7 @@ int vfs_utimes(const struct path *path, struct timespec64 *times)
 	}
 retry_deleg:
 	inode_lock(inode);
-	error = notify_change(mnt_idmap(path->mnt), path->dentry, &newattrs,
+	error = notify_change(mnt_idmap(path->mnt), path, &newattrs,
 			      &delegated_inode);
 	inode_unlock(inode);
 	if (is_delegated(&delegated_inode)) {
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 58d25fc23ec4..cd19aa264a98 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -289,6 +289,16 @@ struct iattr {
 	 * check for (ia_valid & ATTR_FILE), and not for (ia_file != NULL).
 	 */
 	struct file	*ia_file;
+
+	/*
+	 * Not an attribute, but the path on which the change was requested.
+	 * This is set by notify_change() so that filesystems which forward a
+	 * change to another inode (e.g. NTFS named streams) can pass the path
+	 * supplied by the caller back to notify_change_target().  The pointer
+	 * is valid only for the duration of the notify_change() call and must
+	 * not be stored.
+	 */
+	const struct path *ia_path;
 };
 
 /*
@@ -2495,8 +2505,8 @@ static inline bool is_idmapped_mnt(const struct vfsmount *mnt)
 }
 
 int vfs_truncate(const struct path *, loff_t);
-int do_truncate(const struct mnt_idmap *, struct dentry *, loff_t start,
-		unsigned int time_attrs, struct file *filp);
+int do_truncate(const struct mnt_idmap *idmap, const struct path *path,
+		loff_t length, unsigned int time_attrs, struct file *filp);
 extern int vfs_fallocate(struct file *file, int mode, loff_t offset,
 			loff_t len);
 int do_sys_open(int dfd, const char __user *filename, int flags,
@@ -2719,8 +2729,12 @@ static inline int bmap(struct inode *inode,  sector_t *block)
 }
 #endif
 
-int notify_change(const struct mnt_idmap *, struct dentry *,
+int notify_change(const struct mnt_idmap *, const struct path *,
 		  struct iattr *, struct delegated_inode *);
+int notify_change_target(const struct mnt_idmap *idmap,
+			 const struct path *path, struct dentry *target,
+			 struct iattr *attr,
+			 struct delegated_inode *delegated_inode);
 int inode_permission(const struct mnt_idmap *, struct inode *, int);
 int generic_permission(const struct mnt_idmap *, struct inode *, int);
 static inline int file_permission(struct file *file, int mask)
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 02/17] LSM: pass struct path to the inode_setsecctx hook
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
  2026-11-17 15:05 ` [PATCH -next -v4 01/17] fs: pass struct path to notify_change() Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 14:43   ` sashiko-bot
  2026-11-17 18:43   ` Al Viro
  2026-11-17 15:05 ` [PATCH -next -v4 03/17] fs: pass struct path to xattr helpers Cai Xinchen
                   ` (14 subsequent siblings)
  16 siblings, 2 replies; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

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.

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 fs/nfsd/vfs.c                 | 2 +-
 include/linux/lsm_hook_defs.h | 9 ++++++++-
 include/linux/security.h      | 5 +++--
 security/security.c           | 6 +++---
 security/selinux/hooks.c      | 7 ++++---
 security/smack/smack_lsm.c    | 6 +++---
 6 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 359277716fe8..1c686b82e70a 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -626,7 +626,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
 			break;
 	}
 	if (attr->na_seclabel && attr->na_seclabel->len)
-		attr->na_labelerr = security_inode_setsecctx(dentry,
+		attr->na_labelerr = security_inode_setsecctx(&path,
 			attr->na_seclabel->data, attr->na_seclabel->len);
 	if (IS_ENABLED(CONFIG_FS_POSIX_ACL) && attr->na_dpacl) {
 		if (!S_ISDIR(inode->i_mode))
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index 87d9d06710cb..7d3cd5395365 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -25,6 +25,12 @@
  *   #include <linux/lsm_hook_defs.h>
  *   #undef LSM_HOOK
  * };
+ *
+ * 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.
  */
 LSM_HOOK(int, 0, binder_set_context_mgr, const struct cred *mgr)
 LSM_HOOK(int, 0, binder_transaction, const struct cred *from,
@@ -313,7 +319,8 @@ LSM_HOOK(int, 0, secctx_to_secid, const char *secdata, u32 seclen, u32 *secid)
 LSM_HOOK(void, LSM_RET_VOID, release_secctx, struct lsm_context *cp)
 LSM_HOOK(void, LSM_RET_VOID, inode_invalidate_secctx, struct inode *inode)
 LSM_HOOK(int, 0, inode_notifysecctx, struct inode *inode, void *ctx, u32 ctxlen)
-LSM_HOOK(int, 0, inode_setsecctx, struct dentry *dentry, void *ctx, u32 ctxlen)
+LSM_HOOK(int, 0, inode_setsecctx, const struct path *path, void *ctx,
+	 u32 ctxlen)
 LSM_HOOK(int, -EOPNOTSUPP, inode_getsecctx, struct inode *inode,
 	 struct lsm_context *cp)
 
diff --git a/include/linux/security.h b/include/linux/security.h
index 40831fab5470..b9cae538b6fc 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -588,7 +588,7 @@ int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid);
 void security_release_secctx(struct lsm_context *cp);
 void security_inode_invalidate_secctx(struct inode *inode);
 int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen);
-int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen);
+int security_inode_setsecctx(const struct path *path, void *ctx, u32 ctxlen);
 int security_inode_getsecctx(struct inode *inode, struct lsm_context *cp);
 int security_locked_down(enum lockdown_reason what);
 int lsm_fill_user_ctx(struct lsm_ctx __user *uctx, u32 *uctx_len,
@@ -1630,7 +1630,8 @@ static inline int security_inode_notifysecctx(struct inode *inode, void *ctx, u3
 {
 	return -EOPNOTSUPP;
 }
-static inline int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
+static inline int security_inode_setsecctx(const struct path *path, void *ctx,
+					   u32 ctxlen)
 {
 	return -EOPNOTSUPP;
 }
diff --git a/security/security.c b/security/security.c
index 4727b8347fc4..7e6a8a2a2ee5 100644
--- a/security/security.c
+++ b/security/security.c
@@ -4110,7 +4110,7 @@ EXPORT_SYMBOL(security_inode_notifysecctx);
 
 /**
  * security_inode_setsecctx() - Change the security label of an inode
- * @dentry: inode
+ * @path: inode (the VFS makes no guarantees with regard to @path->mnt)
  * @ctx: secctx
  * @ctxlen: length of secctx
  *
@@ -4124,9 +4124,9 @@ EXPORT_SYMBOL(security_inode_notifysecctx);
  *
  * Return: Returns 0 on success, error on failure.
  */
-int security_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
+int security_inode_setsecctx(const struct path *path, void *ctx, u32 ctxlen)
 {
-	return call_int_hook(inode_setsecctx, dentry, ctx, ctxlen);
+	return call_int_hook(inode_setsecctx, path, ctx, ctxlen);
 }
 EXPORT_SYMBOL(security_inode_setsecctx);
 
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index da83f4111bdf..6ecb5f9657e6 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -7148,10 +7148,11 @@ static int selinux_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen
 /*
  *	called with inode->i_mutex locked
  */
-static int selinux_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
+static int selinux_inode_setsecctx(const struct path *path, void *ctx,
+				   u32 ctxlen)
 {
-	return __vfs_setxattr_locked(&nop_mnt_idmap, dentry, XATTR_NAME_SELINUX,
-				     ctx, ctxlen, 0, NULL);
+	return __vfs_setxattr_locked(&nop_mnt_idmap, path->dentry,
+				     XATTR_NAME_SELINUX, ctx, ctxlen, 0, NULL);
 }
 
 static int selinux_inode_getsecctx(struct inode *inode, struct lsm_context *cp)
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 2192cdcabfe2..f2c34e9ea4f8 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -4982,10 +4982,10 @@ static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
 				       ctxlen, 0);
 }
 
-static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
+static int smack_inode_setsecctx(const struct path *path, void *ctx, u32 ctxlen)
 {
-	return __vfs_setxattr_locked(&nop_mnt_idmap, dentry, XATTR_NAME_SMACK,
-				     ctx, ctxlen, 0, NULL);
+	return __vfs_setxattr_locked(&nop_mnt_idmap, path->dentry,
+				     XATTR_NAME_SMACK, ctx, ctxlen, 0, NULL);
 }
 
 static int smack_inode_getsecctx(struct inode *inode, struct lsm_context *cp)
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 03/17] fs: pass struct path to xattr helpers
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
  2026-11-17 15:05 ` [PATCH -next -v4 01/17] fs: pass struct path to notify_change() Cai Xinchen
  2026-11-17 15:05 ` [PATCH -next -v4 02/17] LSM: pass struct path to the inode_setsecctx hook Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 14:59   ` sashiko-bot
  2026-11-17 15:05 ` [PATCH -next -v4 04/17] fs: pass struct path to POSIX ACL helpers Cai Xinchen
                   ` (13 subsequent siblings)
  16 siblings, 1 reply; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

vfs_setxattr(), vfs_getxattr(), vfs_listxattr() and vfs_removexattr(),
together with the __vfs_*_locked() variants, take a struct dentry even
though their callers either hold a struct path (or a struct file).  Pass
a struct path instead; the idmap stays a separate argument so that the
VFS and the filesystem see the same idmap, including for filesystems that
forward a change with &nop_mnt_idmap.

__vfs_setxattr_noperm(), __vfs_getxattr(), __vfs_setxattr(),
__vfs_removexattr() and vfs_getxattr_alloc() keep taking a dentry, as
they are only called from LSM internals and other dentry-only contexts.

The ksmbd helpers now take a proper struct path from their callers
instead of wrapping the dentry in a synthetic path built from the share
root's mount.  For the '..' entry of a mount root, follow the mount stack
up with follow_up(), and report the share root if the mount has been
detached, so that the path stays valid.

evm_calc_hmac_or_hash() calls vfs_getxattr() only to print a debug
message when the kernel-side and user-space-side xattr sizes differ.
That call cannot be migrated, so drop the check and the now unused
user_space_size variable.

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 drivers/block/zloop.c               |  4 +-
 fs/cachefiles/xattr.c               | 35 +++++++------
 fs/ecryptfs/inode.c                 |  9 ++--
 fs/nfsd/nfs4ctl.h                   |  5 +-
 fs/nfsd/vfs.c                       | 65 +++++++++++++----------
 fs/overlayfs/copy_up.c              |  4 +-
 fs/overlayfs/overlayfs.h            | 17 ++++--
 fs/overlayfs/xattrs.c               | 12 +++--
 fs/smb/server/smb2pdu.c             | 51 +++++++++---------
 fs/smb/server/smb_common.c          | 59 ++++++++++++++++++---
 fs/smb/server/smbacl.c              | 10 ++--
 fs/smb/server/vfs.c                 | 80 +++++++++++++----------------
 fs/smb/server/vfs.h                 | 16 +++---
 fs/xattr.c                          | 78 +++++++++++++++-------------
 include/linux/xattr.h               | 26 ++++++----
 security/integrity/evm/evm_crypto.c |  8 +--
 security/selinux/hooks.c            |  4 +-
 security/smack/smack_lsm.c          |  4 +-
 18 files changed, 277 insertions(+), 210 deletions(-)

diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
index 96666742523b..cfde2e1f03cd 100644
--- a/drivers/block/zloop.c
+++ b/drivers/block/zloop.c
@@ -718,7 +718,7 @@ static int zloop_record_safe_wps(struct zloop_device *zlo)
 
 		if (!zloop_zone_is_active(zone))
 			continue;
-		ret = vfs_setxattr(file_mnt_idmap(file), file_dentry(file),
+		ret = vfs_setxattr(file_mnt_idmap(file), &file->f_path,
 				"user.zloop.wp", &zone->wp, sizeof(zone->wp), 0);
 		if (ret) {
 			pr_err("%pg: failed to record write pointer (%d)\n",
@@ -1419,7 +1419,7 @@ static void zloop_forget_cache(struct zloop_device *zlo)
 		if (!zloop_zone_is_active(zone))
 			continue;
 
-		ret = vfs_getxattr(file_mnt_idmap(file), file_dentry(file),
+		ret = vfs_getxattr(file_mnt_idmap(file), &file->f_path,
 				"user.zloop.wp", &old_wp, sizeof(old_wp));
 		if (ret == -ENODATA) {
 			old_wp = 0;
diff --git a/fs/cachefiles/xattr.c b/fs/cachefiles/xattr.c
index 8ebb713482e3..afdce5ce3b73 100644
--- a/fs/cachefiles/xattr.c
+++ b/fs/cachefiles/xattr.c
@@ -40,7 +40,6 @@ struct cachefiles_vol_xattr {
 int cachefiles_preset_object_xattr(struct cachefiles_object *object, struct file *file)
 {
 	struct cachefiles_xattr *buf;
-	struct dentry *dentry = file->f_path.dentry;
 	unsigned int len = object->cookie->aux_len;
 	int ret;
 
@@ -55,7 +54,7 @@ int cachefiles_preset_object_xattr(struct cachefiles_object *object, struct file
 	if (ret == 0) {
 		ret = mnt_want_write_file(file);
 		if (ret == 0) {
-			ret = vfs_setxattr(&nop_mnt_idmap, dentry,
+			ret = vfs_setxattr(&nop_mnt_idmap, &file->f_path,
 					   cachefiles_xattr_cache, buf,
 					   sizeof(struct cachefiles_xattr) + len, 0);
 			mnt_drop_write_file(file);
@@ -91,7 +90,6 @@ int cachefiles_preset_object_xattr(struct cachefiles_object *object, struct file
 int cachefiles_set_object_xattr(struct cachefiles_object *object)
 {
 	struct cachefiles_xattr *buf;
-	struct dentry *dentry;
 	struct file *file = object->file;
 	unsigned int len = object->cookie->aux_len;
 	uoff_t object_size = object->cookie->object_size;
@@ -99,7 +97,6 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object)
 
 	if (!file)
 		return -ESTALE;
-	dentry = file->f_path.dentry;
 
 	_enter("%x,#%d", object->debug_id, len);
 
@@ -121,7 +118,7 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object)
 	if (ret == 0) {
 		ret = mnt_want_write_file(file);
 		if (ret == 0) {
-			ret = vfs_setxattr(&nop_mnt_idmap, dentry,
+			ret = vfs_setxattr(&nop_mnt_idmap, &file->f_path,
 					   cachefiles_xattr_cache, buf,
 					   sizeof(struct cachefiles_xattr) + len, 0);
 			mnt_drop_write_file(file);
@@ -160,7 +157,6 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object)
 int cachefiles_check_auxdata(struct cachefiles_object *object, struct file *file)
 {
 	struct cachefiles_xattr *buf;
-	struct dentry *dentry = file->f_path.dentry;
 	struct inode *inode = file_inode(file);
 	unsigned int len = object->cookie->aux_len, tlen;
 	const void *p = fscache_get_aux(object->cookie);
@@ -177,7 +173,8 @@ int cachefiles_check_auxdata(struct cachefiles_object *object, struct file *file
 
 	xlen = cachefiles_inject_read_error();
 	if (xlen == 0)
-		xlen = vfs_getxattr(&nop_mnt_idmap, dentry, cachefiles_xattr_cache, buf, tlen);
+		xlen = vfs_getxattr(&nop_mnt_idmap, &file->f_path,
+				    cachefiles_xattr_cache, buf, tlen);
 	if (xlen != tlen) {
 		if (xlen < 0) {
 			ret = xlen;
@@ -226,6 +223,7 @@ int cachefiles_remove_object_xattr(struct cachefiles_cache *cache,
 				   struct cachefiles_object *object,
 				   struct dentry *dentry)
 {
+	struct path path = { .mnt = cache->mnt, .dentry = dentry };
 	int ret;
 
 	trace_cachefiles_coherency(object, d_inode(dentry)->i_ino, 0, NULL, 0,
@@ -235,7 +233,7 @@ int cachefiles_remove_object_xattr(struct cachefiles_cache *cache,
 	if (ret == 0) {
 		ret = mnt_want_write(cache->mnt);
 		if (ret == 0) {
-			ret = vfs_removexattr(&nop_mnt_idmap, dentry,
+			ret = vfs_removexattr(&nop_mnt_idmap, &path,
 					      cachefiles_xattr_cache);
 			mnt_drop_write(cache->mnt);
 		}
@@ -282,7 +280,8 @@ bool cachefiles_set_volume_xattr(struct cachefiles_volume *volume)
 	struct cachefiles_vol_xattr *buf;
 	unsigned int len = volume->vcookie->coherency_len;
 	const void *p = volume->vcookie->coherency;
-	struct dentry *dentry = volume->dentry;
+	struct path path = { .mnt = volume->cache->mnt,
+			     .dentry = volume->dentry };
 	int ret;
 
 	_enter("%x,#%d", volume->vcookie->debug_id, len);
@@ -298,22 +297,22 @@ bool cachefiles_set_volume_xattr(struct cachefiles_volume *volume)
 	if (ret == 0) {
 		ret = mnt_want_write(volume->cache->mnt);
 		if (ret == 0) {
-			ret = vfs_setxattr(&nop_mnt_idmap, dentry,
+			ret = vfs_setxattr(&nop_mnt_idmap, &path,
 					   cachefiles_xattr_cache,
 					   buf, len, 0);
 			mnt_drop_write(volume->cache->mnt);
 		}
 	}
 	if (ret < 0) {
-		trace_cachefiles_vfs_error(NULL, d_inode(dentry), ret,
+		trace_cachefiles_vfs_error(NULL, d_inode(path.dentry), ret,
 					   cachefiles_trace_setxattr_error);
-		trace_cachefiles_vol_coherency(volume, d_inode(dentry)->i_ino,
+		trace_cachefiles_vol_coherency(volume, d_inode(path.dentry)->i_ino,
 					       cachefiles_coherency_vol_set_fail);
 		if (ret != -ENOMEM)
 			cachefiles_io_error(
 				volume->cache, "Failed to set xattr with error %d", ret);
 	} else {
-		trace_cachefiles_vol_coherency(volume, d_inode(dentry)->i_ino,
+		trace_cachefiles_vol_coherency(volume, d_inode(path.dentry)->i_ino,
 					       cachefiles_coherency_vol_set_ok);
 	}
 
@@ -328,9 +327,10 @@ bool cachefiles_set_volume_xattr(struct cachefiles_volume *volume)
 int cachefiles_check_volume_xattr(struct cachefiles_volume *volume)
 {
 	struct cachefiles_vol_xattr *buf;
-	struct dentry *dentry = volume->dentry;
 	unsigned int len = volume->vcookie->coherency_len;
 	const void *p = volume->vcookie->coherency;
+	struct path path = { .mnt = volume->cache->mnt,
+			     .dentry = volume->dentry };
 	enum cachefiles_coherency_trace why;
 	ssize_t xlen;
 	int ret = -ESTALE;
@@ -344,11 +344,12 @@ int cachefiles_check_volume_xattr(struct cachefiles_volume *volume)
 
 	xlen = cachefiles_inject_read_error();
 	if (xlen == 0)
-		xlen = vfs_getxattr(&nop_mnt_idmap, dentry, cachefiles_xattr_cache, buf, len);
+		xlen = vfs_getxattr(&nop_mnt_idmap, &path,
+				    cachefiles_xattr_cache, buf, len);
 	if (xlen != len) {
 		if (xlen < 0) {
 			ret = xlen;
-			trace_cachefiles_vfs_error(NULL, d_inode(dentry), xlen,
+			trace_cachefiles_vfs_error(NULL, d_inode(path.dentry), xlen,
 						   cachefiles_trace_getxattr_error);
 			if (xlen == -EIO)
 				cachefiles_io_error(
@@ -365,7 +366,7 @@ int cachefiles_check_volume_xattr(struct cachefiles_volume *volume)
 		ret = 0;
 	}
 
-	trace_cachefiles_vol_coherency(volume, d_inode(dentry)->i_ino, why);
+	trace_cachefiles_vol_coherency(volume, d_inode(path.dentry)->i_ino, why);
 	kfree(buf);
 	_leave(" = %d", ret);
 	return ret;
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index 26967e4e4660..c1be27e1f7eb 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -992,17 +992,18 @@ ecryptfs_setxattr(struct dentry *dentry, struct inode *inode,
 		  size_t size, int flags)
 {
 	int rc;
-	struct dentry *lower_dentry;
+	struct path lower_path;
 	struct inode *lower_inode;
 
-	lower_dentry = ecryptfs_dentry_to_lower(dentry);
-	lower_inode = d_inode(lower_dentry);
+	lower_path = ecryptfs_lower_path(dentry);
+	lower_inode = d_inode(lower_path.dentry);
 	if (!(lower_inode->i_opflags & IOP_XATTR)) {
 		rc = -EOPNOTSUPP;
 		goto out;
 	}
 	inode_lock(lower_inode);
-	rc = __vfs_setxattr_locked(&nop_mnt_idmap, lower_dentry, name, value, size, flags, NULL);
+	rc = __vfs_setxattr_locked(&nop_mnt_idmap, &lower_path, name, value,
+				   size, flags, NULL);
 	inode_unlock(lower_inode);
 	if (!rc && inode)
 		fsstack_copy_attr_all(inode, lower_inode);
diff --git a/fs/nfsd/nfs4ctl.h b/fs/nfsd/nfs4ctl.h
index e0d1246ca337..fad496c07bae 100644
--- a/fs/nfsd/nfs4ctl.h
+++ b/fs/nfsd/nfs4ctl.h
@@ -20,6 +20,7 @@
 struct net;
 struct inode;
 struct dentry;
+struct path;
 struct svc_rqst;
 struct nfsd_net;
 
@@ -36,7 +37,7 @@ int nfsd4_create_laundry_wq(void);
 void nfsd4_destroy_laundry_wq(void);
 bool nfsd_wait_for_delegreturn(struct svc_rqst *rqstp, struct inode *inode);
 
-extern int nfsd4_is_junction(struct dentry *dentry);
+extern int nfsd4_is_junction(const struct path *path);
 extern int register_cld_notifier(void);
 extern void unregister_cld_notifier(void);
 #ifdef CONFIG_NFSD_V4_2_INTER_SSC
@@ -64,7 +65,7 @@ static inline bool nfsd_wait_for_delegreturn(struct svc_rqst *rqstp,
 	return false;
 }
 
-static inline int nfsd4_is_junction(struct dentry *dentry)
+static inline int nfsd4_is_junction(const struct path *path)
 {
 	return 0;
 }
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 1c686b82e70a..aef4097e9ef3 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -233,11 +233,13 @@ static int nfsd_lookup_parent(struct svc_rqst *rqstp, struct dentry *dparent, st
  */
 int nfsd_mountpoint(struct dentry *dentry, struct svc_export *exp)
 {
+	struct path path = { .mnt = exp->ex_path.mnt, .dentry = dentry };
+
 	if (!d_inode(dentry))
 		return 0;
 	if (exp->ex_flags & NFSEXP_V4ROOT)
 		return 1;
-	if (nfsd4_is_junction(dentry))
+	if (nfsd4_is_junction(&path))
 		return 1;
 	if (d_managed(dentry))
 		/*
@@ -685,14 +687,14 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
 /**
  * nfsd4_is_junction - Test if an object could be an NFS junction
  *
- * @dentry: object to test
+ * @path: object to test
  *
- * Returns 1 if "dentry" appears to contain NFS junction information.
+ * Returns 1 if "path" appears to contain NFS junction information.
  * Otherwise 0 is returned.
  */
-int nfsd4_is_junction(struct dentry *dentry)
+int nfsd4_is_junction(const struct path *path)
 {
-	struct inode *inode = d_inode(dentry);
+	struct inode *inode = d_inode(path->dentry);
 
 	if (inode == NULL)
 		return 0;
@@ -700,7 +702,7 @@ int nfsd4_is_junction(struct dentry *dentry)
 		return 0;
 	if (!(inode->i_mode & S_ISVTX))
 		return 0;
-	if (vfs_getxattr(&nop_mnt_idmap, dentry, NFSD_JUNCTION_XATTR_NAME,
+	if (vfs_getxattr(&nop_mnt_idmap, path, NFSD_JUNCTION_XATTR_NAME,
 			 NULL, 0) <= 0)
 		return 0;
 	return 1;
@@ -2676,23 +2678,24 @@ __be32
 nfsd_getxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name,
 	      void **bufp, int *lenp)
 {
+	struct path path;
+	struct inode *inode;
+	char *buf;
 	ssize_t len;
 	__be32 err;
-	char *buf;
-	struct inode *inode;
-	struct dentry *dentry;
 
 	err = fh_verify(rqstp, fhp, 0, NFSD_MAY_READ);
 	if (err)
 		return err;
 
 	err = nfs_ok;
-	dentry = fhp->fh_dentry;
-	inode = d_inode(dentry);
+	path.mnt = fhp->fh_export->ex_path.mnt;
+	path.dentry = fhp->fh_dentry;
+	inode = d_inode(path.dentry);
 
 	inode_lock_shared(inode);
 
-	len = vfs_getxattr(&nop_mnt_idmap, dentry, name, NULL, 0);
+	len = vfs_getxattr(&nop_mnt_idmap, &path, name, NULL, 0);
 
 	/*
 	 * Zero-length attribute, just return.
@@ -2719,7 +2722,7 @@ nfsd_getxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name,
 		goto out;
 	}
 
-	len = vfs_getxattr(&nop_mnt_idmap, dentry, name, buf, len);
+	len = vfs_getxattr(&nop_mnt_idmap, &path, name, buf, len);
 	if (len <= 0) {
 		kvfree(buf);
 		buf = NULL;
@@ -2749,23 +2752,24 @@ __be32
 nfsd_listxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char **bufp,
 	       int *lenp)
 {
+	struct path path;
+	struct inode *inode;
+	char *buf;
 	ssize_t len;
 	__be32 err;
-	char *buf;
-	struct inode *inode;
-	struct dentry *dentry;
 
 	err = fh_verify(rqstp, fhp, 0, NFSD_MAY_READ);
 	if (err)
 		return err;
 
-	dentry = fhp->fh_dentry;
-	inode = d_inode(dentry);
+	path.mnt = fhp->fh_export->ex_path.mnt;
+	path.dentry = fhp->fh_dentry;
+	inode = d_inode(path.dentry);
 	*lenp = 0;
 
 	inode_lock_shared(inode);
 
-	len = vfs_listxattr(dentry, NULL, 0);
+	len = vfs_listxattr(&path, NULL, 0);
 	if (len <= 0) {
 		err = nfsd_xattr_errno(len);
 		goto out;
@@ -2782,7 +2786,7 @@ nfsd_listxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char **bufp,
 		goto out;
 	}
 
-	len = vfs_listxattr(dentry, buf, len);
+	len = vfs_listxattr(&path, buf, len);
 	if (len <= 0) {
 		kvfree(buf);
 		err = nfsd_xattr_errno(len);
@@ -2813,6 +2817,7 @@ nfsd_listxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char **bufp,
 __be32
 nfsd_removexattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name)
 {
+	struct path path;
 	__be32 err;
 	int ret;
 
@@ -2824,16 +2829,17 @@ nfsd_removexattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name)
 	if (ret)
 		return nfserrno(ret);
 
-	inode_lock(fhp->fh_dentry->d_inode);
+	path.mnt = fhp->fh_export->ex_path.mnt;
+	path.dentry = fhp->fh_dentry;
+	inode_lock(d_inode(path.dentry));
 	err = fh_fill_pre_attrs(fhp);
 	if (err != nfs_ok)
 		goto out_unlock;
-	ret = __vfs_removexattr_locked(&nop_mnt_idmap, fhp->fh_dentry,
-				       name, NULL);
+	ret = __vfs_removexattr_locked(&nop_mnt_idmap, &path, name, NULL);
 	err = nfsd_xattr_errno(ret);
 	fh_fill_post_attrs(fhp);
 out_unlock:
-	inode_unlock(fhp->fh_dentry->d_inode);
+	inode_unlock(d_inode(path.dentry));
 	fh_drop_write(fhp);
 
 	return err;
@@ -2843,6 +2849,7 @@ __be32
 nfsd_setxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name,
 	      void *buf, u32 len, u32 flags)
 {
+	struct path path;
 	__be32 err;
 	int ret;
 
@@ -2853,16 +2860,18 @@ nfsd_setxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name,
 	ret = fh_want_write(fhp);
 	if (ret)
 		return nfserrno(ret);
-	inode_lock(fhp->fh_dentry->d_inode);
+	path.mnt = fhp->fh_export->ex_path.mnt;
+	path.dentry = fhp->fh_dentry;
+	inode_lock(d_inode(path.dentry));
 	err = fh_fill_pre_attrs(fhp);
 	if (err != nfs_ok)
 		goto out_unlock;
-	ret = __vfs_setxattr_locked(&nop_mnt_idmap, fhp->fh_dentry,
-				    name, buf, len, flags, NULL);
+	ret = __vfs_setxattr_locked(&nop_mnt_idmap, &path, name, buf, len,
+				    flags, NULL);
 	fh_fill_post_attrs(fhp);
 	err = nfsd_xattr_errno(ret);
 out_unlock:
-	inode_unlock(fhp->fh_dentry->d_inode);
+	inode_unlock(d_inode(path.dentry));
 	fh_drop_write(fhp);
 	return err;
 }
diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index c147ad155b79..ac7718aa1388 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -95,7 +95,7 @@ int ovl_copy_xattr(struct super_block *sb, const struct path *oldpath, struct de
 	if (!old->d_inode->i_op->listxattr || !new->d_inode->i_op->listxattr)
 		return 0;
 
-	list_size = vfs_listxattr(old, NULL, 0);
+	list_size = vfs_listxattr(oldpath, NULL, 0);
 	if (list_size <= 0) {
 		if (list_size == -EOPNOTSUPP)
 			return 0;
@@ -106,7 +106,7 @@ int ovl_copy_xattr(struct super_block *sb, const struct path *oldpath, struct de
 	if (!buf)
 		return -ENOMEM;
 
-	list_size = vfs_listxattr(old, buf, list_size);
+	list_size = vfs_listxattr(oldpath, buf, list_size);
 	if (list_size <= 0) {
 		error = list_size;
 		goto out;
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index c6f67672460d..2c7beb041ef0 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -301,8 +301,7 @@ static inline ssize_t ovl_do_getxattr(const struct path *path, const char *name,
 
 	WARN_ON(path->dentry->d_sb != path->mnt->mnt_sb);
 
-	err = vfs_getxattr(mnt_idmap(path->mnt), path->dentry,
-			       name, value, size);
+	err = vfs_getxattr(mnt_idmap(path->mnt), path, name, value, size);
 	len = (value && err > 0) ? err : 0;
 
 	pr_debug("getxattr(%pd2, \"%s\", \"%*pE\", %zu, 0) = %i\n",
@@ -335,8 +334,13 @@ static inline int ovl_do_setxattr(struct ovl_fs *ofs, struct dentry *dentry,
 				  const char *name, const void *value,
 				  size_t size, int flags)
 {
+	struct path path = {
+		.mnt = ovl_upper_mnt(ofs),
+		.dentry = dentry,
+	};
+
 	/* Use vfs_setxattr(), not __vfs_setxattr(): it idmaps the security.capability rootid. */
-	int err = vfs_setxattr(ovl_upper_mnt_idmap(ofs), dentry, name,
+	int err = vfs_setxattr(ovl_upper_mnt_idmap(ofs), &path, name,
 			       value, size, flags);
 
 	pr_debug("setxattr(%pd2, \"%s\", \"%*pE\", %zu, %d) = %i\n",
@@ -354,7 +358,12 @@ static inline int ovl_setxattr(struct ovl_fs *ofs, struct dentry *dentry,
 static inline int ovl_do_removexattr(struct ovl_fs *ofs, struct dentry *dentry,
 				     const char *name)
 {
-	int err = vfs_removexattr(ovl_upper_mnt_idmap(ofs), dentry, name);
+	struct path path = {
+		.mnt = ovl_upper_mnt(ofs),
+		.dentry = dentry,
+	};
+
+	int err = vfs_removexattr(ovl_upper_mnt_idmap(ofs), &path, name);
 	pr_debug("removexattr(%pd2, \"%s\") = %i\n", dentry, name, err);
 	return err;
 }
diff --git a/fs/overlayfs/xattrs.c b/fs/overlayfs/xattrs.c
index acc54f6138ef..2a97a9ec642a 100644
--- a/fs/overlayfs/xattrs.c
+++ b/fs/overlayfs/xattrs.c
@@ -45,7 +45,8 @@ static int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char
 	if (!value && !upperdentry) {
 		ovl_path_lower(dentry, &realpath);
 		with_ovl_creds(dentry->d_sb)
-			err = vfs_getxattr(mnt_idmap(realpath.mnt), realdentry, name, NULL, 0);
+			err = vfs_getxattr(mnt_idmap(realpath.mnt), &realpath,
+					   name, NULL, 0);
 		if (err < 0)
 			goto out;
 	}
@@ -86,7 +87,8 @@ static int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char
 	ovl_i_path_real(inode, &realpath);
 	/* Use vfs_getxattr(), not __vfs_getxattr(): it idmaps the security.capability rootid. */
 	with_ovl_creds(dentry->d_sb)
-		return vfs_getxattr(mnt_idmap(realpath.mnt), realpath.dentry, name, value, size);
+		return vfs_getxattr(mnt_idmap(realpath.mnt), &realpath,
+				    name, value, size);
 }
 
 static bool ovl_can_list(struct super_block *sb, const char *s)
@@ -105,15 +107,17 @@ static bool ovl_can_list(struct super_block *sb, const char *s)
 
 ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size)
 {
-	struct dentry *realdentry = ovl_dentry_real(dentry);
+	struct path realpath;
 	struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
 	ssize_t res;
 	size_t len;
 	char *s;
 	size_t prefix_len, name_len;
 
+	ovl_path_real(dentry, &realpath);
+
 	with_ovl_creds(dentry->d_sb)
-		res = vfs_listxattr(realdentry, list, size);
+		res = vfs_listxattr(&realpath, list, size);
 	if (res <= 0 || size == 0)
 		return res;
 
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 4832decf6478..a36ad354b37b 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -3615,16 +3615,14 @@ static int smb2_set_ea(struct smb2_ea_info *eabuf, unsigned int buf_len,
 		value = (char *)&eabuf->name + eabuf->EaNameLength + 1;
 
 		if (!eabuf->EaValueLength) {
-			rc = ksmbd_vfs_casexattr_len(idmap,
-						     path->dentry,
+			rc = ksmbd_vfs_casexattr_len(idmap, path,
 						     attr_name,
 						     XATTR_USER_PREFIX_LEN +
 						     eabuf->EaNameLength, NULL);
 
 			/* delete the EA only when it exits */
 			if (rc > 0) {
-				rc = ksmbd_vfs_remove_xattr(idmap,
-							    path,
+				rc = ksmbd_vfs_remove_xattr(idmap, path,
 							    attr_name,
 							    get_write);
 
@@ -3693,8 +3691,7 @@ static noinline int smb2_set_stream_name_xattr(const struct path *path,
 	fp->stream.size = xattr_stream_size;
 
 	/* Keep the existing xattr's case for subsequent writes and removal. */
-	rc = ksmbd_vfs_casexattr_len(idmap,
-				     path->dentry,
+	rc = ksmbd_vfs_casexattr_len(idmap, path,
 				     xattr_stream_name,
 				     xattr_stream_size, xattr_stream_name);
 	if (rc >= 0)
@@ -3754,7 +3751,7 @@ static noinline int smb2_set_stream_name_xattr(const struct path *path,
 static loff_t ksmbd_stream_eof(struct ksmbd_file *fp)
 {
 	ssize_t slen = ksmbd_vfs_casexattr_len(file_mnt_idmap(fp->filp),
-					       fp->filp->f_path.dentry,
+					       &fp->filp->f_path,
 					       fp->stream.name,
 					       fp->stream.size, NULL);
 	return slen < 0 ? 0 : (loff_t)slen;
@@ -3767,7 +3764,7 @@ static int smb2_remove_smb_xattrs(const struct path *path)
 	ssize_t xattr_list_len;
 	int err = 0;
 
-	xattr_list_len = ksmbd_vfs_listxattr(path->dentry, &xattr_list);
+	xattr_list_len = ksmbd_vfs_listxattr(path, &xattr_list);
 	if (xattr_list_len < 0) {
 		goto out;
 	} else if (!xattr_list_len) {
@@ -3782,8 +3779,7 @@ static int smb2_remove_smb_xattrs(const struct path *path)
 		if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) &&
 		    !strncmp(&name[XATTR_USER_PREFIX_LEN], STREAM_PREFIX,
 			     STREAM_PREFIX_LEN)) {
-			err = ksmbd_vfs_remove_xattr(idmap, path,
-						     name, true);
+			err = ksmbd_vfs_remove_xattr(idmap, path, name, true);
 			if (err)
 				ksmbd_debug(SMB, "remove xattr failed : %s\n",
 					    name);
@@ -3838,6 +3834,7 @@ static bool smb2_parent_compressed(struct ksmbd_tree_connect *tcon,
 				   const struct path *path)
 {
 	struct dentry *parent = dget_parent(path->dentry);
+	struct path parent_path = { .mnt = path->mnt, .dentry = parent };
 	struct file_kattr fa = { .flags_valid = true };
 	struct xattr_dos_attrib da;
 	bool compressed = false;
@@ -3849,7 +3846,8 @@ static bool smb2_parent_compressed(struct ksmbd_tree_connect *tcon,
 		goto out;
 	}
 
-	rc = ksmbd_vfs_get_dos_attrib_xattr(mnt_idmap(path->mnt), parent, &da);
+	rc = ksmbd_vfs_get_dos_attrib_xattr(mnt_idmap(path->mnt),
+					    &parent_path, &da);
 	if (rc > 0 && da.attr & FILE_ATTRIBUTE_COMPRESSED)
 		compressed = true;
 
@@ -3870,7 +3868,7 @@ static void smb2_update_xattrs(struct ksmbd_tree_connect *tcon,
 
 	/* get FileAttributes from XATTR_NAME_DOS_ATTRIBUTE */
 	rc = ksmbd_vfs_get_dos_attrib_xattr(mnt_idmap(path->mnt),
-					    path->dentry, &da);
+					    path, &da);
 	if (rc > 0) {
 		if (store_dos_attrs) {
 			fp->f_ci->m_fattr = cpu_to_le32(da.attr);
@@ -4903,7 +4901,7 @@ int smb2_open(struct ksmbd_work *work)
 			if (test_share_config_flag(tcon->share_conf,
 						   KSMBD_SHARE_FLAG_STORE_DOS_ATTRS) &&
 			    ksmbd_vfs_get_dos_attrib_xattr(mnt_idmap(path.mnt),
-							 path.dentry, &da) > 0 &&
+							   &path, &da) > 0 &&
 			    da.attr & FILE_ATTRIBUTE_READONLY) {
 				rsp->hdr.Status = STATUS_CANNOT_DELETE;
 				rc = -EACCES;
@@ -6486,13 +6484,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,
@@ -6508,7 +6507,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);
@@ -7152,7 +7151,7 @@ static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp,
 	if (buf_free_len < 0)
 		return -EINVAL;
 
-	rc = ksmbd_vfs_listxattr(path->dentry, &xattr_list);
+	rc = ksmbd_vfs_listxattr(path, &xattr_list);
 	if (rc < 0) {
 		rsp->hdr.Status = STATUS_INVALID_HANDLE;
 		goto out;
@@ -7198,8 +7197,7 @@ static int smb2_get_ea(struct ksmbd_work *work, struct ksmbd_file *fp,
 		buf_free_len -= (offsetof(struct smb2_ea_info, name) +
 				name_len + 1);
 		/* bailout if xattr can't fit in buf_free_len */
-		value_len = ksmbd_vfs_getxattr(idmap, path->dentry,
-					       name, &buf);
+		value_len = ksmbd_vfs_getxattr(idmap, path, name, &buf);
 		if (value_len <= 0) {
 			rc = -ENOENT;
 			rsp->hdr.Status = STATUS_INVALID_HANDLE;
@@ -7489,7 +7487,7 @@ static char *smb2_get_normalized_stream_name(struct ksmbd_file *fp)
 	if (!ksmbd_stream_fd(fp))
 		return NULL;
 
-	xattr_list_len = ksmbd_vfs_listxattr(fp->filp->f_path.dentry,
+	xattr_list_len = ksmbd_vfs_listxattr(&fp->filp->f_path,
 					     &xattr_list);
 	if (xattr_list_len <= 0)
 		goto out;
@@ -7657,7 +7655,7 @@ static int get_file_stream_info(struct ksmbd_work *work,
 	if (ret)
 		return ret;
 
-	xattr_list_len = ksmbd_vfs_listxattr(path->dentry, &xattr_list);
+	xattr_list_len = ksmbd_vfs_listxattr(path, &xattr_list);
 	if (xattr_list_len < 0) {
 		goto default_stream;
 	} else if (!xattr_list_len) {
@@ -7683,7 +7681,7 @@ static int get_file_stream_info(struct ksmbd_work *work,
 			goto out;
 		}
 		slen = ksmbd_vfs_xattr_len(file_mnt_idmap(fp->filp),
-					   path->dentry, stream_name);
+					   path, stream_name);
 		ssize = slen < 0 ? 0 : (loff_t)slen;
 		ret = smb2_add_stream_info(&buf, stream_buf, ssize, ssize);
 		kfree(stream_buf);
@@ -8493,7 +8491,7 @@ static int smb2_get_info_sec(struct ksmbd_work *work,
 	if (test_share_config_flag(work->tcon->share_conf,
 				   KSMBD_SHARE_FLAG_ACL_XATTR)) {
 		ppntsd_size = ksmbd_vfs_get_sd_xattr(work->conn, idmap,
-						     fp->filp->f_path.dentry,
+						     &fp->filp->f_path,
 						     &ppntsd);
 		if (ppntsd_size < 0 && !smb_no_stored_sd(ppntsd_size)) {
 			rc = ppntsd_size == -ENOMEM ? -ENOMEM : -EIO;
@@ -8860,7 +8858,7 @@ static int smb2_rename(struct ksmbd_work *work,
 			}
 
 			stream_buf_len = ksmbd_vfs_getcasexattr(file_mnt_idmap(fp->filp),
-								fp->filp->f_path.dentry,
+								&fp->filp->f_path,
 								fp->stream.name,
 								fp->stream.size,
 								&stream_buf);
@@ -9043,7 +9041,8 @@ static int set_file_basic_info(struct ksmbd_file *fp,
 	    (crtime > 0 || file_info->Attributes)) {
 		struct xattr_dos_attrib da = {0};
 
-		rc = ksmbd_vfs_get_dos_attrib_xattr(idmap, fp->filp->f_path.dentry, &da);
+		rc = ksmbd_vfs_get_dos_attrib_xattr(idmap, &fp->filp->f_path,
+						   &da);
 		if (rc <= 0) {
 			da.version = 4;
 			da.flags = 0;
@@ -11894,7 +11893,7 @@ static inline int fsctl_set_sparse(struct ksmbd_work *work, u64 id,
 		struct xattr_dos_attrib da = {0};
 
 		ret = ksmbd_vfs_get_dos_attrib_xattr(idmap,
-						     fp->filp->f_path.dentry, &da);
+						     &fp->filp->f_path, &da);
 		if (ret <= 0) {
 			da.version = 4;
 			da.flags = 0;
diff --git a/fs/smb/server/smb_common.c b/fs/smb/server/smb_common.c
index e7a987af64ba..a6da27a7d7cb 100644
--- a/fs/smb/server/smb_common.c
+++ b/fs/smb/server/smb_common.c
@@ -467,37 +467,82 @@ int ksmbd_populate_dot_dotdot_entries(struct ksmbd_work *work, int info_level,
 {
 	int i, rc = 0;
 	struct ksmbd_conn *conn = work->conn;
-	const struct mnt_idmap *idmap = file_mnt_idmap(dir->filp);
+	const struct path *const share_root = &work->tcon->share_conf->vfs_path;
 
 	for (i = 0; i < 2; i++) {
 		struct kstat kstat;
 		struct ksmbd_kstat ksmbd_kstat;
-		struct dentry *dentry;
+		struct path path = dir->filp->f_path;
+		const struct mnt_idmap *idmap;
+		struct dentry *parent;
 
 		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_get(&path);
 			} else {
 				d_info->name = "..";
 				d_info->name_len = 2;
-				dentry = dget_parent(dir->filp->f_path.dentry);
+				path_get(&path);
+				/*
+				 * A ".." entry must not walk above the
+				 * share root, so it designates the share
+				 * root itself in that case.
+				 */
+				if (!path_equal(&path, share_root)) {
+					/*
+					 * The parent of a mount root dentry
+					 * is not covered by the same mount,
+					 * so follow the mount stack up like
+					 * a ".." path walk would, to keep
+					 * the path valid.
+					 */
+					while (path.dentry == path.mnt->mnt_root &&
+					       follow_up(&path))
+						;
+					if (path.dentry == path.mnt->mnt_root) {
+						/*
+						 * The mount is detached, for
+						 * example after a lazy umount
+						 * which the open file pins
+						 * down, so the parent would
+						 * not be covered by path.mnt:
+						 * report the share root
+						 * instead, as for any other
+						 * ".." above the share root.
+						 */
+						path_put(&path);
+						path_get(share_root);
+						path = *share_root;
+					} else {
+						parent = dget_parent(path.dentry);
+						dput(path.dentry);
+						path.dentry = parent;
+					}
+				}
 			}
 
+			/*
+			 * The path may now live in an ancestor mount, so
+			 * derive the idmap from it instead of reusing the
+			 * one of the enumerated directory.
+			 */
+			idmap = mnt_idmap(path.mnt);
+
 			if (!match_pattern(d_info->name, d_info->name_len,
 					   search_pattern)) {
 				dir->dot_dotdot[i] = 1;
-				dput(dentry);
+				path_put(&path);
 				continue;
 			}
 
 			ksmbd_kstat.kstat = &kstat;
 			rc = ksmbd_vfs_fill_dentry_attrs(work,
 							 idmap,
-							 dentry,
+							 &path,
 							 &ksmbd_kstat);
-			dput(dentry);
+			path_put(&path);
 			if (rc)
 				break;
 
diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c
index c2863b9f92ba..9fcc7f412e45 100644
--- a/fs/smb/server/smbacl.c
+++ b/fs/smb/server/smbacl.c
@@ -1210,6 +1210,7 @@ int smb_inherit_dacl(struct ksmbd_conn *conn,
 	struct smb_ntsd *parent_pntsd = NULL;
 	struct smb_sid owner_sid, group_sid;
 	struct dentry *parent;
+	struct path parent_path;
 	const struct mnt_idmap *idmap = mnt_idmap(path->mnt);
 	int inherited_flags = 0, flags = 0, i, nt_size = 0, pdacl_size;
 	int rc = 0, pntsd_type, ppntsd_size, acl_len, aces_size;
@@ -1224,8 +1225,10 @@ int smb_inherit_dacl(struct ksmbd_conn *conn,
 		dput(parent);
 		return -ENOENT;
 	}
-	ppntsd_size = ksmbd_vfs_get_sd_xattr(conn, idmap,
-					    parent, &parent_pntsd);
+	parent_path.mnt = path->mnt;
+	parent_path.dentry = parent;
+	ppntsd_size = ksmbd_vfs_get_sd_xattr(conn, idmap, &parent_path,
+					    &parent_pntsd);
 	dput(parent);
 	if (ppntsd_size <= 0)
 		return -ENOENT;
@@ -1543,8 +1546,7 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path,
 	vfsuid_t vfsuid;
 
 	ksmbd_debug(SMB, "check permission using windows acl\n");
-	pntsd_size = ksmbd_vfs_get_sd_xattr(conn, idmap,
-					    path->dentry, &pntsd);
+	pntsd_size = ksmbd_vfs_get_sd_xattr(conn, idmap, path, &pntsd);
 	if (pntsd_size <= 0 || !pntsd) {
 		if (pntsd_size < 0 && !smb_no_stored_sd(pntsd_size))
 			rc = pntsd_size == -ENOMEM ? -ENOMEM : -EACCES;
diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
index 7c3edbe6cb77..445fadd66f21 100644
--- a/fs/smb/server/vfs.c
+++ b/fs/smb/server/vfs.c
@@ -224,13 +224,13 @@ int ksmbd_vfs_mkdir(struct ksmbd_work *work, const char *name, umode_t mode)
 }
 
 ssize_t ksmbd_vfs_getcasexattr(const struct mnt_idmap *idmap,
-			       struct dentry *dentry, char *attr_name,
+			       const struct path *path, char *attr_name,
 			       int attr_name_len, char **attr_value)
 {
 	char *name, *xattr_list = NULL;
 	ssize_t value_len = -ENOENT, xattr_list_len;
 
-	xattr_list_len = ksmbd_vfs_listxattr(dentry, &xattr_list);
+	xattr_list_len = ksmbd_vfs_listxattr(path, &xattr_list);
 	if (xattr_list_len <= 0)
 		goto out;
 
@@ -240,8 +240,7 @@ ssize_t ksmbd_vfs_getcasexattr(const struct mnt_idmap *idmap,
 		if (strncasecmp(attr_name, name, attr_name_len))
 			continue;
 
-		value_len = ksmbd_vfs_getxattr(idmap,
-					       dentry,
+		value_len = ksmbd_vfs_getxattr(idmap, path,
 					       name,
 					       attr_value);
 		if (value_len < 0)
@@ -266,7 +265,7 @@ static int ksmbd_vfs_stream_read(struct ksmbd_file *fp, char *buf, loff_t *pos,
 
 	saved_cred = override_creds(fp->filp->f_cred);
 	v_len = ksmbd_vfs_getcasexattr(file_mnt_idmap(fp->filp),
-				       fp->filp->f_path.dentry,
+				       &fp->filp->f_path,
 				       fp->stream.name,
 				       fp->stream.size,
 				       &stream_buf);
@@ -415,8 +414,7 @@ static int ksmbd_vfs_stream_write(struct ksmbd_file *fp, char *buf, loff_t *pos,
 	write_end = *pos + count;
 
 	saved_cred = override_creds(fp->filp->f_cred);
-	v_len = ksmbd_vfs_getcasexattr(idmap,
-				       fp->filp->f_path.dentry,
+	v_len = ksmbd_vfs_getcasexattr(idmap, &fp->filp->f_path,
 				       fp->stream.name,
 				       fp->stream.size,
 				       &stream_buf);
@@ -443,8 +441,7 @@ static int ksmbd_vfs_stream_write(struct ksmbd_file *fp, char *buf, loff_t *pos,
 
 	memcpy(&stream_buf[*pos], buf, count);
 
-	err = ksmbd_vfs_setxattr(idmap,
-				 &fp->filp->f_path,
+	err = ksmbd_vfs_setxattr(idmap, &fp->filp->f_path,
 				 fp->stream.name,
 				 (void *)stream_buf,
 				 size,
@@ -485,7 +482,7 @@ int ksmbd_vfs_stream_truncate(struct ksmbd_file *fp, loff_t newsize)
 		return -EFBIG;
 
 	saved_cred = override_creds(fp->filp->f_cred);
-	v_len = ksmbd_vfs_getcasexattr(idmap, fp->filp->f_path.dentry,
+	v_len = ksmbd_vfs_getcasexattr(idmap, &fp->filp->f_path,
 				       fp->stream.name, fp->stream.size,
 				       &stream_buf);
 	if (v_len < 0) {
@@ -878,17 +875,17 @@ int ksmbd_vfs_truncate(struct ksmbd_work *work,
 
 /**
  * ksmbd_vfs_listxattr() - vfs helper for smb list extended attributes
- * @dentry:	dentry of file for listing xattrs
+ * @path:	path of file for listing xattrs
  * @list:	destination buffer
  *
  * Return:	xattr list length on success, otherwise error
  */
-ssize_t ksmbd_vfs_listxattr(struct dentry *dentry, char **list)
+ssize_t ksmbd_vfs_listxattr(const struct path *path, char **list)
 {
 	ssize_t size;
 	char *vlist = NULL;
 
-	size = vfs_listxattr(dentry, NULL, 0);
+	size = vfs_listxattr(path, NULL, 0);
 	if (size <= 0)
 		return size;
 
@@ -897,7 +894,7 @@ ssize_t ksmbd_vfs_listxattr(struct dentry *dentry, char **list)
 		return -ENOMEM;
 
 	*list = vlist;
-	size = vfs_listxattr(dentry, vlist, size);
+	size = vfs_listxattr(path, vlist, size);
 	if (size < 0) {
 		ksmbd_debug(VFS, "listxattr failed\n");
 		kvfree(vlist);
@@ -908,29 +905,29 @@ ssize_t ksmbd_vfs_listxattr(struct dentry *dentry, char **list)
 }
 
 ssize_t ksmbd_vfs_xattr_len(const struct mnt_idmap *idmap,
-			    struct dentry *dentry, char *xattr_name)
+			    const struct path *path, char *xattr_name)
 {
-	return vfs_getxattr(idmap, dentry, xattr_name, NULL, 0);
+	return vfs_getxattr(idmap, path, xattr_name, NULL, 0);
 }
 
 /**
  * ksmbd_vfs_getxattr() - vfs helper for smb get extended attributes value
  * @idmap:	idmap
- * @dentry:	dentry of file for getting xattrs
+ * @path:	path of file for getting xattrs
  * @xattr_name:	name of xattr name to query
  * @xattr_buf:	destination buffer xattr value
  *
  * Return:	read xattr value length on success, otherwise error
  */
 ssize_t ksmbd_vfs_getxattr(const struct mnt_idmap *idmap,
-			   struct dentry *dentry,
+			   const struct path *path,
 			   char *xattr_name, char **xattr_buf)
 {
 	ssize_t xattr_len;
 	char *buf;
 
 	*xattr_buf = NULL;
-	xattr_len = ksmbd_vfs_xattr_len(idmap, dentry, xattr_name);
+	xattr_len = ksmbd_vfs_xattr_len(idmap, path, xattr_name);
 	if (xattr_len < 0)
 		return xattr_len;
 
@@ -938,7 +935,7 @@ ssize_t ksmbd_vfs_getxattr(const struct mnt_idmap *idmap,
 	if (!buf)
 		return -ENOMEM;
 
-	xattr_len = vfs_getxattr(idmap, dentry, xattr_name,
+	xattr_len = vfs_getxattr(idmap, path, xattr_name,
 				 (void *)buf, xattr_len);
 	if (xattr_len > 0)
 		*xattr_buf = buf;
@@ -972,8 +969,7 @@ int ksmbd_vfs_setxattr(const struct mnt_idmap *idmap,
 			return err;
 	}
 
-	err = vfs_setxattr(idmap,
-			   path->dentry,
+	err = vfs_setxattr(idmap, path,
 			   attr_name,
 			   attr_value,
 			   attr_size,
@@ -1264,7 +1260,7 @@ int ksmbd_vfs_remove_xattr(const struct mnt_idmap *idmap,
 			return err;
 	}
 
-	err = vfs_removexattr(idmap, path->dentry, attr_name);
+	err = vfs_removexattr(idmap, path, attr_name);
 
 	if (get_write == true)
 		mnt_drop_write(path->mnt);
@@ -1553,7 +1549,7 @@ int ksmbd_vfs_remove_acl_xattrs(const struct mnt_idmap *idmap,
 	ssize_t xattr_list_len;
 	int err = 0;
 
-	xattr_list_len = ksmbd_vfs_listxattr(path->dentry, &xattr_list);
+	xattr_list_len = ksmbd_vfs_listxattr(path, &xattr_list);
 	if (xattr_list_len < 0) {
 		goto out;
 	} else if (!xattr_list_len) {
@@ -1592,7 +1588,7 @@ int ksmbd_vfs_remove_sd_xattrs(const struct mnt_idmap *idmap, const struct path
 	ssize_t xattr_list_len;
 	int err = 0;
 
-	xattr_list_len = ksmbd_vfs_listxattr(path->dentry, &xattr_list);
+	xattr_list_len = ksmbd_vfs_listxattr(path, &xattr_list);
 	if (xattr_list_len < 0) {
 		goto out;
 	} else if (!xattr_list_len) {
@@ -1758,18 +1754,18 @@ EXPORT_SYMBOL_IF_KUNIT(ksmbd_vfs_set_sd_xattr);
 
 int ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn,
 			   const struct mnt_idmap *idmap,
-			   struct dentry *dentry,
+			   const struct path *path,
 			   struct smb_ntsd **pntsd)
 {
 	int rc;
 	struct ndr n;
-	struct inode *inode = d_inode(dentry);
+	struct inode *inode = d_inode(path->dentry);
 	struct ndr acl_ndr = {0};
 	struct xattr_ntacl acl = {0};
 	struct xattr_smb_acl *smb_acl = NULL, *def_smb_acl = NULL;
 	__u8 cmp_hash[XATTR_SD_HASH_SIZE] = {0};
 
-	rc = ksmbd_vfs_getxattr(idmap, dentry, XATTR_NAME_SD, &n.data);
+	rc = ksmbd_vfs_getxattr(idmap, path, XATTR_NAME_SD, &n.data);
 	if (rc <= 0)
 		return rc;
 
@@ -1861,13 +1857,13 @@ int ksmbd_vfs_set_dos_attrib_xattr(const struct mnt_idmap *idmap,
 }
 
 int ksmbd_vfs_get_dos_attrib_xattr(const struct mnt_idmap *idmap,
-				   struct dentry *dentry,
+				   const struct path *path,
 				   struct xattr_dos_attrib *da)
 {
 	struct ndr n;
 	int err;
 
-	err = ksmbd_vfs_getxattr(idmap, dentry, XATTR_NAME_DOS_ATTRIBUTE,
+	err = ksmbd_vfs_getxattr(idmap, path, XATTR_NAME_DOS_ATTRIBUTE,
 				 (char **)&n.data);
 	if (err > 0) {
 		n.length = err;
@@ -1917,18 +1913,13 @@ 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,
-				struct dentry *dentry,
+				const struct path *path,
 				struct ksmbd_kstat *ksmbd_kstat)
 {
-	struct ksmbd_share_config *share_conf = work->tcon->share_conf;
 	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)
@@ -1953,7 +1944,7 @@ int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work,
 				   KSMBD_SHARE_FLAG_STORE_DOS_ATTRS)) {
 		struct xattr_dos_attrib da;
 
-		rc = ksmbd_vfs_get_dos_attrib_xattr(idmap, dentry, &da);
+		rc = ksmbd_vfs_get_dos_attrib_xattr(idmap, path, &da);
 		if (rc > 0) {
 			ksmbd_kstat->file_attributes = cpu_to_le32(da.attr);
 			/*
@@ -1982,7 +1973,7 @@ int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work,
 		char *xattr_list = NULL, *name;
 		ssize_t xattr_list_len;
 
-		xattr_list_len = ksmbd_vfs_listxattr(dentry, &xattr_list);
+		xattr_list_len = ksmbd_vfs_listxattr(path, &xattr_list);
 		if (xattr_list_len > 0) {
 			for (name = xattr_list;
 			     name - xattr_list < xattr_list_len;
@@ -2001,13 +1992,13 @@ int ksmbd_vfs_fill_dentry_attrs(struct ksmbd_work *work,
 }
 
 ssize_t ksmbd_vfs_casexattr_len(const struct mnt_idmap *idmap,
-				struct dentry *dentry, char *attr_name,
+				const struct path *path, char *attr_name,
 				int attr_name_len, char *actual_name)
 {
 	char *name, *xattr_list = NULL;
 	ssize_t value_len = -ENOENT, xattr_list_len;
 
-	xattr_list_len = ksmbd_vfs_listxattr(dentry, &xattr_list);
+	xattr_list_len = ksmbd_vfs_listxattr(path, &xattr_list);
 	if (xattr_list_len < 0) {
 		value_len = xattr_list_len;
 		goto out;
@@ -2023,7 +2014,7 @@ ssize_t ksmbd_vfs_casexattr_len(const struct mnt_idmap *idmap,
 		if (actual_name && strlen(name) + 1 != attr_name_len)
 			continue;
 
-		value_len = ksmbd_vfs_xattr_len(idmap, dentry, name);
+		value_len = ksmbd_vfs_xattr_len(idmap, path, name);
 		/* The caller provides attr_name_len bytes for the actual name. */
 		if (value_len >= 0 && actual_name)
 			memcpy(actual_name, name, attr_name_len);
@@ -2180,7 +2171,7 @@ int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work,
 		saved_cred = override_creds(src_fp->filp->f_cred);
 		src_file_size = ksmbd_vfs_casexattr_len(
 				file_mnt_idmap(src_fp->filp),
-				src_fp->filp->f_path.dentry,
+				&src_fp->filp->f_path,
 				src_fp->stream.name, src_fp->stream.size, NULL);
 		revert_creds(saved_cred);
 		if (src_file_size < 0)
@@ -2504,7 +2495,8 @@ static int __ksmbd_vfs_set_compression(struct ksmbd_work *work,
 	if (fp->f_ci->m_fattr != old_fattr) {
 		struct xattr_dos_attrib da = {0};
 
-		rc = ksmbd_vfs_get_dos_attrib_xattr(idmap, dentry, &da);
+		rc = ksmbd_vfs_get_dos_attrib_xattr(idmap, &fp->filp->f_path,
+						    &da);
 		if (rc <= 0) {
 			da.version = 4;
 			da.flags = 0;
diff --git a/fs/smb/server/vfs.h b/fs/smb/server/vfs.h
index 21b0d29a3db0..c1ea94cf153f 100644
--- a/fs/smb/server/vfs.h
+++ b/fs/smb/server/vfs.h
@@ -104,18 +104,18 @@ int ksmbd_vfs_copy_file_ranges(struct ksmbd_work *work,
 			       unsigned int *chunk_count_written,
 			       unsigned int *chunk_size_written,
 			       loff_t  *total_size_written);
-ssize_t ksmbd_vfs_listxattr(struct dentry *dentry, char **list);
+ssize_t ksmbd_vfs_listxattr(const struct path *path, char **list);
 ssize_t ksmbd_vfs_getxattr(const struct mnt_idmap *idmap,
-			   struct dentry *dentry,
+			   const struct path *path,
 			   char *xattr_name,
 			   char **xattr_buf);
 ssize_t ksmbd_vfs_xattr_len(const struct mnt_idmap *idmap,
-			    struct dentry *dentry, char *xattr_name);
+			    const struct path *path, char *xattr_name);
 ssize_t ksmbd_vfs_getcasexattr(const struct mnt_idmap *idmap,
-			       struct dentry *dentry, char *attr_name,
+			       const struct path *path, char *attr_name,
 			       int attr_name_len, char **attr_value);
 ssize_t ksmbd_vfs_casexattr_len(const struct mnt_idmap *idmap,
-				struct dentry *dentry, char *attr_name,
+				const struct path *path, char *attr_name,
 				int attr_name_len, char *actual_name);
 int ksmbd_vfs_setxattr(const struct mnt_idmap *idmap,
 		       const struct path *path, const char *attr_name,
@@ -154,7 +154,7 @@ int ksmbd_vfs_unlink(struct file *filp);
 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,
-				struct dentry *dentry,
+				const struct path *path,
 				struct ksmbd_kstat *ksmbd_kstat);
 void ksmbd_vfs_posix_lock_wait(struct file_lock *flock);
 void ksmbd_vfs_posix_lock_unblock(struct file_lock *flock);
@@ -168,14 +168,14 @@ int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn,
 			   bool get_write);
 int ksmbd_vfs_get_sd_xattr(struct ksmbd_conn *conn,
 			   const struct mnt_idmap *idmap,
-			   struct dentry *dentry,
+			   const struct path *path,
 			   struct smb_ntsd **pntsd);
 int ksmbd_vfs_set_dos_attrib_xattr(const struct mnt_idmap *idmap,
 				   const struct path *path,
 				   struct xattr_dos_attrib *da,
 				   bool get_write);
 int ksmbd_vfs_get_dos_attrib_xattr(const struct mnt_idmap *idmap,
-				   struct dentry *dentry,
+				   const struct path *path,
 				   struct xattr_dos_attrib *da);
 int ksmbd_vfs_set_init_posix_acl(const struct mnt_idmap *idmap,
 				 const struct path *path);
diff --git a/fs/xattr.c b/fs/xattr.c
index 0705801a62cc..33bf97c3ac7f 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -286,7 +286,7 @@ int __vfs_setxattr_noperm(const struct mnt_idmap *idmap,
  * lock
  *
  *  @idmap: idmap of the mount of the target inode
- *  @dentry: object to perform setxattr on
+ *  @path: object to perform setxattr on
  *  @name: xattr name to set
  *  @value: value to set @name to
  *  @size: size of @value
@@ -295,10 +295,11 @@ int __vfs_setxattr_noperm(const struct mnt_idmap *idmap,
  *  a delegation was broken on, NULL if none.
  */
 int
-__vfs_setxattr_locked(const struct mnt_idmap *idmap, struct dentry *dentry,
+__vfs_setxattr_locked(const struct mnt_idmap *idmap, const struct path *path,
 		      const char *name, const void *value, size_t size,
 		      int flags, struct delegated_inode *delegated_inode)
 {
+	struct dentry *dentry = path->dentry;
 	struct inode *inode = dentry->d_inode;
 	int error;
 
@@ -324,9 +325,10 @@ __vfs_setxattr_locked(const struct mnt_idmap *idmap, struct dentry *dentry,
 EXPORT_SYMBOL_GPL(__vfs_setxattr_locked);
 
 int
-vfs_setxattr(const struct mnt_idmap *idmap, struct dentry *dentry,
+vfs_setxattr(const struct mnt_idmap *idmap, const struct path *path,
 	     const char *name, const void *value, size_t size, int flags)
 {
+	struct dentry *dentry = path->dentry;
 	struct inode *inode = dentry->d_inode;
 	struct delegated_inode delegated_inode = { };
 	const void  *orig_value = value;
@@ -341,7 +343,7 @@ vfs_setxattr(const struct mnt_idmap *idmap, struct dentry *dentry,
 
 retry_deleg:
 	inode_lock(inode);
-	error = __vfs_setxattr_locked(idmap, dentry, name, value, size,
+	error = __vfs_setxattr_locked(idmap, path, name, value, size,
 				      flags, &delegated_inode);
 	inode_unlock(inode);
 
@@ -448,9 +450,10 @@ __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
 EXPORT_SYMBOL(__vfs_getxattr);
 
 ssize_t
-vfs_getxattr(const struct mnt_idmap *idmap, struct dentry *dentry,
+vfs_getxattr(const struct mnt_idmap *idmap, const struct path *path,
 	     const char *name, void *value, size_t size)
 {
+	struct dentry *dentry = path->dentry;
 	struct inode *inode = dentry->d_inode;
 	int error;
 
@@ -482,12 +485,12 @@ EXPORT_SYMBOL_GPL(vfs_getxattr);
 
 /**
  * vfs_listxattr - retrieve \0 separated list of xattr names
- * @dentry: the dentry from whose inode the xattr names are retrieved
+ * @path: the path from whose inode the xattr names are retrieved
  * @list: buffer to store xattr names into
  * @size: size of the buffer
  *
  * This function returns the names of all xattrs associated with the
- * inode of @dentry.
+ * inode of @path->dentry.
  *
  * Note, for legacy reasons the vfs_listxattr() function lists POSIX
  * ACLs as well. Since POSIX ACLs are decoupled from IOP_XATTR the
@@ -503,8 +506,9 @@ EXPORT_SYMBOL_GPL(vfs_getxattr);
  *         negative error code.
  */
 ssize_t
-vfs_listxattr(struct dentry *dentry, char *list, size_t size)
+vfs_listxattr(const struct path *path, char *list, size_t size)
 {
+	struct dentry *dentry = path->dentry;
 	struct inode *inode = d_inode(dentry);
 	ssize_t error;
 
@@ -551,16 +555,17 @@ EXPORT_SYMBOL(__vfs_removexattr);
  * lock
  *
  *  @idmap: idmap of the mount of the target inode
- *  @dentry: object to perform setxattr on
+ *  @path: object to perform removexattr on
  *  @name: name of xattr to remove
  *  @delegated_inode: on return, will contain an inode pointer that
  *  a delegation was broken on, NULL if none.
  */
 int
 __vfs_removexattr_locked(const struct mnt_idmap *idmap,
-			 struct dentry *dentry, const char *name,
+			 const struct path *path, const char *name,
 			 struct delegated_inode *delegated_inode)
 {
+	struct dentry *dentry = path->dentry;
 	struct inode *inode = dentry->d_inode;
 	int error;
 
@@ -589,17 +594,17 @@ __vfs_removexattr_locked(const struct mnt_idmap *idmap,
 EXPORT_SYMBOL_GPL(__vfs_removexattr_locked);
 
 int
-vfs_removexattr(const struct mnt_idmap *idmap, struct dentry *dentry,
+vfs_removexattr(const struct mnt_idmap *idmap, const struct path *path,
 		const char *name)
 {
+	struct dentry *dentry = path->dentry;
 	struct inode *inode = dentry->d_inode;
 	struct delegated_inode delegated_inode = { };
 	int error;
 
 retry_deleg:
 	inode_lock(inode);
-	error = __vfs_removexattr_locked(idmap, dentry,
-					 name, &delegated_inode);
+	error = __vfs_removexattr_locked(idmap, path, name, &delegated_inode);
 	inode_unlock(inode);
 
 	if (is_delegated(&delegated_inode)) {
@@ -652,14 +657,14 @@ int setxattr_copy(const char __user *name, struct kernel_xattr_ctx *ctx)
 	return error;
 }
 
-static int do_setxattr(const struct mnt_idmap *idmap, struct dentry *dentry,
-		struct kernel_xattr_ctx *ctx)
+static int do_setxattr(const struct mnt_idmap *idmap, const struct path *path,
+		       struct kernel_xattr_ctx *ctx)
 {
 	if (is_posix_acl_xattr(ctx->kname->name))
-		return do_set_acl(idmap, dentry, ctx->kname->name,
-				  ctx->kvalue, ctx->size);
+		return do_set_acl(idmap, path->dentry,
+				  ctx->kname->name, ctx->kvalue, ctx->size);
 
-	return vfs_setxattr(idmap, dentry, ctx->kname->name,
+	return vfs_setxattr(idmap, path, ctx->kname->name,
 			ctx->kvalue, ctx->size, ctx->flags);
 }
 
@@ -669,7 +674,7 @@ int file_setxattr(struct file *f, struct kernel_xattr_ctx *ctx)
 
 	if (!error) {
 		audit_file(f);
-		error = do_setxattr(file_mnt_idmap(f), f->f_path.dentry, ctx);
+		error = do_setxattr(file_mnt_idmap(f), &f->f_path, ctx);
 		mnt_drop_write_file(f);
 	}
 	return error;
@@ -687,7 +692,7 @@ int filename_setxattr(int dfd, struct filename *filename,
 		return error;
 	error = mnt_want_write(path.mnt);
 	if (!error) {
-		error = do_setxattr(mnt_idmap(path.mnt), path.dentry, ctx);
+		error = do_setxattr(mnt_idmap(path.mnt), &path, ctx);
 		mnt_drop_write(path.mnt);
 	}
 	path_put(&path);
@@ -787,8 +792,8 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
  * Extended attribute GET operations
  */
 static ssize_t
-do_getxattr(const struct mnt_idmap *idmap, struct dentry *d,
-	struct kernel_xattr_ctx *ctx)
+do_getxattr(const struct mnt_idmap *idmap, const struct path *path,
+	    struct kernel_xattr_ctx *ctx)
 {
 	ssize_t error;
 	char *kname = ctx->kname->name;
@@ -803,9 +808,10 @@ do_getxattr(const struct mnt_idmap *idmap, struct dentry *d,
 	}
 
 	if (is_posix_acl_xattr(kname))
-		error = do_get_acl(idmap, d, kname, kvalue, ctx->size);
+		error = do_get_acl(idmap, path->dentry,
+				   kname, kvalue, ctx->size);
 	else
-		error = vfs_getxattr(idmap, d, kname, kvalue, ctx->size);
+		error = vfs_getxattr(idmap, path, kname, kvalue, ctx->size);
 	if (error > 0) {
 		if (ctx->size && copy_to_user(ctx->value, kvalue, error))
 			error = -EFAULT;
@@ -822,7 +828,7 @@ do_getxattr(const struct mnt_idmap *idmap, struct dentry *d,
 ssize_t file_getxattr(struct file *f, struct kernel_xattr_ctx *ctx)
 {
 	audit_file(f);
-	return do_getxattr(file_mnt_idmap(f), f->f_path.dentry, ctx);
+	return do_getxattr(file_mnt_idmap(f), &f->f_path, ctx);
 }
 
 ssize_t filename_getxattr(int dfd, struct filename *filename,
@@ -834,7 +840,7 @@ ssize_t filename_getxattr(int dfd, struct filename *filename,
 	error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
 	if (error)
 		return error;
-	error = do_getxattr(mnt_idmap(path.mnt), path.dentry, ctx);
+	error = do_getxattr(mnt_idmap(path.mnt), &path, ctx);
 	path_put(&path);
 	if (retry_estale(error, lookup_flags)) {
 		lookup_flags |= LOOKUP_REVAL;
@@ -925,7 +931,7 @@ SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name,
  * Extended attribute LIST operations
  */
 static ssize_t
-listxattr(struct dentry *d, char __user *list, size_t size)
+listxattr(const struct path *path, char __user *list, size_t size)
 {
 	ssize_t error;
 	char *klist = NULL;
@@ -938,7 +944,7 @@ listxattr(struct dentry *d, char __user *list, size_t size)
 			return -ENOMEM;
 	}
 
-	error = vfs_listxattr(d, klist, size);
+	error = vfs_listxattr(path, klist, size);
 	if (error > 0) {
 		if (size && copy_to_user(list, klist, error))
 			error = -EFAULT;
@@ -957,7 +963,7 @@ static
 ssize_t file_listxattr(struct file *f, char __user *list, size_t size)
 {
 	audit_file(f);
-	return listxattr(f->f_path.dentry, list, size);
+	return listxattr(&f->f_path, list, size);
 }
 
 static
@@ -971,7 +977,7 @@ ssize_t filename_listxattr(int dfd, struct filename *filename,
 	error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
 	if (error)
 		return error;
-	error = listxattr(path.dentry, list, size);
+	error = listxattr(&path, list, size);
 	path_put(&path);
 	if (retry_estale(error, lookup_flags)) {
 		lookup_flags |= LOOKUP_REVAL;
@@ -1029,11 +1035,12 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
  * Extended attribute REMOVE operations
  */
 static long
-removexattr(const struct mnt_idmap *idmap, struct dentry *d, const char *name)
+removexattr(const struct mnt_idmap *idmap, const struct path *path,
+	    const char *name)
 {
 	if (is_posix_acl_xattr(name))
-		return vfs_remove_acl(idmap, d, name);
-	return vfs_removexattr(idmap, d, name);
+		return vfs_remove_acl(idmap, path->dentry, name);
+	return vfs_removexattr(idmap, path, name);
 }
 
 static int file_removexattr(struct file *f, struct xattr_name *kname)
@@ -1042,8 +1049,7 @@ static int file_removexattr(struct file *f, struct xattr_name *kname)
 
 	if (!error) {
 		audit_file(f);
-		error = removexattr(file_mnt_idmap(f),
-				    f->f_path.dentry, kname->name);
+		error = removexattr(file_mnt_idmap(f), &f->f_path, kname->name);
 		mnt_drop_write_file(f);
 	}
 	return error;
@@ -1061,7 +1067,7 @@ static int filename_removexattr(int dfd, struct filename *filename,
 		return error;
 	error = mnt_want_write(path.mnt);
 	if (!error) {
-		error = removexattr(mnt_idmap(path.mnt), path.dentry, kname->name);
+		error = removexattr(mnt_idmap(path.mnt), &path, kname->name);
 		mnt_drop_write(path.mnt);
 	}
 	path_put(&path);
diff --git a/include/linux/xattr.h b/include/linux/xattr.h
index 4cc4257de084..c39f6495fb78 100644
--- a/include/linux/xattr.h
+++ b/include/linux/xattr.h
@@ -26,6 +26,7 @@
 
 struct inode;
 struct dentry;
+struct path;
 
 static inline bool is_posix_acl_xattr(const char *name)
 {
@@ -77,22 +78,25 @@ struct xattr {
 };
 
 ssize_t __vfs_getxattr(struct dentry *, struct inode *, const char *, void *, size_t);
-ssize_t vfs_getxattr(const struct mnt_idmap *, struct dentry *, const char *,
-		     void *, size_t);
-ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
+ssize_t vfs_getxattr(const struct mnt_idmap *idmap, const struct path *path,
+		     const char *name, void *value, size_t size);
+ssize_t vfs_listxattr(const struct path *path, char *list, size_t size);
 int __vfs_setxattr(const struct mnt_idmap *, struct dentry *, struct inode *,
 		   const char *, const void *, size_t, int);
 int __vfs_setxattr_noperm(const struct mnt_idmap *, struct dentry *,
 			  const char *, const void *, size_t, int);
-int __vfs_setxattr_locked(const struct mnt_idmap *, struct dentry *,
-			  const char *, const void *, size_t, int,
-			  struct delegated_inode *);
-int vfs_setxattr(const struct mnt_idmap *, struct dentry *, const char *,
-		 const void *, size_t, int);
+int __vfs_setxattr_locked(const struct mnt_idmap *idmap,
+			  const struct path *path, const char *name,
+			  const void *value, size_t size, int flags,
+			  struct delegated_inode *delegated_inode);
+int vfs_setxattr(const struct mnt_idmap *idmap, const struct path *path,
+		 const char *name, const void *value, size_t size, int flags);
 int __vfs_removexattr(const struct mnt_idmap *, struct dentry *, const char *);
-int __vfs_removexattr_locked(const struct mnt_idmap *, struct dentry *,
-			     const char *, struct delegated_inode *);
-int vfs_removexattr(const struct mnt_idmap *, struct dentry *, const char *);
+int __vfs_removexattr_locked(const struct mnt_idmap *idmap,
+			     const struct path *path, const char *name,
+			     struct delegated_inode *delegated_inode);
+int vfs_removexattr(const struct mnt_idmap *idmap, const struct path *path,
+		    const char *name);
 
 ssize_t generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size);
 int vfs_getxattr_alloc(const struct mnt_idmap *idmap,
diff --git a/security/integrity/evm/evm_crypto.c b/security/integrity/evm/evm_crypto.c
index 5eae8723f5f9..bf2b2ca90f36 100644
--- a/security/integrity/evm/evm_crypto.c
+++ b/security/integrity/evm/evm_crypto.c
@@ -254,7 +254,7 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
 	size_t xattr_size = 0;
 	char *xattr_value = NULL;
 	int error;
-	int size, user_space_size;
+	int size;
 	bool ima_present = false;
 	u64 i_version = 0;
 
@@ -309,12 +309,6 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
 		if (size < 0)
 			continue;
 
-		user_space_size = vfs_getxattr(&nop_mnt_idmap, dentry,
-					       xattr->name, NULL, 0);
-		if (user_space_size != size)
-			pr_debug("file %s: xattr %s size mismatch (kernel: %d, user: %d)\n",
-				 dentry->d_name.name, xattr->name, size,
-				 user_space_size);
 		xattr_size = size;
 		error = crypto_shash_update(desc, (const u8 *)xattr_value,
 					    xattr_size);
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 6ecb5f9657e6..d022dbffa484 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -7151,8 +7151,8 @@ static int selinux_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen
 static int selinux_inode_setsecctx(const struct path *path, void *ctx,
 				   u32 ctxlen)
 {
-	return __vfs_setxattr_locked(&nop_mnt_idmap, path->dentry,
-				     XATTR_NAME_SELINUX, ctx, ctxlen, 0, NULL);
+	return __vfs_setxattr_locked(&nop_mnt_idmap, path, XATTR_NAME_SELINUX,
+				     ctx, ctxlen, 0, NULL);
 }
 
 static int selinux_inode_getsecctx(struct inode *inode, struct lsm_context *cp)
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index f2c34e9ea4f8..8f3276746bfd 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -4984,8 +4984,8 @@ static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
 
 static int smack_inode_setsecctx(const struct path *path, void *ctx, u32 ctxlen)
 {
-	return __vfs_setxattr_locked(&nop_mnt_idmap, path->dentry,
-				     XATTR_NAME_SMACK, ctx, ctxlen, 0, NULL);
+	return __vfs_setxattr_locked(&nop_mnt_idmap, path, XATTR_NAME_SMACK,
+				     ctx, ctxlen, 0, NULL);
 }
 
 static int smack_inode_getsecctx(struct inode *inode, struct lsm_context *cp)
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 04/17] fs: pass struct path to POSIX ACL helpers
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
                   ` (2 preceding siblings ...)
  2026-11-17 15:05 ` [PATCH -next -v4 03/17] fs: pass struct path to xattr helpers Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 14:45   ` sashiko-bot
  2026-11-17 15:05 ` [PATCH -next -v4 05/17] LSM: pass struct path and struct file to the inode xattr hooks Cai Xinchen
                   ` (12 subsequent siblings)
  16 siblings, 1 reply; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

vfs_set_acl(), vfs_get_acl(), vfs_remove_acl() and the
do_set_acl()/do_get_acl() helpers take a struct dentry even though their
callers either hold a struct path (or a struct file).  Pass a struct path
instead, with the idmap still as a separate first argument.

set_posix_acl() keeps taking a dentry, as it is called from
inode_operations->set_acl.  ecryptfs_set_acl() keeps passing
&nop_mnt_idmap because its ACLs have already been translated into global
ids, while ecryptfs_get_acl() threads the upper idmap down.

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 Documentation/filesystems/porting.rst | 11 +++++++
 fs/ecryptfs/inode.c                   | 11 +++----
 fs/internal.h                         | 11 +++----
 fs/overlayfs/inode.c                  |  5 ++--
 fs/overlayfs/overlayfs.h              | 14 +++++++--
 fs/posix_acl.c                        | 41 ++++++++++++++++++---------
 fs/smb/server/vfs.c                   |  2 +-
 fs/xattr.c                            |  9 +++---
 include/linux/posix_acl.h             | 15 ++++++----
 9 files changed, 79 insertions(+), 40 deletions(-)

diff --git a/Documentation/filesystems/porting.rst b/Documentation/filesystems/porting.rst
index 82be56207772..034252f0da77 100644
--- a/Documentation/filesystems/porting.rst
+++ b/Documentation/filesystems/porting.rst
@@ -1447,3 +1447,14 @@ which notify_change() sets for the duration of the call; it must not be
 stored beyond that.  Filesystems that forward a change to another inode
 can use notify_change_target() to update the target dentry while keeping
 the caller-supplied path in ia_path.
+
+---
+
+**mandatory**
+
+vfs_set_acl(), vfs_get_acl() and vfs_remove_acl(), along with
+do_set_acl() and do_get_acl(), now take a const struct path * instead of a
+struct dentry *, keeping the mnt_idmap as a separate first argument.  The
+idmap is not derived from the path: it must be the idmap of the mount the
+operation is performed through, which for a stacking filesystem may belong
+to a different mount than the one the passed path was built from.
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index c1be27e1f7eb..7db6fa6e5274 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -1095,8 +1095,9 @@ static int ecryptfs_fileattr_set(const struct mnt_idmap *idmap,
 static struct posix_acl *ecryptfs_get_acl(const struct mnt_idmap *idmap,
 					  struct dentry *dentry, int type)
 {
-	return vfs_get_acl(idmap, ecryptfs_dentry_to_lower(dentry),
-			   posix_acl_xattr_name(type));
+	struct path lower_path = ecryptfs_lower_path(dentry);
+
+	return vfs_get_acl(idmap, &lower_path, posix_acl_xattr_name(type));
 }
 
 static int ecryptfs_set_acl(const struct mnt_idmap *idmap,
@@ -1104,10 +1105,10 @@ static int ecryptfs_set_acl(const struct mnt_idmap *idmap,
 			    int type)
 {
 	int rc;
-	struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
-	struct inode *lower_inode = d_inode(lower_dentry);
+	struct path lower_path = ecryptfs_lower_path(dentry);
+	struct inode *lower_inode = d_inode(lower_path.dentry);
 
-	rc = vfs_set_acl(&nop_mnt_idmap, lower_dentry,
+	rc = vfs_set_acl(&nop_mnt_idmap, &lower_path,
 			 posix_acl_xattr_name(type), acl);
 	if (!rc)
 		fsstack_copy_attr_all(d_inode(dentry), lower_inode);
diff --git a/fs/internal.h b/fs/internal.h
index 9580afef293e..734cd922475a 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -305,20 +305,21 @@ int import_xattr_name(struct xattr_name *kname, const char __user *name);
 int may_write_xattr(const struct mnt_idmap *idmap, struct inode *inode);
 
 #ifdef CONFIG_FS_POSIX_ACL
-int do_set_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
+int do_set_acl(const struct mnt_idmap *idmap, const struct path *path,
 	       const char *acl_name, const void *kvalue, size_t size);
-ssize_t do_get_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
+ssize_t do_get_acl(const struct mnt_idmap *idmap, const struct path *path,
 		   const char *acl_name, void *kvalue, size_t size);
 #else
 static inline int do_set_acl(const struct mnt_idmap *idmap,
-			     struct dentry *dentry, const char *acl_name,
+			     const struct path *path, const char *acl_name,
 			     const void *kvalue, size_t size)
 {
 	return -EOPNOTSUPP;
 }
 static inline ssize_t do_get_acl(const struct mnt_idmap *idmap,
-				 struct dentry *dentry, const char *acl_name,
-				 void *kvalue, size_t size)
+				 const struct path *path,
+				 const char *acl_name, void *kvalue,
+				 size_t size)
 {
 	return -EOPNOTSUPP;
 }
diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index f1c6df39d0ae..95666163075c 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -414,7 +414,7 @@ struct posix_acl *ovl_get_acl_path(const struct path *path,
 	if (noperm)
 		real_acl = get_inode_acl(realinode, posix_acl_type(acl_name));
 	else
-		real_acl = vfs_get_acl(idmap, path->dentry, acl_name);
+		real_acl = vfs_get_acl(idmap, path, acl_name);
 	if (IS_ERR_OR_NULL(real_acl))
 		return real_acl;
 
@@ -502,7 +502,8 @@ static int ovl_set_or_remove_acl(struct dentry *dentry, struct inode *inode,
 
 		ovl_path_lower(dentry, &realpath);
 		with_ovl_creds(dentry->d_sb)
-			real_acl = vfs_get_acl(mnt_idmap(realpath.mnt), realdentry, acl_name);
+			real_acl = vfs_get_acl(mnt_idmap(realpath.mnt),
+					       &realpath, acl_name);
 		if (IS_ERR(real_acl)) {
 			err = PTR_ERR(real_acl);
 			goto out;
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index 2c7beb041ef0..413f1214b1bb 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -377,13 +377,23 @@ static inline int ovl_removexattr(struct ovl_fs *ofs, struct dentry *dentry,
 static inline int ovl_do_set_acl(struct ovl_fs *ofs, struct dentry *dentry,
 				 const char *acl_name, struct posix_acl *acl)
 {
-	return vfs_set_acl(ovl_upper_mnt_idmap(ofs), dentry, acl_name, acl);
+	struct path path = {
+		.mnt = ovl_upper_mnt(ofs),
+		.dentry = dentry,
+	};
+
+	return vfs_set_acl(ovl_upper_mnt_idmap(ofs), &path, acl_name, acl);
 }
 
 static inline int ovl_do_remove_acl(struct ovl_fs *ofs, struct dentry *dentry,
 				    const char *acl_name)
 {
-	return vfs_remove_acl(ovl_upper_mnt_idmap(ofs), dentry, acl_name);
+	struct path path = {
+		.mnt = ovl_upper_mnt(ofs),
+		.dentry = dentry,
+	};
+
+	return vfs_remove_acl(ovl_upper_mnt_idmap(ofs), &path, acl_name);
 }
 
 static inline int ovl_do_rename_rd(struct renamedata *rd)
diff --git a/fs/posix_acl.c b/fs/posix_acl.c
index fe77934ea8f2..c0f835192191 100644
--- a/fs/posix_acl.c
+++ b/fs/posix_acl.c
@@ -1081,8 +1081,11 @@ static int vfs_set_acl_idmapped_mnt(const struct mnt_idmap *idmap,
 
 /**
  * vfs_set_acl - set posix acls
- * @idmap: idmap of the mount
- * @dentry: the dentry based on which to set the posix acls
+ * @idmap: idmap of the mount the posix acls are set through; it is not
+ *         derived from @path->mnt, which for a stacking filesystem may
+ *         belong to a different mount than the operation was requested
+ *         through
+ * @path: the path the posix acls are set on
  * @acl_name: the name of the posix acl
  * @kacl: the posix acls in the appropriate VFS format
  *
@@ -1091,9 +1094,10 @@ static int vfs_set_acl_idmapped_mnt(const struct mnt_idmap *idmap,
  *
  * Return: On success 0, on error negative errno.
  */
-int vfs_set_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
+int vfs_set_acl(const struct mnt_idmap *idmap, const struct path *path,
 		const char *acl_name, struct posix_acl *kacl)
 {
+	struct dentry *dentry = path->dentry;
 	int acl_type;
 	int error;
 	struct inode *inode = d_inode(dentry);
@@ -1159,8 +1163,11 @@ EXPORT_SYMBOL_GPL(vfs_set_acl);
 
 /**
  * vfs_get_acl - get posix acls
- * @idmap: idmap of the mount
- * @dentry: the dentry based on which to retrieve the posix acls
+ * @idmap: idmap of the mount the posix acls are retrieved through; it is
+ *         not derived from @path->mnt, which for a stacking filesystem may
+ *         belong to a different mount than the operation was requested
+ *         through
+ * @path: the path the posix acls are retrieved from
  * @acl_name: the name of the posix acl
  *
  * This function retrieves @kacl from the filesystem. The caller must all
@@ -1169,8 +1176,10 @@ EXPORT_SYMBOL_GPL(vfs_set_acl);
  * Return: On success POSIX ACLs in VFS format, on error negative errno.
  */
 struct posix_acl *vfs_get_acl(const struct mnt_idmap *idmap,
-			      struct dentry *dentry, const char *acl_name)
+			      const struct path *path,
+			      const char *acl_name)
 {
+	struct dentry *dentry = path->dentry;
 	struct inode *inode = d_inode(dentry);
 	struct posix_acl *acl;
 	int acl_type, error;
@@ -1204,17 +1213,21 @@ EXPORT_SYMBOL_GPL(vfs_get_acl);
 
 /**
  * vfs_remove_acl - remove posix acls
- * @idmap: idmap of the mount
- * @dentry: the dentry based on which to retrieve the posix acls
+ * @idmap: idmap of the mount the posix acls are removed through; it is
+ *         not derived from @path->mnt, which for a stacking filesystem may
+ *         belong to a different mount than the operation was requested
+ *         through
+ * @path: the path the posix acls are removed from
  * @acl_name: the name of the posix acl
  *
  * This function removes posix acls.
  *
  * Return: On success 0, on error negative errno.
  */
-int vfs_remove_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
+int vfs_remove_acl(const struct mnt_idmap *idmap, const struct path *path,
 		   const char *acl_name)
 {
+	struct dentry *dentry = path->dentry;
 	int acl_type;
 	int error;
 	struct inode *inode = d_inode(dentry);
@@ -1265,7 +1278,7 @@ int vfs_remove_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
 }
 EXPORT_SYMBOL_GPL(vfs_remove_acl);
 
-int do_set_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
+int do_set_acl(const struct mnt_idmap *idmap, const struct path *path,
 	       const char *acl_name, const void *kvalue, size_t size)
 {
 	int error;
@@ -1281,22 +1294,22 @@ int do_set_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
 			return PTR_ERR(acl);
 	}
 
-	error = vfs_set_acl(idmap, dentry, acl_name, acl);
+	error = vfs_set_acl(idmap, path, acl_name, acl);
 	posix_acl_release(acl);
 	return error;
 }
 
-ssize_t do_get_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
+ssize_t do_get_acl(const struct mnt_idmap *idmap, const struct path *path,
 		   const char *acl_name, void *kvalue, size_t size)
 {
 	ssize_t error;
 	struct posix_acl *acl;
 
-	acl = vfs_get_acl(idmap, dentry, acl_name);
+	acl = vfs_get_acl(idmap, path, acl_name);
 	if (IS_ERR(acl))
 		return PTR_ERR(acl);
 
-	error = vfs_posix_acl_to_xattr(idmap, d_inode(dentry),
+	error = vfs_posix_acl_to_xattr(idmap, d_inode(path->dentry),
 				       acl, kvalue, size);
 	posix_acl_release(acl);
 	return error;
diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
index 445fadd66f21..016510069b45 100644
--- a/fs/smb/server/vfs.c
+++ b/fs/smb/server/vfs.c
@@ -1569,7 +1569,7 @@ int ksmbd_vfs_remove_acl_xattrs(const struct mnt_idmap *idmap,
 			     sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1) ||
 		    !strncmp(name, XATTR_NAME_POSIX_ACL_DEFAULT,
 			     sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) - 1)) {
-			err = vfs_remove_acl(idmap, path->dentry, name);
+			err = vfs_remove_acl(idmap, path, name);
 			if (err)
 				ksmbd_debug(SMB,
 					    "remove acl xattr failed : %s\n", name);
diff --git a/fs/xattr.c b/fs/xattr.c
index 33bf97c3ac7f..f5b13a6402d3 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -661,8 +661,8 @@ static int do_setxattr(const struct mnt_idmap *idmap, const struct path *path,
 		       struct kernel_xattr_ctx *ctx)
 {
 	if (is_posix_acl_xattr(ctx->kname->name))
-		return do_set_acl(idmap, path->dentry,
-				  ctx->kname->name, ctx->kvalue, ctx->size);
+		return do_set_acl(idmap, path, ctx->kname->name,
+				  ctx->kvalue, ctx->size);
 
 	return vfs_setxattr(idmap, path, ctx->kname->name,
 			ctx->kvalue, ctx->size, ctx->flags);
@@ -808,8 +808,7 @@ do_getxattr(const struct mnt_idmap *idmap, const struct path *path,
 	}
 
 	if (is_posix_acl_xattr(kname))
-		error = do_get_acl(idmap, path->dentry,
-				   kname, kvalue, ctx->size);
+		error = do_get_acl(idmap, path, kname, kvalue, ctx->size);
 	else
 		error = vfs_getxattr(idmap, path, kname, kvalue, ctx->size);
 	if (error > 0) {
@@ -1039,7 +1038,7 @@ removexattr(const struct mnt_idmap *idmap, const struct path *path,
 	    const char *name)
 {
 	if (is_posix_acl_xattr(name))
-		return vfs_remove_acl(idmap, path->dentry, name);
+		return vfs_remove_acl(idmap, path, name);
 	return vfs_removexattr(idmap, path, name);
 }
 
diff --git a/include/linux/posix_acl.h b/include/linux/posix_acl.h
index caf500bed993..5a9c743dbab5 100644
--- a/include/linux/posix_acl.h
+++ b/include/linux/posix_acl.h
@@ -15,6 +15,7 @@
 #include <linux/refcount.h>
 #include <uapi/linux/posix_acl.h>
 
+struct path;
 struct user_namespace;
 
 struct posix_acl_entry {
@@ -105,11 +106,12 @@ static inline void cache_no_acl(struct inode *inode)
 	inode->i_default_acl = NULL;
 }
 
-int vfs_set_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
+int vfs_set_acl(const struct mnt_idmap *idmap, const struct path *path,
 		const char *acl_name, struct posix_acl *kacl);
 struct posix_acl *vfs_get_acl(const struct mnt_idmap *idmap,
-			      struct dentry *dentry, const char *acl_name);
-int vfs_remove_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
+			      const struct path *path,
+			      const char *acl_name);
+int vfs_remove_acl(const struct mnt_idmap *idmap, const struct path *path,
 		   const char *acl_name);
 int posix_acl_listxattr(struct inode *inode, char **buffer,
 			ssize_t *remaining_size);
@@ -142,21 +144,22 @@ static inline void forget_all_cached_acls(struct inode *inode)
 }
 
 static inline int vfs_set_acl(const struct mnt_idmap *idmap,
-			      struct dentry *dentry, const char *name,
+			      const struct path *path, const char *name,
 			      struct posix_acl *acl)
 {
 	return -EOPNOTSUPP;
 }
 
 static inline struct posix_acl *vfs_get_acl(const struct mnt_idmap *idmap,
-					    struct dentry *dentry,
+					    const struct path *path,
 					    const char *acl_name)
 {
 	return ERR_PTR(-EOPNOTSUPP);
 }
 
 static inline int vfs_remove_acl(const struct mnt_idmap *idmap,
-				 struct dentry *dentry, const char *acl_name)
+				 const struct path *path,
+				 const char *acl_name)
 {
 	return -EOPNOTSUPP;
 }
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 05/17] LSM: pass struct path and struct file to the inode xattr hooks
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
                   ` (3 preceding siblings ...)
  2026-11-17 15:05 ` [PATCH -next -v4 04/17] fs: pass struct path to POSIX ACL helpers Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 15:03   ` sashiko-bot
  2026-11-17 15:05 ` [PATCH -next -v4 06/17] LSM: pass struct path and struct file to the inode posix acl hooks Cai Xinchen
                   ` (11 subsequent siblings)
  16 siblings, 1 reply; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

Convert the inode_setxattr, inode_getxattr, inode_listxattr and
inode_removexattr hooks, along with their commoncap, SELinux, Smack, EVM
and IMA implementations, to take a const struct path instead of a dentry.
The idmap stays a separate argument for the two hooks that already take
one.

Also pass the struct file through which an xattr operation is requested,
when there is one, so that LSMs can later authorize file descriptor-based
operations with the rights available at open(2) time.  The file is
threaded through the xattr helpers and is NULL for path-based operations
and in-kernel users.

Add strong definitions of the four bpf_lsm_* stubs naming the file
argument file__nullable, and update the BPF selftests that attach to
these hooks.

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 Documentation/filesystems/porting.rst         | 13 ++++
 drivers/block/zloop.c                         |  5 +-
 fs/cachefiles/xattr.c                         | 14 ++--
 fs/ecryptfs/inode.c                           |  2 +-
 fs/nfsd/vfs.c                                 | 15 ++--
 fs/overlayfs/copy_up.c                        |  4 +-
 fs/overlayfs/overlayfs.h                      |  8 ++-
 fs/overlayfs/xattrs.c                         |  6 +-
 fs/smb/server/vfs.c                           | 12 ++--
 fs/xattr.c                                    | 70 +++++++++++--------
 include/linux/lsm_hook_defs.h                 | 12 ++--
 include/linux/security.h                      | 43 +++++++-----
 include/linux/xattr.h                         | 18 +++--
 kernel/bpf/bpf_lsm_proto.c                    | 33 +++++++++
 security/commoncap.c                          | 17 +++--
 security/integrity/evm/evm_main.c             | 20 ++++--
 security/integrity/ima/ima_appraise.c         | 16 +++--
 security/security.c                           | 55 ++++++++-------
 security/selinux/hooks.c                      | 23 +++---
 security/smack/smack_lsm.c                    | 25 ++++---
 .../selftests/bpf/progs/test_get_xattr.c      |  5 +-
 .../bpf/progs/test_set_remove_xattr.c         | 30 ++++----
 .../bpf/progs/verifier_lsm_init_xattr.c       |  6 +-
 23 files changed, 289 insertions(+), 163 deletions(-)

diff --git a/Documentation/filesystems/porting.rst b/Documentation/filesystems/porting.rst
index 034252f0da77..973f3650f8b5 100644
--- a/Documentation/filesystems/porting.rst
+++ b/Documentation/filesystems/porting.rst
@@ -1452,6 +1452,19 @@ the caller-supplied path in ia_path.
 
 **mandatory**
 
+vfs_setxattr(), vfs_getxattr(), vfs_listxattr() and vfs_removexattr()
+along with their __vfs_setxattr_locked() and __vfs_removexattr_locked()
+counterparts now take a const struct path * instead of a struct dentry *.
+The ones that already had a mnt_idmap, i.e. all of them but
+vfs_listxattr(), keep it as a separate argument: like for the POSIX ACL
+helpers, the idmap is not derived from the path.  All six helpers also
+take a trailing struct file through which the operation is requested, or
+NULL for path-based callers.
+
+---
+
+**mandatory**
+
 vfs_set_acl(), vfs_get_acl() and vfs_remove_acl(), along with
 do_set_acl() and do_get_acl(), now take a const struct path * instead of a
 struct dentry *, keeping the mnt_idmap as a separate first argument.  The
diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
index cfde2e1f03cd..9d82850d3f44 100644
--- a/drivers/block/zloop.c
+++ b/drivers/block/zloop.c
@@ -719,7 +719,8 @@ static int zloop_record_safe_wps(struct zloop_device *zlo)
 		if (!zloop_zone_is_active(zone))
 			continue;
 		ret = vfs_setxattr(file_mnt_idmap(file), &file->f_path,
-				"user.zloop.wp", &zone->wp, sizeof(zone->wp), 0);
+				"user.zloop.wp", &zone->wp, sizeof(zone->wp),
+				0, NULL);
 		if (ret) {
 			pr_err("%pg: failed to record write pointer (%d)\n",
 				zlo->disk->part0, ret);
@@ -1420,7 +1421,7 @@ static void zloop_forget_cache(struct zloop_device *zlo)
 			continue;
 
 		ret = vfs_getxattr(file_mnt_idmap(file), &file->f_path,
-				"user.zloop.wp", &old_wp, sizeof(old_wp));
+				"user.zloop.wp", &old_wp, sizeof(old_wp), NULL);
 		if (ret == -ENODATA) {
 			old_wp = 0;
 		} else if (ret != sizeof(old_wp)) {
diff --git a/fs/cachefiles/xattr.c b/fs/cachefiles/xattr.c
index afdce5ce3b73..1e814183ade4 100644
--- a/fs/cachefiles/xattr.c
+++ b/fs/cachefiles/xattr.c
@@ -56,7 +56,8 @@ int cachefiles_preset_object_xattr(struct cachefiles_object *object, struct file
 		if (ret == 0) {
 			ret = vfs_setxattr(&nop_mnt_idmap, &file->f_path,
 					   cachefiles_xattr_cache, buf,
-					   sizeof(struct cachefiles_xattr) + len, 0);
+					   sizeof(struct cachefiles_xattr) + len,
+					   0, NULL);
 			mnt_drop_write_file(file);
 		}
 	}
@@ -120,7 +121,8 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object)
 		if (ret == 0) {
 			ret = vfs_setxattr(&nop_mnt_idmap, &file->f_path,
 					   cachefiles_xattr_cache, buf,
-					   sizeof(struct cachefiles_xattr) + len, 0);
+					   sizeof(struct cachefiles_xattr) + len,
+					   0, NULL);
 			mnt_drop_write_file(file);
 		}
 	}
@@ -174,7 +176,7 @@ int cachefiles_check_auxdata(struct cachefiles_object *object, struct file *file
 	xlen = cachefiles_inject_read_error();
 	if (xlen == 0)
 		xlen = vfs_getxattr(&nop_mnt_idmap, &file->f_path,
-				    cachefiles_xattr_cache, buf, tlen);
+				    cachefiles_xattr_cache, buf, tlen, NULL);
 	if (xlen != tlen) {
 		if (xlen < 0) {
 			ret = xlen;
@@ -234,7 +236,7 @@ int cachefiles_remove_object_xattr(struct cachefiles_cache *cache,
 		ret = mnt_want_write(cache->mnt);
 		if (ret == 0) {
 			ret = vfs_removexattr(&nop_mnt_idmap, &path,
-					      cachefiles_xattr_cache);
+					      cachefiles_xattr_cache, NULL);
 			mnt_drop_write(cache->mnt);
 		}
 	}
@@ -299,7 +301,7 @@ bool cachefiles_set_volume_xattr(struct cachefiles_volume *volume)
 		if (ret == 0) {
 			ret = vfs_setxattr(&nop_mnt_idmap, &path,
 					   cachefiles_xattr_cache,
-					   buf, len, 0);
+					   buf, len, 0, NULL);
 			mnt_drop_write(volume->cache->mnt);
 		}
 	}
@@ -345,7 +347,7 @@ int cachefiles_check_volume_xattr(struct cachefiles_volume *volume)
 	xlen = cachefiles_inject_read_error();
 	if (xlen == 0)
 		xlen = vfs_getxattr(&nop_mnt_idmap, &path,
-				    cachefiles_xattr_cache, buf, len);
+				    cachefiles_xattr_cache, buf, len, NULL);
 	if (xlen != len) {
 		if (xlen < 0) {
 			ret = xlen;
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index 7db6fa6e5274..76abf142ab59 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -1003,7 +1003,7 @@ ecryptfs_setxattr(struct dentry *dentry, struct inode *inode,
 	}
 	inode_lock(lower_inode);
 	rc = __vfs_setxattr_locked(&nop_mnt_idmap, &lower_path, name, value,
-				   size, flags, NULL);
+				   size, flags, NULL, NULL);
 	inode_unlock(lower_inode);
 	if (!rc && inode)
 		fsstack_copy_attr_all(inode, lower_inode);
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index aef4097e9ef3..382bb24ddc9e 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -703,7 +703,7 @@ int nfsd4_is_junction(const struct path *path)
 	if (!(inode->i_mode & S_ISVTX))
 		return 0;
 	if (vfs_getxattr(&nop_mnt_idmap, path, NFSD_JUNCTION_XATTR_NAME,
-			 NULL, 0) <= 0)
+			 NULL, 0, NULL) <= 0)
 		return 0;
 	return 1;
 }
@@ -2695,7 +2695,7 @@ nfsd_getxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name,
 
 	inode_lock_shared(inode);
 
-	len = vfs_getxattr(&nop_mnt_idmap, &path, name, NULL, 0);
+	len = vfs_getxattr(&nop_mnt_idmap, &path, name, NULL, 0, NULL);
 
 	/*
 	 * Zero-length attribute, just return.
@@ -2722,7 +2722,7 @@ nfsd_getxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name,
 		goto out;
 	}
 
-	len = vfs_getxattr(&nop_mnt_idmap, &path, name, buf, len);
+	len = vfs_getxattr(&nop_mnt_idmap, &path, name, buf, len, NULL);
 	if (len <= 0) {
 		kvfree(buf);
 		buf = NULL;
@@ -2769,7 +2769,7 @@ nfsd_listxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char **bufp,
 
 	inode_lock_shared(inode);
 
-	len = vfs_listxattr(&path, NULL, 0);
+	len = vfs_listxattr(&path, NULL, 0, NULL);
 	if (len <= 0) {
 		err = nfsd_xattr_errno(len);
 		goto out;
@@ -2786,7 +2786,7 @@ nfsd_listxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char **bufp,
 		goto out;
 	}
 
-	len = vfs_listxattr(&path, buf, len);
+	len = vfs_listxattr(&path, buf, len, NULL);
 	if (len <= 0) {
 		kvfree(buf);
 		err = nfsd_xattr_errno(len);
@@ -2835,7 +2835,8 @@ nfsd_removexattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name)
 	err = fh_fill_pre_attrs(fhp);
 	if (err != nfs_ok)
 		goto out_unlock;
-	ret = __vfs_removexattr_locked(&nop_mnt_idmap, &path, name, NULL);
+	ret = __vfs_removexattr_locked(&nop_mnt_idmap, &path, name,
+				       NULL, NULL);
 	err = nfsd_xattr_errno(ret);
 	fh_fill_post_attrs(fhp);
 out_unlock:
@@ -2867,7 +2868,7 @@ nfsd_setxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name,
 	if (err != nfs_ok)
 		goto out_unlock;
 	ret = __vfs_setxattr_locked(&nop_mnt_idmap, &path, name, buf, len,
-				    flags, NULL);
+				    flags, NULL, NULL);
 	fh_fill_post_attrs(fhp);
 	err = nfsd_xattr_errno(ret);
 out_unlock:
diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index ac7718aa1388..dc87657733bf 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -95,7 +95,7 @@ int ovl_copy_xattr(struct super_block *sb, const struct path *oldpath, struct de
 	if (!old->d_inode->i_op->listxattr || !new->d_inode->i_op->listxattr)
 		return 0;
 
-	list_size = vfs_listxattr(oldpath, NULL, 0);
+	list_size = vfs_listxattr(oldpath, NULL, 0, NULL);
 	if (list_size <= 0) {
 		if (list_size == -EOPNOTSUPP)
 			return 0;
@@ -106,7 +106,7 @@ int ovl_copy_xattr(struct super_block *sb, const struct path *oldpath, struct de
 	if (!buf)
 		return -ENOMEM;
 
-	list_size = vfs_listxattr(oldpath, buf, list_size);
+	list_size = vfs_listxattr(oldpath, buf, list_size, NULL);
 	if (list_size <= 0) {
 		error = list_size;
 		goto out;
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index 413f1214b1bb..fb603044b59f 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -301,7 +301,8 @@ static inline ssize_t ovl_do_getxattr(const struct path *path, const char *name,
 
 	WARN_ON(path->dentry->d_sb != path->mnt->mnt_sb);
 
-	err = vfs_getxattr(mnt_idmap(path->mnt), path, name, value, size);
+	err = vfs_getxattr(mnt_idmap(path->mnt), path, name, value, size,
+			   NULL);
 	len = (value && err > 0) ? err : 0;
 
 	pr_debug("getxattr(%pd2, \"%s\", \"%*pE\", %zu, 0) = %i\n",
@@ -341,7 +342,7 @@ static inline int ovl_do_setxattr(struct ovl_fs *ofs, struct dentry *dentry,
 
 	/* Use vfs_setxattr(), not __vfs_setxattr(): it idmaps the security.capability rootid. */
 	int err = vfs_setxattr(ovl_upper_mnt_idmap(ofs), &path, name,
-			       value, size, flags);
+			       value, size, flags, NULL);
 
 	pr_debug("setxattr(%pd2, \"%s\", \"%*pE\", %zu, %d) = %i\n",
 		 dentry, name, min((int)size, 48), value, size, flags, err);
@@ -363,7 +364,8 @@ static inline int ovl_do_removexattr(struct ovl_fs *ofs, struct dentry *dentry,
 		.dentry = dentry,
 	};
 
-	int err = vfs_removexattr(ovl_upper_mnt_idmap(ofs), &path, name);
+	int err = vfs_removexattr(ovl_upper_mnt_idmap(ofs), &path, name,
+				  NULL);
 	pr_debug("removexattr(%pd2, \"%s\") = %i\n", dentry, name, err);
 	return err;
 }
diff --git a/fs/overlayfs/xattrs.c b/fs/overlayfs/xattrs.c
index 2a97a9ec642a..7bd12daba28a 100644
--- a/fs/overlayfs/xattrs.c
+++ b/fs/overlayfs/xattrs.c
@@ -46,7 +46,7 @@ static int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char
 		ovl_path_lower(dentry, &realpath);
 		with_ovl_creds(dentry->d_sb)
 			err = vfs_getxattr(mnt_idmap(realpath.mnt), &realpath,
-					   name, NULL, 0);
+					   name, NULL, 0, NULL);
 		if (err < 0)
 			goto out;
 	}
@@ -88,7 +88,7 @@ static int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char
 	/* Use vfs_getxattr(), not __vfs_getxattr(): it idmaps the security.capability rootid. */
 	with_ovl_creds(dentry->d_sb)
 		return vfs_getxattr(mnt_idmap(realpath.mnt), &realpath,
-				    name, value, size);
+				    name, value, size, NULL);
 }
 
 static bool ovl_can_list(struct super_block *sb, const char *s)
@@ -117,7 +117,7 @@ ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size)
 	ovl_path_real(dentry, &realpath);
 
 	with_ovl_creds(dentry->d_sb)
-		res = vfs_listxattr(&realpath, list, size);
+		res = vfs_listxattr(&realpath, list, size, NULL);
 	if (res <= 0 || size == 0)
 		return res;
 
diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
index 016510069b45..af7aef0c89fc 100644
--- a/fs/smb/server/vfs.c
+++ b/fs/smb/server/vfs.c
@@ -885,7 +885,7 @@ ssize_t ksmbd_vfs_listxattr(const struct path *path, char **list)
 	ssize_t size;
 	char *vlist = NULL;
 
-	size = vfs_listxattr(path, NULL, 0);
+	size = vfs_listxattr(path, NULL, 0, NULL);
 	if (size <= 0)
 		return size;
 
@@ -894,7 +894,7 @@ ssize_t ksmbd_vfs_listxattr(const struct path *path, char **list)
 		return -ENOMEM;
 
 	*list = vlist;
-	size = vfs_listxattr(path, vlist, size);
+	size = vfs_listxattr(path, vlist, size, NULL);
 	if (size < 0) {
 		ksmbd_debug(VFS, "listxattr failed\n");
 		kvfree(vlist);
@@ -907,7 +907,7 @@ ssize_t ksmbd_vfs_listxattr(const struct path *path, char **list)
 ssize_t ksmbd_vfs_xattr_len(const struct mnt_idmap *idmap,
 			    const struct path *path, char *xattr_name)
 {
-	return vfs_getxattr(idmap, path, xattr_name, NULL, 0);
+	return vfs_getxattr(idmap, path, xattr_name, NULL, 0, NULL);
 }
 
 /**
@@ -936,7 +936,7 @@ ssize_t ksmbd_vfs_getxattr(const struct mnt_idmap *idmap,
 		return -ENOMEM;
 
 	xattr_len = vfs_getxattr(idmap, path, xattr_name,
-				 (void *)buf, xattr_len);
+				 (void *)buf, xattr_len, NULL);
 	if (xattr_len > 0)
 		*xattr_buf = buf;
 	else
@@ -973,7 +973,7 @@ int ksmbd_vfs_setxattr(const struct mnt_idmap *idmap,
 			   attr_name,
 			   attr_value,
 			   attr_size,
-			   flags);
+			   flags, NULL);
 	if (err)
 		ksmbd_debug(VFS, "setxattr failed, err %d\n", err);
 	if (get_write == true)
@@ -1260,7 +1260,7 @@ int ksmbd_vfs_remove_xattr(const struct mnt_idmap *idmap,
 			return err;
 	}
 
-	err = vfs_removexattr(idmap, path, attr_name);
+	err = vfs_removexattr(idmap, path, attr_name, NULL);
 
 	if (get_write == true)
 		mnt_drop_write(path->mnt);
diff --git a/fs/xattr.c b/fs/xattr.c
index f5b13a6402d3..5256372e0fe9 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -293,11 +293,13 @@ int __vfs_setxattr_noperm(const struct mnt_idmap *idmap,
  *  @flags: flags to pass into filesystem operations
  *  @delegated_inode: on return, will contain an inode pointer that
  *  a delegation was broken on, NULL if none.
+ *  @file: file to perform setxattr on, or NULL
  */
 int
 __vfs_setxattr_locked(const struct mnt_idmap *idmap, const struct path *path,
 		      const char *name, const void *value, size_t size,
-		      int flags, struct delegated_inode *delegated_inode)
+		      int flags, struct delegated_inode *delegated_inode,
+		      struct file *file)
 {
 	struct dentry *dentry = path->dentry;
 	struct inode *inode = dentry->d_inode;
@@ -307,8 +309,8 @@ __vfs_setxattr_locked(const struct mnt_idmap *idmap, const struct path *path,
 	if (error)
 		return error;
 
-	error = security_inode_setxattr(idmap, dentry, name, value, size,
-					flags);
+	error = security_inode_setxattr(idmap, path, name, value, size,
+					flags, file);
 	if (error)
 		goto out;
 
@@ -326,7 +328,8 @@ EXPORT_SYMBOL_GPL(__vfs_setxattr_locked);
 
 int
 vfs_setxattr(const struct mnt_idmap *idmap, const struct path *path,
-	     const char *name, const void *value, size_t size, int flags)
+	     const char *name, const void *value, size_t size, int flags,
+	     struct file *file)
 {
 	struct dentry *dentry = path->dentry;
 	struct inode *inode = dentry->d_inode;
@@ -344,7 +347,7 @@ vfs_setxattr(const struct mnt_idmap *idmap, const struct path *path,
 retry_deleg:
 	inode_lock(inode);
 	error = __vfs_setxattr_locked(idmap, path, name, value, size,
-				      flags, &delegated_inode);
+				      flags, &delegated_inode, file);
 	inode_unlock(inode);
 
 	if (is_delegated(&delegated_inode)) {
@@ -451,7 +454,7 @@ EXPORT_SYMBOL(__vfs_getxattr);
 
 ssize_t
 vfs_getxattr(const struct mnt_idmap *idmap, const struct path *path,
-	     const char *name, void *value, size_t size)
+	     const char *name, void *value, size_t size, struct file *file)
 {
 	struct dentry *dentry = path->dentry;
 	struct inode *inode = dentry->d_inode;
@@ -461,7 +464,7 @@ vfs_getxattr(const struct mnt_idmap *idmap, const struct path *path,
 	if (error)
 		return error;
 
-	error = security_inode_getxattr(dentry, name);
+	error = security_inode_getxattr(path, name, file);
 	if (error)
 		return error;
 
@@ -488,6 +491,7 @@ EXPORT_SYMBOL_GPL(vfs_getxattr);
  * @path: the path from whose inode the xattr names are retrieved
  * @list: buffer to store xattr names into
  * @size: size of the buffer
+ * @file: file through which the xattr names are retrieved, if any
  *
  * This function returns the names of all xattrs associated with the
  * inode of @path->dentry.
@@ -506,13 +510,14 @@ EXPORT_SYMBOL_GPL(vfs_getxattr);
  *         negative error code.
  */
 ssize_t
-vfs_listxattr(const struct path *path, char *list, size_t size)
+vfs_listxattr(const struct path *path, char *list, size_t size,
+	      struct file *file)
 {
 	struct dentry *dentry = path->dentry;
 	struct inode *inode = d_inode(dentry);
 	ssize_t error;
 
-	error = security_inode_listxattr(dentry);
+	error = security_inode_listxattr(path, file);
 	if (error)
 		return error;
 
@@ -559,11 +564,13 @@ EXPORT_SYMBOL(__vfs_removexattr);
  *  @name: name of xattr to remove
  *  @delegated_inode: on return, will contain an inode pointer that
  *  a delegation was broken on, NULL if none.
+ *  @file: file to perform removexattr on, or NULL
  */
 int
 __vfs_removexattr_locked(const struct mnt_idmap *idmap,
 			 const struct path *path, const char *name,
-			 struct delegated_inode *delegated_inode)
+			 struct delegated_inode *delegated_inode,
+			 struct file *file)
 {
 	struct dentry *dentry = path->dentry;
 	struct inode *inode = dentry->d_inode;
@@ -573,7 +580,7 @@ __vfs_removexattr_locked(const struct mnt_idmap *idmap,
 	if (error)
 		return error;
 
-	error = security_inode_removexattr(idmap, dentry, name);
+	error = security_inode_removexattr(idmap, path, name, file);
 	if (error)
 		goto out;
 
@@ -595,7 +602,7 @@ EXPORT_SYMBOL_GPL(__vfs_removexattr_locked);
 
 int
 vfs_removexattr(const struct mnt_idmap *idmap, const struct path *path,
-		const char *name)
+		const char *name, struct file *file)
 {
 	struct dentry *dentry = path->dentry;
 	struct inode *inode = dentry->d_inode;
@@ -604,7 +611,8 @@ vfs_removexattr(const struct mnt_idmap *idmap, const struct path *path,
 
 retry_deleg:
 	inode_lock(inode);
-	error = __vfs_removexattr_locked(idmap, path, name, &delegated_inode);
+	error = __vfs_removexattr_locked(idmap, path, name, &delegated_inode,
+					  file);
 	inode_unlock(inode);
 
 	if (is_delegated(&delegated_inode)) {
@@ -658,14 +666,14 @@ int setxattr_copy(const char __user *name, struct kernel_xattr_ctx *ctx)
 }
 
 static int do_setxattr(const struct mnt_idmap *idmap, const struct path *path,
-		       struct kernel_xattr_ctx *ctx)
+		       struct kernel_xattr_ctx *ctx, struct file *file)
 {
 	if (is_posix_acl_xattr(ctx->kname->name))
 		return do_set_acl(idmap, path, ctx->kname->name,
 				  ctx->kvalue, ctx->size);
 
 	return vfs_setxattr(idmap, path, ctx->kname->name,
-			ctx->kvalue, ctx->size, ctx->flags);
+			ctx->kvalue, ctx->size, ctx->flags, file);
 }
 
 int file_setxattr(struct file *f, struct kernel_xattr_ctx *ctx)
@@ -674,7 +682,7 @@ int file_setxattr(struct file *f, struct kernel_xattr_ctx *ctx)
 
 	if (!error) {
 		audit_file(f);
-		error = do_setxattr(file_mnt_idmap(f), &f->f_path, ctx);
+		error = do_setxattr(file_mnt_idmap(f), &f->f_path, ctx, f);
 		mnt_drop_write_file(f);
 	}
 	return error;
@@ -692,7 +700,7 @@ int filename_setxattr(int dfd, struct filename *filename,
 		return error;
 	error = mnt_want_write(path.mnt);
 	if (!error) {
-		error = do_setxattr(mnt_idmap(path.mnt), &path, ctx);
+		error = do_setxattr(mnt_idmap(path.mnt), &path, ctx, NULL);
 		mnt_drop_write(path.mnt);
 	}
 	path_put(&path);
@@ -793,7 +801,7 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
  */
 static ssize_t
 do_getxattr(const struct mnt_idmap *idmap, const struct path *path,
-	    struct kernel_xattr_ctx *ctx)
+	    struct kernel_xattr_ctx *ctx, struct file *file)
 {
 	ssize_t error;
 	char *kname = ctx->kname->name;
@@ -810,7 +818,8 @@ do_getxattr(const struct mnt_idmap *idmap, const struct path *path,
 	if (is_posix_acl_xattr(kname))
 		error = do_get_acl(idmap, path, kname, kvalue, ctx->size);
 	else
-		error = vfs_getxattr(idmap, path, kname, kvalue, ctx->size);
+		error = vfs_getxattr(idmap, path, kname, kvalue,
+				     ctx->size, file);
 	if (error > 0) {
 		if (ctx->size && copy_to_user(ctx->value, kvalue, error))
 			error = -EFAULT;
@@ -827,7 +836,7 @@ do_getxattr(const struct mnt_idmap *idmap, const struct path *path,
 ssize_t file_getxattr(struct file *f, struct kernel_xattr_ctx *ctx)
 {
 	audit_file(f);
-	return do_getxattr(file_mnt_idmap(f), &f->f_path, ctx);
+	return do_getxattr(file_mnt_idmap(f), &f->f_path, ctx, f);
 }
 
 ssize_t filename_getxattr(int dfd, struct filename *filename,
@@ -839,7 +848,7 @@ ssize_t filename_getxattr(int dfd, struct filename *filename,
 	error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
 	if (error)
 		return error;
-	error = do_getxattr(mnt_idmap(path.mnt), &path, ctx);
+	error = do_getxattr(mnt_idmap(path.mnt), &path, ctx, NULL);
 	path_put(&path);
 	if (retry_estale(error, lookup_flags)) {
 		lookup_flags |= LOOKUP_REVAL;
@@ -930,7 +939,8 @@ SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name,
  * Extended attribute LIST operations
  */
 static ssize_t
-listxattr(const struct path *path, char __user *list, size_t size)
+listxattr(const struct path *path, char __user *list, size_t size,
+	   struct file *file)
 {
 	ssize_t error;
 	char *klist = NULL;
@@ -943,7 +953,7 @@ listxattr(const struct path *path, char __user *list, size_t size)
 			return -ENOMEM;
 	}
 
-	error = vfs_listxattr(path, klist, size);
+	error = vfs_listxattr(path, klist, size, file);
 	if (error > 0) {
 		if (size && copy_to_user(list, klist, error))
 			error = -EFAULT;
@@ -962,7 +972,7 @@ static
 ssize_t file_listxattr(struct file *f, char __user *list, size_t size)
 {
 	audit_file(f);
-	return listxattr(&f->f_path, list, size);
+	return listxattr(&f->f_path, list, size, f);
 }
 
 static
@@ -976,7 +986,7 @@ ssize_t filename_listxattr(int dfd, struct filename *filename,
 	error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
 	if (error)
 		return error;
-	error = listxattr(&path, list, size);
+	error = listxattr(&path, list, size, NULL);
 	path_put(&path);
 	if (retry_estale(error, lookup_flags)) {
 		lookup_flags |= LOOKUP_REVAL;
@@ -1035,11 +1045,11 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
  */
 static long
 removexattr(const struct mnt_idmap *idmap, const struct path *path,
-	    const char *name)
+	    const char *name, struct file *file)
 {
 	if (is_posix_acl_xattr(name))
 		return vfs_remove_acl(idmap, path, name);
-	return vfs_removexattr(idmap, path, name);
+	return vfs_removexattr(idmap, path, name, file);
 }
 
 static int file_removexattr(struct file *f, struct xattr_name *kname)
@@ -1048,7 +1058,8 @@ static int file_removexattr(struct file *f, struct xattr_name *kname)
 
 	if (!error) {
 		audit_file(f);
-		error = removexattr(file_mnt_idmap(f), &f->f_path, kname->name);
+		error = removexattr(file_mnt_idmap(f), &f->f_path,
+				    kname->name, f);
 		mnt_drop_write_file(f);
 	}
 	return error;
@@ -1066,7 +1077,8 @@ static int filename_removexattr(int dfd, struct filename *filename,
 		return error;
 	error = mnt_want_write(path.mnt);
 	if (!error) {
-		error = removexattr(mnt_idmap(path.mnt), &path, kname->name);
+		error = removexattr(mnt_idmap(path.mnt), &path,
+				    kname->name, NULL);
 		mnt_drop_write(path.mnt);
 	}
 	path_put(&path);
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index 7d3cd5395365..b1fffff5b3e0 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -154,14 +154,16 @@ LSM_HOOK(void, LSM_RET_VOID, inode_post_setattr, const struct mnt_idmap *idmap,
 LSM_HOOK(int, 0, inode_getattr, const struct path *path)
 LSM_HOOK(int, 0, inode_xattr_skipcap, const char *name)
 LSM_HOOK(int, 0, inode_setxattr, const struct mnt_idmap *idmap,
-	 struct dentry *dentry, const char *name, const void *value,
-	 size_t size, int flags)
+	 const struct path *path, const char *name, const void *value,
+	 size_t size, int flags, struct file *file)
 LSM_HOOK(void, LSM_RET_VOID, inode_post_setxattr, struct dentry *dentry,
 	 const char *name, const void *value, size_t size, int flags)
-LSM_HOOK(int, 0, inode_getxattr, struct dentry *dentry, const char *name)
-LSM_HOOK(int, 0, inode_listxattr, struct dentry *dentry)
+LSM_HOOK(int, 0, inode_getxattr, const struct path *path, const char *name,
+	 struct file *file)
+LSM_HOOK(int, 0, inode_listxattr, const struct path *path,
+	 struct file *file)
 LSM_HOOK(int, 0, inode_removexattr, const struct mnt_idmap *idmap,
-	 struct dentry *dentry, const char *name)
+	 const struct path *path, const char *name, struct file *file)
 LSM_HOOK(void, LSM_RET_VOID, inode_post_removexattr, struct dentry *dentry,
 	 const char *name)
 LSM_HOOK(int, 0, inode_file_setattr, struct dentry *dentry, struct file_kattr *fa)
diff --git a/include/linux/security.h b/include/linux/security.h
index b9cae538b6fc..d93492054c8d 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -185,10 +185,12 @@ extern int cap_capset(struct cred *new, const struct cred *old,
 		      const kernel_cap_t *inheritable,
 		      const kernel_cap_t *permitted);
 extern int cap_bprm_creds_from_file(struct linux_binprm *bprm, const struct file *file);
-int cap_inode_setxattr(struct dentry *dentry, const char *name,
-		       const void *value, size_t size, int flags);
+int cap_inode_setxattr(const struct path *path, const char *name,
+		       const void *value, size_t size, int flags,
+		       struct file *file);
 int cap_inode_removexattr(const struct mnt_idmap *idmap,
-			  struct dentry *dentry, const char *name);
+			  const struct path *path, const char *name,
+			  struct file *file);
 int cap_inode_need_killpriv(struct dentry *dentry);
 int cap_inode_killpriv(const struct mnt_idmap *idmap, struct dentry *dentry);
 int cap_inode_getsecurity(const struct mnt_idmap *idmap,
@@ -434,8 +436,9 @@ void security_inode_post_setattr(const struct mnt_idmap *idmap, struct dentry *d
 				 int ia_valid);
 int security_inode_getattr(const struct path *path);
 int security_inode_setxattr(const struct mnt_idmap *idmap,
-			    struct dentry *dentry, const char *name,
-			    const void *value, size_t size, int flags);
+			    const struct path *path, const char *name,
+			    const void *value, size_t size, int flags,
+			    struct file *file);
 int security_inode_set_acl(const struct mnt_idmap *idmap,
 			   struct dentry *dentry, const char *acl_name,
 			   struct posix_acl *kacl);
@@ -450,10 +453,13 @@ void security_inode_post_remove_acl(const struct mnt_idmap *idmap,
 				    const char *acl_name);
 void security_inode_post_setxattr(struct dentry *dentry, const char *name,
 				  const void *value, size_t size, int flags);
-int security_inode_getxattr(struct dentry *dentry, const char *name);
-int security_inode_listxattr(struct dentry *dentry);
+int security_inode_getxattr(const struct path *path,
+			    const char *name, struct file *file);
+int security_inode_listxattr(const struct path *path,
+			      struct file *file);
 int security_inode_removexattr(const struct mnt_idmap *idmap,
-			       struct dentry *dentry, const char *name);
+			       const struct path *path, const char *name,
+			       struct file *file);
 void security_inode_post_removexattr(struct dentry *dentry, const char *name);
 int security_inode_file_setattr(struct dentry *dentry,
 			      struct file_kattr *fa);
@@ -1012,10 +1018,11 @@ static inline int security_inode_getattr(const struct path *path)
 }
 
 static inline int security_inode_setxattr(const struct mnt_idmap *idmap,
-		struct dentry *dentry, const char *name, const void *value,
-		size_t size, int flags)
+		const struct path *path, const char *name,
+		const void *value, size_t size, int flags,
+		struct file *file)
 {
-	return cap_inode_setxattr(dentry, name, value, size, flags);
+	return cap_inode_setxattr(path, name, value, size, flags, file);
 }
 
 static inline int security_inode_set_acl(const struct mnt_idmap *idmap,
@@ -1054,22 +1061,24 @@ static inline void security_inode_post_setxattr(struct dentry *dentry,
 		const char *name, const void *value, size_t size, int flags)
 { }
 
-static inline int security_inode_getxattr(struct dentry *dentry,
-			const char *name)
+static inline int security_inode_getxattr(const struct path *path,
+			const char *name, struct file *file)
 {
 	return 0;
 }
 
-static inline int security_inode_listxattr(struct dentry *dentry)
+static inline int security_inode_listxattr(const struct path *path,
+					   struct file *file)
 {
 	return 0;
 }
 
 static inline int security_inode_removexattr(const struct mnt_idmap *idmap,
-					     struct dentry *dentry,
-					     const char *name)
+					     const struct path *path,
+					     const char *name,
+					     struct file *file)
 {
-	return cap_inode_removexattr(idmap, dentry, name);
+	return cap_inode_removexattr(idmap, path, name, file);
 }
 
 static inline void security_inode_post_removexattr(struct dentry *dentry,
diff --git a/include/linux/xattr.h b/include/linux/xattr.h
index c39f6495fb78..c82c40cd1494 100644
--- a/include/linux/xattr.h
+++ b/include/linux/xattr.h
@@ -26,6 +26,7 @@
 
 struct inode;
 struct dentry;
+struct file;
 struct path;
 
 static inline bool is_posix_acl_xattr(const char *name)
@@ -79,8 +80,10 @@ struct xattr {
 
 ssize_t __vfs_getxattr(struct dentry *, struct inode *, const char *, void *, size_t);
 ssize_t vfs_getxattr(const struct mnt_idmap *idmap, const struct path *path,
-		     const char *name, void *value, size_t size);
-ssize_t vfs_listxattr(const struct path *path, char *list, size_t size);
+		     const char *name, void *value, size_t size,
+		     struct file *file);
+ssize_t vfs_listxattr(const struct path *path, char *list, size_t size,
+		      struct file *file);
 int __vfs_setxattr(const struct mnt_idmap *, struct dentry *, struct inode *,
 		   const char *, const void *, size_t, int);
 int __vfs_setxattr_noperm(const struct mnt_idmap *, struct dentry *,
@@ -88,15 +91,18 @@ int __vfs_setxattr_noperm(const struct mnt_idmap *, struct dentry *,
 int __vfs_setxattr_locked(const struct mnt_idmap *idmap,
 			  const struct path *path, const char *name,
 			  const void *value, size_t size, int flags,
-			  struct delegated_inode *delegated_inode);
+			  struct delegated_inode *delegated_inode,
+			  struct file *file);
 int vfs_setxattr(const struct mnt_idmap *idmap, const struct path *path,
-		 const char *name, const void *value, size_t size, int flags);
+		 const char *name, const void *value, size_t size, int flags,
+		 struct file *file);
 int __vfs_removexattr(const struct mnt_idmap *, struct dentry *, const char *);
 int __vfs_removexattr_locked(const struct mnt_idmap *idmap,
 			     const struct path *path, const char *name,
-			     struct delegated_inode *delegated_inode);
+			     struct delegated_inode *delegated_inode,
+			     struct file *file);
 int vfs_removexattr(const struct mnt_idmap *idmap, const struct path *path,
-		    const char *name);
+		    const char *name, struct file *file);
 
 ssize_t generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size);
 int vfs_getxattr_alloc(const struct mnt_idmap *idmap,
diff --git a/kernel/bpf/bpf_lsm_proto.c b/kernel/bpf/bpf_lsm_proto.c
index b81179ae2e08..921910e2a1c5 100644
--- a/kernel/bpf/bpf_lsm_proto.c
+++ b/kernel/bpf/bpf_lsm_proto.c
@@ -32,3 +32,36 @@ noinline int bpf_lsm_inode_init_security(struct inode *inode, struct inode *dir,
 {
 	return -EOPNOTSUPP;
 }
+
+/*
+ * Strong definitions of the inode xattr BPF LSM hooks.  The file argument is
+ * only set for file descriptor-based operations and is NULL for path-based
+ * and in-kernel callers, so mark it as PTR_MAYBE_NULL.
+ */
+noinline int bpf_lsm_inode_setxattr(const struct mnt_idmap *idmap,
+				    const struct path *path, const char *name,
+				    const void *value, size_t size, int flags,
+				    struct file *file__nullable)
+{
+	return 0;
+}
+
+noinline int bpf_lsm_inode_getxattr(const struct path *path, const char *name,
+				    struct file *file__nullable)
+{
+	return 0;
+}
+
+noinline int bpf_lsm_inode_listxattr(const struct path *path,
+				     struct file *file__nullable)
+{
+	return 0;
+}
+
+noinline int bpf_lsm_inode_removexattr(const struct mnt_idmap *idmap,
+				       const struct path *path,
+				       const char *name,
+				       struct file *file__nullable)
+{
+	return 0;
+}
diff --git a/security/commoncap.c b/security/commoncap.c
index d0ba7049f579..1bf535a9ddd9 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -14,6 +14,7 @@
 #include <linux/netlink.h>
 #include <linux/ptrace.h>
 #include <linux/xattr.h>
+#include <linux/path.h>
 #include <linux/mount.h>
 #include <linux/sched.h>
 #include <linux/prctl.h>
@@ -1007,11 +1008,12 @@ int cap_bprm_creds_from_file(struct linux_binprm *bprm, const struct file *file)
 
 /**
  * cap_inode_setxattr - Determine whether an xattr may be altered
- * @dentry: The inode/dentry being altered
+ * @path: The inode/path being altered
  * @name: The name of the xattr to be changed
  * @value: The value that the xattr will be changed to
  * @size: The size of value
  * @flags: The replacement flag
+ * @file: the file through which the xattr change is requested, if any
  *
  * Determine whether an xattr may be altered or set on an inode, returning 0 if
  * permission is granted, -ve if denied.
@@ -1019,9 +1021,11 @@ int cap_bprm_creds_from_file(struct linux_binprm *bprm, const struct file *file)
  * This is used to make sure security xattrs don't get updated or set by those
  * who aren't privileged to do so.
  */
-int cap_inode_setxattr(struct dentry *dentry, const char *name,
-		       const void *value, size_t size, int flags)
+int cap_inode_setxattr(const struct path *path, const char *name,
+		       const void *value, size_t size, int flags,
+		       struct file *file)
 {
+	struct dentry *dentry = path->dentry;
 	struct user_namespace *user_ns = dentry->d_sb->s_user_ns;
 
 	/* Ignore non-security xattrs */
@@ -1045,8 +1049,9 @@ int cap_inode_setxattr(struct dentry *dentry, const char *name,
  * cap_inode_removexattr - Determine whether an xattr may be removed
  *
  * @idmap:	idmap of the mount the inode was found from
- * @dentry:	The inode/dentry being altered
+ * @path:	The inode/path being altered
  * @name:	The name of the xattr to be changed
+ * @file:	the file through which the xattr removal is requested, if any
  *
  * Determine whether an xattr may be removed from an inode, returning 0 if
  * permission is granted, -ve if denied.
@@ -1061,8 +1066,10 @@ int cap_inode_setxattr(struct dentry *dentry, const char *name,
  * aren't privileged to remove them.
  */
 int cap_inode_removexattr(const struct mnt_idmap *idmap,
-			  struct dentry *dentry, const char *name)
+			  const struct path *path, const char *name,
+			  struct file *file)
 {
+	struct dentry *dentry = path->dentry;
 	struct user_namespace *user_ns = dentry->d_sb->s_user_ns;
 
 	/* Ignore non-security xattrs */
diff --git a/security/integrity/evm/evm_main.c b/security/integrity/evm/evm_main.c
index 7167d854688a..d5407ed88fdc 100644
--- a/security/integrity/evm/evm_main.c
+++ b/security/integrity/evm/evm_main.c
@@ -615,11 +615,12 @@ static int evm_protect_xattr(const struct mnt_idmap *idmap,
 /**
  * evm_inode_setxattr - protect the EVM extended attribute
  * @idmap: idmap of the mount
- * @dentry: pointer to the affected dentry
+ * @path: pointer to the affected object
  * @xattr_name: pointer to the affected extended attribute name
  * @xattr_value: pointer to the new extended attribute value
  * @xattr_value_len: pointer to the new extended attribute value length
  * @flags: flags to pass into filesystem operations
+ * @file: file through which the xattr change is requested, if any
  *
  * Before allowing the 'security.evm' protected xattr to be updated,
  * verify the existing value is valid.  As only the kernel should have
@@ -627,11 +628,14 @@ static int evm_protect_xattr(const struct mnt_idmap *idmap,
  * userspace from writing HMAC value.  Writing 'security.evm' requires
  * requires CAP_SYS_ADMIN privileges.
  */
-static int evm_inode_setxattr(const struct mnt_idmap *idmap, struct dentry *dentry,
+static int evm_inode_setxattr(const struct mnt_idmap *idmap,
+			      const struct path *path,
 			      const char *xattr_name, const void *xattr_value,
-			      size_t xattr_value_len, int flags)
+			      size_t xattr_value_len, int flags,
+			      struct file *file)
 {
 	const struct evm_ima_xattr_data *xattr_data = xattr_value;
+	struct dentry *dentry = path->dentry;
 
 	/* Policy permits modification of the protected xattrs even though
 	 * there's no HMAC key loaded
@@ -653,15 +657,19 @@ static int evm_inode_setxattr(const struct mnt_idmap *idmap, struct dentry *dent
 /**
  * evm_inode_removexattr - protect the EVM extended attribute
  * @idmap: idmap of the mount
- * @dentry: pointer to the affected dentry
+ * @path: pointer to the affected object
  * @xattr_name: pointer to the affected extended attribute name
+ * @file: file through which the xattr removal is requested, if any
  *
  * Removing 'security.evm' requires CAP_SYS_ADMIN privileges and that
  * the current value is valid.
  */
-static int evm_inode_removexattr(const struct mnt_idmap *idmap, struct dentry *dentry,
-				 const char *xattr_name)
+static int evm_inode_removexattr(const struct mnt_idmap *idmap,
+				 const struct path *path,
+				 const char *xattr_name, struct file *file)
 {
+	struct dentry *dentry = path->dentry;
+
 	/* Policy permits modification of the protected xattrs even though
 	 * there's no HMAC key loaded
 	 */
diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c
index 134174d2e3f0..ebf050195cf0 100644
--- a/security/integrity/ima/ima_appraise.c
+++ b/security/integrity/ima/ima_appraise.c
@@ -759,11 +759,14 @@ static int validate_hash_algo(struct dentry *dentry,
 	return -EACCES;
 }
 
-static int ima_inode_setxattr(const struct mnt_idmap *idmap, struct dentry *dentry,
+static int ima_inode_setxattr(const struct mnt_idmap *idmap,
+			      const struct path *path,
 			      const char *xattr_name, const void *xattr_value,
-			      size_t xattr_value_len, int flags)
+			      size_t xattr_value_len, int flags,
+			      struct file *file)
 {
 	const struct evm_ima_xattr_data *xvalue = xattr_value;
+	struct dentry *dentry = path->dentry;
 	int digsig = 0;
 	int result;
 	int err;
@@ -801,16 +804,17 @@ static int ima_inode_set_acl(const struct mnt_idmap *idmap, struct dentry *dentr
 	return 0;
 }
 
-static int ima_inode_removexattr(const struct mnt_idmap *idmap, struct dentry *dentry,
-				 const char *xattr_name)
+static int ima_inode_removexattr(const struct mnt_idmap *idmap,
+				 const struct path *path,
+				 const char *xattr_name, struct file *file)
 {
 	int result, digsig = -1;
 
-	result = ima_protect_xattr(dentry, xattr_name, NULL, 0);
+	result = ima_protect_xattr(path->dentry, xattr_name, NULL, 0);
 	if (result == 1 || evm_revalidate_status(xattr_name)) {
 		if (!strcmp(xattr_name, XATTR_NAME_IMA))
 			digsig = 0;
-		ima_reset_appraise_flags(d_backing_inode(dentry), digsig);
+		ima_reset_appraise_flags(d_backing_inode(path->dentry), digsig);
 		if (result == 1)
 			result = 0;
 	}
diff --git a/security/security.c b/security/security.c
index 7e6a8a2a2ee5..e01969809ac5 100644
--- a/security/security.c
+++ b/security/security.c
@@ -1921,14 +1921,15 @@ int security_inode_getattr(const struct path *path)
 /**
  * security_inode_setxattr() - Check if setting file xattrs is allowed
  * @idmap: idmap of the mount
- * @dentry: file
+ * @path: file (the VFS makes no guarantees with regard to @path->mnt)
  * @name: xattr name
  * @value: xattr value
  * @size: size of xattr value
  * @flags: flags
+ * @file: file through which the xattr change is requested, if any
  *
  * This hook performs the desired permission checks before setting the extended
- * attributes (xattrs) on @dentry.  It is important to note that we have some
+ * attributes (xattrs) on @path.  It is important to note that we have some
  * additional logic before the main LSM implementation calls to detect if we
  * need to perform an additional capability check at the LSM layer.
  *
@@ -1945,23 +1946,24 @@ int security_inode_getattr(const struct path *path)
  * Return: Returns 0 if permission is granted.
  */
 int security_inode_setxattr(const struct mnt_idmap *idmap,
-			    struct dentry *dentry, const char *name,
-			    const void *value, size_t size, int flags)
+			    const struct path *path, const char *name,
+			    const void *value, size_t size, int flags,
+			    struct file *file)
 {
 	int rc;
 
-	if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
+	if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
 		return 0;
 
 	/* enforce the capability checks at the lsm layer, if needed */
 	if (!call_int_hook(inode_xattr_skipcap, name)) {
-		rc = cap_inode_setxattr(dentry, name, value, size, flags);
+		rc = cap_inode_setxattr(path, name, value, size, flags, file);
 		if (rc)
 			return rc;
 	}
 
-	return call_int_hook(inode_setxattr, idmap, dentry, name, value, size,
-			     flags);
+	return call_int_hook(inode_setxattr, idmap, path, name, value,
+			     size, flags, file);
 }
 
 /**
@@ -2077,45 +2079,49 @@ void security_inode_post_setxattr(struct dentry *dentry, const char *name,
 
 /**
  * security_inode_getxattr() - Check if xattr access is allowed
- * @dentry: file
+ * @path: file (the VFS makes no guarantees with regard to @path->mnt)
  * @name: xattr name
+ * @file: file through which the xattr access is requested, if any
  *
  * Check permission before obtaining the extended attributes identified by
- * @name for @dentry.
+ * @name for @path.
  *
  * Return: Returns 0 if permission is granted.
  */
-int security_inode_getxattr(struct dentry *dentry, const char *name)
+int security_inode_getxattr(const struct path *path,
+			    const char *name, struct file *file)
 {
-	if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
+	if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
 		return 0;
-	return call_int_hook(inode_getxattr, dentry, name);
+	return call_int_hook(inode_getxattr, path, name, file);
 }
 
 /**
  * security_inode_listxattr() - Check if listing xattrs is allowed
- * @dentry: file
+ * @path: file (the VFS makes no guarantees with regard to @path->mnt)
+ * @file: file through which the xattr names are listed, if any
  *
  * Check permission before obtaining the list of extended attribute names for
- * @dentry.
+ * @path.
  *
  * Return: Returns 0 if permission is granted.
  */
-int security_inode_listxattr(struct dentry *dentry)
+int security_inode_listxattr(const struct path *path, struct file *file)
 {
-	if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
+	if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
 		return 0;
-	return call_int_hook(inode_listxattr, dentry);
+	return call_int_hook(inode_listxattr, path, file);
 }
 
 /**
  * security_inode_removexattr() - Check if removing an xattr is allowed
  * @idmap: idmap of the mount
- * @dentry: file
+ * @path: file (the VFS makes no guarantees with regard to @path->mnt)
  * @name: xattr name
+ * @file: file through which the xattr removal is requested, if any
  *
  * This hook performs the desired permission checks before setting the extended
- * attributes (xattrs) on @dentry.  It is important to note that we have some
+ * attributes (xattrs) on @path.  It is important to note that we have some
  * additional logic before the main LSM implementation calls to detect if we
  * need to perform an additional capability check at the LSM layer.
  *
@@ -2132,21 +2138,22 @@ int security_inode_listxattr(struct dentry *dentry)
  * Return: Returns 0 if permission is granted.
  */
 int security_inode_removexattr(const struct mnt_idmap *idmap,
-			       struct dentry *dentry, const char *name)
+			       const struct path *path, const char *name,
+			       struct file *file)
 {
 	int rc;
 
-	if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
+	if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
 		return 0;
 
 	/* enforce the capability checks at the lsm layer, if needed */
 	if (!call_int_hook(inode_xattr_skipcap, name)) {
-		rc = cap_inode_removexattr(idmap, dentry, name);
+		rc = cap_inode_removexattr(idmap, path, name, file);
 		if (rc)
 			return rc;
 	}
 
-	return call_int_hook(inode_removexattr, idmap, dentry, name);
+	return call_int_hook(inode_removexattr, idmap, path, name, file);
 }
 
 /**
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index d022dbffa484..f38105ccc1fb 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3388,9 +3388,11 @@ static int selinux_inode_xattr_skipcap(const char *name)
 }
 
 static int selinux_inode_setxattr(const struct mnt_idmap *idmap,
-				  struct dentry *dentry, const char *name,
-				  const void *value, size_t size, int flags)
+				  const struct path *path,
+				  const char *name, const void *value,
+				  size_t size, int flags, struct file *file)
 {
+	struct dentry *dentry = path->dentry;
 	struct inode *inode = d_backing_inode(dentry);
 	struct inode_security_struct *isec;
 	struct superblock_security_struct *sbsec;
@@ -3532,26 +3534,29 @@ static void selinux_inode_post_setxattr(struct dentry *dentry, const char *name,
 	spin_unlock(&isec->lock);
 }
 
-static int selinux_inode_getxattr(struct dentry *dentry, const char *name)
+static int selinux_inode_getxattr(const struct path *path,
+				  const char *name, struct file *file)
 {
 	const struct cred *cred = current_cred();
 
-	return dentry_has_perm(cred, dentry, FILE__GETATTR);
+	return dentry_has_perm(cred, path->dentry, FILE__GETATTR);
 }
 
-static int selinux_inode_listxattr(struct dentry *dentry)
+static int selinux_inode_listxattr(const struct path *path, struct file *file)
 {
 	const struct cred *cred = current_cred();
 
-	return dentry_has_perm(cred, dentry, FILE__GETATTR);
+	return dentry_has_perm(cred, path->dentry, FILE__GETATTR);
 }
 
 static int selinux_inode_removexattr(const struct mnt_idmap *idmap,
-				     struct dentry *dentry, const char *name)
+				     const struct path *path,
+				     const char *name, struct file *file)
 {
 	/* if not a selinux xattr, only check the ordinary setattr perm */
 	if (strcmp(name, XATTR_NAME_SELINUX))
-		return dentry_has_perm(current_cred(), dentry, FILE__SETATTR);
+		return dentry_has_perm(current_cred(), path->dentry,
+				       FILE__SETATTR);
 
 	if (!selinux_initialized())
 		return 0;
@@ -7152,7 +7157,7 @@ static int selinux_inode_setsecctx(const struct path *path, void *ctx,
 				   u32 ctxlen)
 {
 	return __vfs_setxattr_locked(&nop_mnt_idmap, path, XATTR_NAME_SELINUX,
-				     ctx, ctxlen, 0, NULL);
+				     ctx, ctxlen, 0, NULL, NULL);
 }
 
 static int selinux_inode_getsecctx(struct inode *inode, struct lsm_context *cp)
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 8f3276746bfd..be522c236dbf 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1340,21 +1340,24 @@ static int smack_inode_xattr_skipcap(const char *name)
 /**
  * smack_inode_setxattr - Smack check for setting xattrs
  * @idmap: idmap of the mount
- * @dentry: the object
+ * @path: the object
  * @name: name of the attribute
  * @value: value of the attribute
  * @size: size of the value
  * @flags: unused
+ * @file: file through which the xattr change is requested, if any
  *
  * This protects the Smack attribute explicitly.
  *
  * Returns 0 if access is permitted, an error code otherwise
  */
 static int smack_inode_setxattr(const struct mnt_idmap *idmap,
-				struct dentry *dentry, const char *name,
-				const void *value, size_t size, int flags)
+				const struct path *path,
+				const char *name, const void *value,
+				size_t size, int flags, struct file *file)
 {
 	struct smk_audit_info ad;
+	struct dentry *dentry = path->dentry;
 	struct smack_known *skp;
 	int check_priv = 0;
 	int check_import = 0;
@@ -1456,14 +1459,17 @@ static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
 
 /**
  * smack_inode_getxattr - Smack check on getxattr
- * @dentry: the object
+ * @path: the object
  * @name: unused
+ * @file: file through which the xattr access is requested, if any
  *
  * Returns 0 if access is permitted, an error code otherwise
  */
-static int smack_inode_getxattr(struct dentry *dentry, const char *name)
+static int smack_inode_getxattr(const struct path *path,
+			const char *name, struct file *file)
 {
 	struct smk_audit_info ad;
+	struct dentry *dentry = path->dentry;
 	int rc;
 
 	smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_DENTRY);
@@ -1477,18 +1483,21 @@ static int smack_inode_getxattr(struct dentry *dentry, const char *name)
 /**
  * smack_inode_removexattr - Smack check on removexattr
  * @idmap: idmap of the mount
- * @dentry: the object
+ * @path: the object
  * @name: name of the attribute
+ * @file: file through which the xattr removal is requested, if any
  *
  * Removing the Smack attribute requires CAP_MAC_ADMIN
  *
  * Returns 0 if access is permitted, an error code otherwise
  */
 static int smack_inode_removexattr(const struct mnt_idmap *idmap,
-				   struct dentry *dentry, const char *name)
+				   const struct path *path,
+				   const char *name, struct file *file)
 {
 	struct inode_smack *isp;
 	struct smk_audit_info ad;
+	struct dentry *dentry = path->dentry;
 	int rc = 0;
 
 	if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
@@ -4985,7 +4994,7 @@ static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
 static int smack_inode_setsecctx(const struct path *path, void *ctx, u32 ctxlen)
 {
 	return __vfs_setxattr_locked(&nop_mnt_idmap, path, XATTR_NAME_SMACK,
-				     ctx, ctxlen, 0, NULL);
+				     ctx, ctxlen, 0, NULL, NULL);
 }
 
 static int smack_inode_getsecctx(struct inode *inode, struct lsm_context *cp)
diff --git a/tools/testing/selftests/bpf/progs/test_get_xattr.c b/tools/testing/selftests/bpf/progs/test_get_xattr.c
index 54305f4c9f2d..97361ff10e9f 100644
--- a/tools/testing/selftests/bpf/progs/test_get_xattr.c
+++ b/tools/testing/selftests/bpf/progs/test_get_xattr.c
@@ -56,7 +56,8 @@ int BPF_PROG(test_file_open, struct file *f)
 }
 
 SEC("lsm.s/inode_getxattr")
-int BPF_PROG(test_inode_getxattr, struct dentry *dentry, char *name)
+int BPF_PROG(test_inode_getxattr, const struct path *path, char *name,
+	     struct file *file)
 {
 	struct bpf_dynptr value_ptr;
 	__u32 pid;
@@ -69,7 +70,7 @@ int BPF_PROG(test_inode_getxattr, struct dentry *dentry, char *name)
 	bpf_dynptr_from_mem(value2, sizeof(value2), 0, &value_ptr);
 
 	for (i = 0; i < ARRAY_SIZE(xattr_names); i++) {
-		ret = bpf_get_dentry_xattr(dentry, xattr_names[i], &value_ptr);
+		ret = bpf_get_dentry_xattr(path->dentry, xattr_names[i], &value_ptr);
 		if (ret == sizeof(expected_value))
 			break;
 	}
diff --git a/tools/testing/selftests/bpf/progs/test_set_remove_xattr.c b/tools/testing/selftests/bpf/progs/test_set_remove_xattr.c
index 6a612cf168d3..06656ac9a777 100644
--- a/tools/testing/selftests/bpf/progs/test_set_remove_xattr.c
+++ b/tools/testing/selftests/bpf/progs/test_set_remove_xattr.c
@@ -33,7 +33,8 @@ static inline bool name_match_foo(const char *name)
 
 /* Test bpf_set_dentry_xattr and bpf_remove_dentry_xattr */
 SEC("lsm.s/inode_getxattr")
-int BPF_PROG(test_inode_getxattr, struct dentry *dentry, char *name)
+int BPF_PROG(test_inode_getxattr, const struct path *path, char *name,
+	     struct file *file)
 {
 	struct bpf_dynptr value_ptr;
 	__u32 pid;
@@ -50,25 +51,25 @@ int BPF_PROG(test_inode_getxattr, struct dentry *dentry, char *name)
 	bpf_dynptr_from_mem(read_value, sizeof(read_value), 0, &value_ptr);
 
 	/* read security.bpf.bar */
-	ret = bpf_get_dentry_xattr(dentry, xattr_bar, &value_ptr);
+	ret = bpf_get_dentry_xattr(path->dentry, xattr_bar, &value_ptr);
 
 	if (ret < 0) {
 		/* If security.bpf.bar doesn't exist, set it */
 		bpf_dynptr_from_mem(value_bar, sizeof(value_bar), 0, &value_ptr);
 
-		ret = bpf_set_dentry_xattr(dentry, xattr_bar, &value_ptr, 0);
+		ret = bpf_set_dentry_xattr(path->dentry, xattr_bar, &value_ptr, 0);
 		if (!ret)
 			set_security_bpf_bar_success = true;
-		ret = bpf_set_dentry_xattr(dentry, xattr_selinux, &value_ptr, 0);
+		ret = bpf_set_dentry_xattr(path->dentry, xattr_selinux, &value_ptr, 0);
 		if (ret)
 			set_security_selinux_fail = true;
 	} else {
 		/* If security.bpf.bar exists, remove it */
-		ret = bpf_remove_dentry_xattr(dentry, xattr_bar);
+		ret = bpf_remove_dentry_xattr(path->dentry, xattr_bar);
 		if (!ret)
 			remove_security_bpf_bar_success = true;
 
-		ret = bpf_remove_dentry_xattr(dentry, xattr_selinux);
+		ret = bpf_remove_dentry_xattr(path->dentry, xattr_selinux);
 		if (ret)
 			remove_security_selinux_fail = true;
 	}
@@ -87,9 +88,10 @@ bool locked_remove_security_selinux_fail;
  * properly.
  */
 SEC("lsm.s/inode_setxattr")
-int BPF_PROG(test_inode_setxattr, struct mnt_idmap *idmap,
-	     struct dentry *dentry, const char *name,
-	     const void *value, size_t size, int flags)
+int BPF_PROG(test_inode_setxattr, const struct mnt_idmap *idmap,
+	     const struct path *path,
+	     const char *name, const void *value, size_t size, int flags,
+	     struct file *file)
 {
 	struct bpf_dynptr value_ptr;
 	__u32 pid;
@@ -106,25 +108,25 @@ int BPF_PROG(test_inode_setxattr, struct mnt_idmap *idmap,
 	bpf_dynptr_from_mem(read_value, sizeof(read_value), 0, &value_ptr);
 
 	/* read security.bpf.bar */
-	ret = bpf_get_dentry_xattr(dentry, xattr_bar, &value_ptr);
+	ret = bpf_get_dentry_xattr(path->dentry, xattr_bar, &value_ptr);
 
 	if (ret < 0) {
 		/* If security.bpf.bar doesn't exist, set it */
 		bpf_dynptr_from_mem(value_bar, sizeof(value_bar), 0, &value_ptr);
 
-		ret = bpf_set_dentry_xattr(dentry, xattr_bar, &value_ptr, 0);
+		ret = bpf_set_dentry_xattr(path->dentry, xattr_bar, &value_ptr, 0);
 		if (!ret)
 			locked_set_security_bpf_bar_success = true;
-		ret = bpf_set_dentry_xattr(dentry, xattr_selinux, &value_ptr, 0);
+		ret = bpf_set_dentry_xattr(path->dentry, xattr_selinux, &value_ptr, 0);
 		if (ret)
 			locked_set_security_selinux_fail = true;
 	} else {
 		/* If security.bpf.bar exists, remove it */
-		ret = bpf_remove_dentry_xattr(dentry, xattr_bar);
+		ret = bpf_remove_dentry_xattr(path->dentry, xattr_bar);
 		if (!ret)
 			locked_remove_security_bpf_bar_success = true;
 
-		ret = bpf_remove_dentry_xattr(dentry, xattr_selinux);
+		ret = bpf_remove_dentry_xattr(path->dentry, xattr_selinux);
 		if (ret)
 			locked_remove_security_selinux_fail = true;
 	}
diff --git a/tools/testing/selftests/bpf/progs/verifier_lsm_init_xattr.c b/tools/testing/selftests/bpf/progs/verifier_lsm_init_xattr.c
index b706bf17b556..9b7a15c1862f 100644
--- a/tools/testing/selftests/bpf/progs/verifier_lsm_init_xattr.c
+++ b/tools/testing/selftests/bpf/progs/verifier_lsm_init_xattr.c
@@ -234,8 +234,10 @@ int BPF_PROG(reject_lsm_cgroup, struct inode *inode, struct inode *dir,
 
 SEC("lsm/inode_setxattr")
 __failure __msg("calling kernel function bpf_inode_init_xattr is not allowed")
-int BPF_PROG(reject_wrong_hook, struct mnt_idmap *idmap, struct dentry *dentry,
-	     const char *name, const void *value, size_t size, int flags)
+int BPF_PROG(reject_wrong_hook, const struct mnt_idmap *idmap,
+	     const struct path *path,
+	     const char *name, const void *value, size_t size, int flags,
+	     struct file *file)
 {
 	struct bpf_dynptr val;
 
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 06/17] LSM: pass struct path and struct file to the inode posix acl hooks
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
                   ` (4 preceding siblings ...)
  2026-11-17 15:05 ` [PATCH -next -v4 05/17] LSM: pass struct path and struct file to the inode xattr hooks Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 15:07   ` sashiko-bot
  2026-11-17 15:05 ` [PATCH -next -v4 07/17] LSM: pass struct path and struct file to the inode fileattr hooks Cai Xinchen
                   ` (10 subsequent siblings)
  16 siblings, 1 reply; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

Convert the inode_set_acl, inode_get_acl and inode_remove_acl hooks and
their SELinux, Smack, EVM and IMA implementations to take a const struct
path instead of a dentry.  The implementations derive the dentry they
still need from the path, and the idmap stays a separate argument.

Also pass the struct file through which the operation is requested, when
there is one, for the same reason as for the xattr hooks, and add strong
definitions of the three bpf_lsm_* stubs naming it file__nullable.

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 Documentation/filesystems/porting.rst |  3 ++
 fs/ecryptfs/inode.c                   |  5 ++--
 fs/internal.h                         | 11 ++++---
 fs/overlayfs/inode.c                  |  4 +--
 fs/overlayfs/overlayfs.h              |  6 ++--
 fs/posix_acl.c                        | 26 ++++++++++-------
 fs/smb/server/vfs.c                   |  2 +-
 fs/xattr.c                            |  7 +++--
 include/linux/lsm_hook_defs.h         |  9 ++++--
 include/linux/posix_acl.h             | 14 +++++----
 include/linux/security.h              | 25 +++++++++-------
 kernel/bpf/bpf_lsm_proto.c            | 29 ++++++++++++++++++
 security/integrity/evm/evm_main.c     | 22 +++++++++-----
 security/integrity/ima/ima_appraise.c | 15 ++++++----
 security/security.c                   | 42 +++++++++++++++++----------
 security/selinux/hooks.c              | 17 ++++++-----
 security/smack/smack_lsm.c            | 41 ++++++++++++++++----------
 17 files changed, 183 insertions(+), 95 deletions(-)

diff --git a/Documentation/filesystems/porting.rst b/Documentation/filesystems/porting.rst
index 973f3650f8b5..01890bda8479 100644
--- a/Documentation/filesystems/porting.rst
+++ b/Documentation/filesystems/porting.rst
@@ -1471,3 +1471,6 @@ struct dentry *, keeping the mnt_idmap as a separate first argument.  The
 idmap is not derived from the path: it must be the idmap of the mount the
 operation is performed through, which for a stacking filesystem may belong
 to a different mount than the one the passed path was built from.
+vfs_set_acl(), vfs_get_acl() and vfs_remove_acl() also take a trailing
+struct file through which the operation is requested, or NULL for
+path-based callers.
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index 76abf142ab59..e4a1e2f346c8 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -1097,7 +1097,8 @@ static struct posix_acl *ecryptfs_get_acl(const struct mnt_idmap *idmap,
 {
 	struct path lower_path = ecryptfs_lower_path(dentry);
 
-	return vfs_get_acl(idmap, &lower_path, posix_acl_xattr_name(type));
+	return vfs_get_acl(idmap, &lower_path, posix_acl_xattr_name(type),
+			   NULL);
 }
 
 static int ecryptfs_set_acl(const struct mnt_idmap *idmap,
@@ -1109,7 +1110,7 @@ static int ecryptfs_set_acl(const struct mnt_idmap *idmap,
 	struct inode *lower_inode = d_inode(lower_path.dentry);
 
 	rc = vfs_set_acl(&nop_mnt_idmap, &lower_path,
-			 posix_acl_xattr_name(type), acl);
+			 posix_acl_xattr_name(type), acl, NULL);
 	if (!rc)
 		fsstack_copy_attr_all(d_inode(dentry), lower_inode);
 	return rc;
diff --git a/fs/internal.h b/fs/internal.h
index 734cd922475a..d6a3b48f1633 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -306,20 +306,23 @@ int may_write_xattr(const struct mnt_idmap *idmap, struct inode *inode);
 
 #ifdef CONFIG_FS_POSIX_ACL
 int do_set_acl(const struct mnt_idmap *idmap, const struct path *path,
-	       const char *acl_name, const void *kvalue, size_t size);
+	       const char *acl_name, const void *kvalue, size_t size,
+	       struct file *file);
 ssize_t do_get_acl(const struct mnt_idmap *idmap, const struct path *path,
-		   const char *acl_name, void *kvalue, size_t size);
+		   const char *acl_name, void *kvalue, size_t size,
+		   struct file *file);
 #else
 static inline int do_set_acl(const struct mnt_idmap *idmap,
 			     const struct path *path, const char *acl_name,
-			     const void *kvalue, size_t size)
+			     const void *kvalue, size_t size,
+			     struct file *file)
 {
 	return -EOPNOTSUPP;
 }
 static inline ssize_t do_get_acl(const struct mnt_idmap *idmap,
 				 const struct path *path,
 				 const char *acl_name, void *kvalue,
-				 size_t size)
+				 size_t size, struct file *file)
 {
 	return -EOPNOTSUPP;
 }
diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index 95666163075c..1700cc74ef01 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -414,7 +414,7 @@ struct posix_acl *ovl_get_acl_path(const struct path *path,
 	if (noperm)
 		real_acl = get_inode_acl(realinode, posix_acl_type(acl_name));
 	else
-		real_acl = vfs_get_acl(idmap, path, acl_name);
+		real_acl = vfs_get_acl(idmap, path, acl_name, NULL);
 	if (IS_ERR_OR_NULL(real_acl))
 		return real_acl;
 
@@ -503,7 +503,7 @@ static int ovl_set_or_remove_acl(struct dentry *dentry, struct inode *inode,
 		ovl_path_lower(dentry, &realpath);
 		with_ovl_creds(dentry->d_sb)
 			real_acl = vfs_get_acl(mnt_idmap(realpath.mnt),
-					       &realpath, acl_name);
+					       &realpath, acl_name, NULL);
 		if (IS_ERR(real_acl)) {
 			err = PTR_ERR(real_acl);
 			goto out;
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index fb603044b59f..71885794421e 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -384,7 +384,8 @@ static inline int ovl_do_set_acl(struct ovl_fs *ofs, struct dentry *dentry,
 		.dentry = dentry,
 	};
 
-	return vfs_set_acl(ovl_upper_mnt_idmap(ofs), &path, acl_name, acl);
+	return vfs_set_acl(ovl_upper_mnt_idmap(ofs), &path, acl_name, acl,
+			   NULL);
 }
 
 static inline int ovl_do_remove_acl(struct ovl_fs *ofs, struct dentry *dentry,
@@ -395,7 +396,8 @@ static inline int ovl_do_remove_acl(struct ovl_fs *ofs, struct dentry *dentry,
 		.dentry = dentry,
 	};
 
-	return vfs_remove_acl(ovl_upper_mnt_idmap(ofs), &path, acl_name);
+	return vfs_remove_acl(ovl_upper_mnt_idmap(ofs), &path, acl_name,
+			      NULL);
 }
 
 static inline int ovl_do_rename_rd(struct renamedata *rd)
diff --git a/fs/posix_acl.c b/fs/posix_acl.c
index c0f835192191..4de0ad023df8 100644
--- a/fs/posix_acl.c
+++ b/fs/posix_acl.c
@@ -1088,6 +1088,7 @@ static int vfs_set_acl_idmapped_mnt(const struct mnt_idmap *idmap,
  * @path: the path the posix acls are set on
  * @acl_name: the name of the posix acl
  * @kacl: the posix acls in the appropriate VFS format
+ * @file: file through which the posix acls are set, or NULL
  *
  * This function sets @kacl. The caller must all posix_acl_release() on @kacl
  * afterwards.
@@ -1095,7 +1096,8 @@ static int vfs_set_acl_idmapped_mnt(const struct mnt_idmap *idmap,
  * Return: On success 0, on error negative errno.
  */
 int vfs_set_acl(const struct mnt_idmap *idmap, const struct path *path,
-		const char *acl_name, struct posix_acl *kacl)
+		const char *acl_name, struct posix_acl *kacl,
+		struct file *file)
 {
 	struct dentry *dentry = path->dentry;
 	int acl_type;
@@ -1131,7 +1133,7 @@ int vfs_set_acl(const struct mnt_idmap *idmap, const struct path *path,
 	if (error)
 		goto out_inode_unlock;
 
-	error = security_inode_set_acl(idmap, dentry, acl_name, kacl);
+	error = security_inode_set_acl(idmap, path, acl_name, kacl, file);
 	if (error)
 		goto out_inode_unlock;
 
@@ -1169,6 +1171,7 @@ EXPORT_SYMBOL_GPL(vfs_set_acl);
  *         through
  * @path: the path the posix acls are retrieved from
  * @acl_name: the name of the posix acl
+ * @file: file through which the posix acls are retrieved, or NULL
  *
  * This function retrieves @kacl from the filesystem. The caller must all
  * posix_acl_release() on @kacl.
@@ -1177,7 +1180,7 @@ EXPORT_SYMBOL_GPL(vfs_set_acl);
  */
 struct posix_acl *vfs_get_acl(const struct mnt_idmap *idmap,
 			      const struct path *path,
-			      const char *acl_name)
+			      const char *acl_name, struct file *file)
 {
 	struct dentry *dentry = path->dentry;
 	struct inode *inode = d_inode(dentry);
@@ -1192,7 +1195,7 @@ struct posix_acl *vfs_get_acl(const struct mnt_idmap *idmap,
 	 * The VFS has no restrictions on reading POSIX ACLs so calling
 	 * something like xattr_permission() isn't needed. Only LSMs get a say.
 	 */
-	error = security_inode_get_acl(idmap, dentry, acl_name);
+	error = security_inode_get_acl(idmap, path, acl_name, file);
 	if (error)
 		return ERR_PTR(error);
 
@@ -1219,13 +1222,14 @@ EXPORT_SYMBOL_GPL(vfs_get_acl);
  *         through
  * @path: the path the posix acls are removed from
  * @acl_name: the name of the posix acl
+ * @file: file through which the posix acls are removed, or NULL
  *
  * This function removes posix acls.
  *
  * Return: On success 0, on error negative errno.
  */
 int vfs_remove_acl(const struct mnt_idmap *idmap, const struct path *path,
-		   const char *acl_name)
+		   const char *acl_name, struct file *file)
 {
 	struct dentry *dentry = path->dentry;
 	int acl_type;
@@ -1248,7 +1252,7 @@ int vfs_remove_acl(const struct mnt_idmap *idmap, const struct path *path,
 	if (error)
 		goto out_inode_unlock;
 
-	error = security_inode_remove_acl(idmap, dentry, acl_name);
+	error = security_inode_remove_acl(idmap, path, acl_name, file);
 	if (error)
 		goto out_inode_unlock;
 
@@ -1279,7 +1283,8 @@ int vfs_remove_acl(const struct mnt_idmap *idmap, const struct path *path,
 EXPORT_SYMBOL_GPL(vfs_remove_acl);
 
 int do_set_acl(const struct mnt_idmap *idmap, const struct path *path,
-	       const char *acl_name, const void *kvalue, size_t size)
+	       const char *acl_name, const void *kvalue, size_t size,
+	       struct file *file)
 {
 	int error;
 	struct posix_acl *acl = NULL;
@@ -1294,18 +1299,19 @@ int do_set_acl(const struct mnt_idmap *idmap, const struct path *path,
 			return PTR_ERR(acl);
 	}
 
-	error = vfs_set_acl(idmap, path, acl_name, acl);
+	error = vfs_set_acl(idmap, path, acl_name, acl, file);
 	posix_acl_release(acl);
 	return error;
 }
 
 ssize_t do_get_acl(const struct mnt_idmap *idmap, const struct path *path,
-		   const char *acl_name, void *kvalue, size_t size)
+		   const char *acl_name, void *kvalue, size_t size,
+		   struct file *file)
 {
 	ssize_t error;
 	struct posix_acl *acl;
 
-	acl = vfs_get_acl(idmap, path, acl_name);
+	acl = vfs_get_acl(idmap, path, acl_name, file);
 	if (IS_ERR(acl))
 		return PTR_ERR(acl);
 
diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
index af7aef0c89fc..efb66a914a8e 100644
--- a/fs/smb/server/vfs.c
+++ b/fs/smb/server/vfs.c
@@ -1569,7 +1569,7 @@ int ksmbd_vfs_remove_acl_xattrs(const struct mnt_idmap *idmap,
 			     sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1) ||
 		    !strncmp(name, XATTR_NAME_POSIX_ACL_DEFAULT,
 			     sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) - 1)) {
-			err = vfs_remove_acl(idmap, path, name);
+			err = vfs_remove_acl(idmap, path, name, NULL);
 			if (err)
 				ksmbd_debug(SMB,
 					    "remove acl xattr failed : %s\n", name);
diff --git a/fs/xattr.c b/fs/xattr.c
index 5256372e0fe9..a07d03a0502f 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -670,7 +670,7 @@ static int do_setxattr(const struct mnt_idmap *idmap, const struct path *path,
 {
 	if (is_posix_acl_xattr(ctx->kname->name))
 		return do_set_acl(idmap, path, ctx->kname->name,
-				  ctx->kvalue, ctx->size);
+				  ctx->kvalue, ctx->size, file);
 
 	return vfs_setxattr(idmap, path, ctx->kname->name,
 			ctx->kvalue, ctx->size, ctx->flags, file);
@@ -816,7 +816,8 @@ do_getxattr(const struct mnt_idmap *idmap, const struct path *path,
 	}
 
 	if (is_posix_acl_xattr(kname))
-		error = do_get_acl(idmap, path, kname, kvalue, ctx->size);
+		error = do_get_acl(idmap, path, kname, kvalue,
+				   ctx->size, file);
 	else
 		error = vfs_getxattr(idmap, path, kname, kvalue,
 				     ctx->size, file);
@@ -1048,7 +1049,7 @@ removexattr(const struct mnt_idmap *idmap, const struct path *path,
 	    const char *name, struct file *file)
 {
 	if (is_posix_acl_xattr(name))
-		return vfs_remove_acl(idmap, path, name);
+		return vfs_remove_acl(idmap, path, name, file);
 	return vfs_removexattr(idmap, path, name, file);
 }
 
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index b1fffff5b3e0..229eaee0a0dd 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -169,13 +169,16 @@ LSM_HOOK(void, LSM_RET_VOID, inode_post_removexattr, struct dentry *dentry,
 LSM_HOOK(int, 0, inode_file_setattr, struct dentry *dentry, struct file_kattr *fa)
 LSM_HOOK(int, 0, inode_file_getattr, struct dentry *dentry, struct file_kattr *fa)
 LSM_HOOK(int, 0, inode_set_acl, const struct mnt_idmap *idmap,
-	 struct dentry *dentry, const char *acl_name, struct posix_acl *kacl)
+	 const struct path *path, const char *acl_name,
+	 struct posix_acl *kacl, struct file *file)
 LSM_HOOK(void, LSM_RET_VOID, inode_post_set_acl, struct dentry *dentry,
 	 const char *acl_name, struct posix_acl *kacl)
 LSM_HOOK(int, 0, inode_get_acl, const struct mnt_idmap *idmap,
-	 struct dentry *dentry, const char *acl_name)
+	 const struct path *path, const char *acl_name,
+	 struct file *file)
 LSM_HOOK(int, 0, inode_remove_acl, const struct mnt_idmap *idmap,
-	 struct dentry *dentry, const char *acl_name)
+	 const struct path *path, const char *acl_name,
+	 struct file *file)
 LSM_HOOK(void, LSM_RET_VOID, inode_post_remove_acl, const struct mnt_idmap *idmap,
 	 struct dentry *dentry, const char *acl_name)
 LSM_HOOK(int, 0, inode_need_killpriv, struct dentry *dentry)
diff --git a/include/linux/posix_acl.h b/include/linux/posix_acl.h
index 5a9c743dbab5..c3c926b3fdeb 100644
--- a/include/linux/posix_acl.h
+++ b/include/linux/posix_acl.h
@@ -107,12 +107,13 @@ static inline void cache_no_acl(struct inode *inode)
 }
 
 int vfs_set_acl(const struct mnt_idmap *idmap, const struct path *path,
-		const char *acl_name, struct posix_acl *kacl);
+		const char *acl_name, struct posix_acl *kacl,
+		struct file *file);
 struct posix_acl *vfs_get_acl(const struct mnt_idmap *idmap,
 			      const struct path *path,
-			      const char *acl_name);
+			      const char *acl_name, struct file *file);
 int vfs_remove_acl(const struct mnt_idmap *idmap, const struct path *path,
-		   const char *acl_name);
+		   const char *acl_name, struct file *file);
 int posix_acl_listxattr(struct inode *inode, char **buffer,
 			ssize_t *remaining_size);
 #else
@@ -145,21 +146,22 @@ static inline void forget_all_cached_acls(struct inode *inode)
 
 static inline int vfs_set_acl(const struct mnt_idmap *idmap,
 			      const struct path *path, const char *name,
-			      struct posix_acl *acl)
+			      struct posix_acl *acl, struct file *file)
 {
 	return -EOPNOTSUPP;
 }
 
 static inline struct posix_acl *vfs_get_acl(const struct mnt_idmap *idmap,
 					    const struct path *path,
-					    const char *acl_name)
+					    const char *acl_name,
+					    struct file *file)
 {
 	return ERR_PTR(-EOPNOTSUPP);
 }
 
 static inline int vfs_remove_acl(const struct mnt_idmap *idmap,
 				 const struct path *path,
-				 const char *acl_name)
+				 const char *acl_name, struct file *file)
 {
 	return -EOPNOTSUPP;
 }
diff --git a/include/linux/security.h b/include/linux/security.h
index d93492054c8d..cbd50cd38255 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -440,14 +440,16 @@ int security_inode_setxattr(const struct mnt_idmap *idmap,
 			    const void *value, size_t size, int flags,
 			    struct file *file);
 int security_inode_set_acl(const struct mnt_idmap *idmap,
-			   struct dentry *dentry, const char *acl_name,
-			   struct posix_acl *kacl);
+			   const struct path *path, const char *acl_name,
+			   struct posix_acl *kacl, struct file *file);
 void security_inode_post_set_acl(struct dentry *dentry, const char *acl_name,
 				 struct posix_acl *kacl);
 int security_inode_get_acl(const struct mnt_idmap *idmap,
-			   struct dentry *dentry, const char *acl_name);
+			   const struct path *path, const char *acl_name,
+			   struct file *file);
 int security_inode_remove_acl(const struct mnt_idmap *idmap,
-			      struct dentry *dentry, const char *acl_name);
+			      const struct path *path, const char *acl_name,
+			      struct file *file);
 void security_inode_post_remove_acl(const struct mnt_idmap *idmap,
 				    struct dentry *dentry,
 				    const char *acl_name);
@@ -1026,9 +1028,10 @@ static inline int security_inode_setxattr(const struct mnt_idmap *idmap,
 }
 
 static inline int security_inode_set_acl(const struct mnt_idmap *idmap,
-					 struct dentry *dentry,
+					 const struct path *path,
 					 const char *acl_name,
-					 struct posix_acl *kacl)
+					 struct posix_acl *kacl,
+					 struct file *file)
 {
 	return 0;
 }
@@ -1039,15 +1042,17 @@ static inline void security_inode_post_set_acl(struct dentry *dentry,
 { }
 
 static inline int security_inode_get_acl(const struct mnt_idmap *idmap,
-					 struct dentry *dentry,
-					 const char *acl_name)
+					 const struct path *path,
+					 const char *acl_name,
+					 struct file *file)
 {
 	return 0;
 }
 
 static inline int security_inode_remove_acl(const struct mnt_idmap *idmap,
-					    struct dentry *dentry,
-					    const char *acl_name)
+					    const struct path *path,
+					    const char *acl_name,
+					    struct file *file)
 {
 	return 0;
 }
diff --git a/kernel/bpf/bpf_lsm_proto.c b/kernel/bpf/bpf_lsm_proto.c
index 921910e2a1c5..4454c1fdbe6b 100644
--- a/kernel/bpf/bpf_lsm_proto.c
+++ b/kernel/bpf/bpf_lsm_proto.c
@@ -65,3 +65,32 @@ noinline int bpf_lsm_inode_removexattr(const struct mnt_idmap *idmap,
 {
 	return 0;
 }
+
+/*
+ * Strong definitions of the inode POSIX ACL BPF LSM hooks.  The file argument
+ * is only set for file descriptor-based operations and is NULL for path-based
+ * and in-kernel callers, so mark it as PTR_MAYBE_NULL.
+ */
+noinline int bpf_lsm_inode_set_acl(const struct mnt_idmap *idmap,
+				   const struct path *path,
+				   const char *acl_name, struct posix_acl *kacl,
+				   struct file *file__nullable)
+{
+	return 0;
+}
+
+noinline int bpf_lsm_inode_get_acl(const struct mnt_idmap *idmap,
+				   const struct path *path,
+				   const char *acl_name,
+				   struct file *file__nullable)
+{
+	return 0;
+}
+
+noinline int bpf_lsm_inode_remove_acl(const struct mnt_idmap *idmap,
+				      const struct path *path,
+				      const char *acl_name,
+				      struct file *file__nullable)
+{
+	return 0;
+}
diff --git a/security/integrity/evm/evm_main.c b/security/integrity/evm/evm_main.c
index d5407ed88fdc..963a1bc89a7d 100644
--- a/security/integrity/evm/evm_main.c
+++ b/security/integrity/evm/evm_main.c
@@ -710,10 +710,11 @@ static inline int evm_inode_set_acl_change(const struct mnt_idmap *idmap,
 
 /**
  * evm_inode_set_acl - protect the EVM extended attribute from posix acls
- * @idmap: idmap of the idmapped mount
- * @dentry: pointer to the affected dentry
+ * @idmap: idmap of the mount
+ * @path: pointer to the affected object
  * @acl_name: name of the posix acl
  * @kacl: pointer to the posix acls
+ * @file: file through which the posix acls are set, if any
  *
  * Prevent modifying posix acls causing the EVM HMAC to be re-calculated
  * and 'security.evm' xattr updated, unless the existing 'security.evm' is
@@ -721,10 +722,13 @@ static inline int evm_inode_set_acl_change(const struct mnt_idmap *idmap,
  *
  * Return: zero on success, -EPERM on failure.
  */
-static int evm_inode_set_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
-			     const char *acl_name, struct posix_acl *kacl)
+static int evm_inode_set_acl(const struct mnt_idmap *idmap,
+			     const struct path *path,
+			     const char *acl_name, struct posix_acl *kacl,
+			     struct file *file)
 {
 	enum integrity_status evm_status;
+	struct dentry *dentry = path->dentry;
 
 	/* Policy permits modification of the protected xattrs even though
 	 * there's no HMAC key loaded
@@ -764,8 +768,9 @@ static int evm_inode_set_acl(const struct mnt_idmap *idmap, struct dentry *dentr
 /**
  * evm_inode_remove_acl - Protect the EVM extended attribute from posix acls
  * @idmap: idmap of the mount
- * @dentry: pointer to the affected dentry
+ * @path: pointer to the affected object
  * @acl_name: name of the posix acl
+ * @file: file through which the posix acls are removed, if any
  *
  * Prevent removing posix acls causing the EVM HMAC to be re-calculated
  * and 'security.evm' xattr updated, unless the existing 'security.evm' is
@@ -773,10 +778,11 @@ static int evm_inode_set_acl(const struct mnt_idmap *idmap, struct dentry *dentr
  *
  * Return: zero on success, -EPERM on failure.
  */
-static int evm_inode_remove_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
-				const char *acl_name)
+static int evm_inode_remove_acl(const struct mnt_idmap *idmap,
+				const struct path *path,
+				const char *acl_name, struct file *file)
 {
-	return evm_inode_set_acl(idmap, dentry, acl_name, NULL);
+	return evm_inode_set_acl(idmap, path, acl_name, NULL, file);
 }
 
 static void evm_reset_status(struct inode *inode)
diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c
index ebf050195cf0..a231f1f419f7 100644
--- a/security/integrity/ima/ima_appraise.c
+++ b/security/integrity/ima/ima_appraise.c
@@ -795,11 +795,13 @@ static int ima_inode_setxattr(const struct mnt_idmap *idmap,
 	return result;
 }
 
-static int ima_inode_set_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
-			     const char *acl_name, struct posix_acl *kacl)
+static int ima_inode_set_acl(const struct mnt_idmap *idmap,
+			     const struct path *path,
+			     const char *acl_name, struct posix_acl *kacl,
+			     struct file *file)
 {
 	if (evm_revalidate_status(acl_name))
-		ima_reset_appraise_flags(d_backing_inode(dentry), -1);
+		ima_reset_appraise_flags(d_backing_inode(path->dentry), -1);
 
 	return 0;
 }
@@ -821,10 +823,11 @@ static int ima_inode_removexattr(const struct mnt_idmap *idmap,
 	return result;
 }
 
-static int ima_inode_remove_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
-				const char *acl_name)
+static int ima_inode_remove_acl(const struct mnt_idmap *idmap,
+				 const struct path *path,
+				 const char *acl_name, struct file *file)
 {
-	return ima_inode_set_acl(idmap, dentry, acl_name, NULL);
+	return ima_inode_set_acl(idmap, path, acl_name, NULL, file);
 }
 
 static struct security_hook_list ima_appraise_hooks[] __ro_after_init = {
diff --git a/security/security.c b/security/security.c
index e01969809ac5..b62a6e63dea1 100644
--- a/security/security.c
+++ b/security/security.c
@@ -1969,9 +1969,12 @@ int security_inode_setxattr(const struct mnt_idmap *idmap,
 /**
  * security_inode_set_acl() - Check if setting posix acls is allowed
  * @idmap: idmap of the mount
- * @dentry: file
+ * @path: the object the posix acls are set on (the VFS makes no guarantees
+ *        with regard to @path->mnt)
  * @acl_name: acl name
  * @kacl: acl struct
+ * @file: file through which the posix acls are set, if any; it refers to
+ *        the same object as @path
  *
  * Check permission before setting posix acls, the posix acls in @kacl are
  * identified by @acl_name.
@@ -1979,12 +1982,13 @@ int security_inode_setxattr(const struct mnt_idmap *idmap,
  * Return: Returns 0 if permission is granted.
  */
 int security_inode_set_acl(const struct mnt_idmap *idmap,
-			   struct dentry *dentry, const char *acl_name,
-			   struct posix_acl *kacl)
+			   const struct path *path, const char *acl_name,
+			   struct posix_acl *kacl, struct file *file)
 {
-	if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
+	if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
 		return 0;
-	return call_int_hook(inode_set_acl, idmap, dentry, acl_name, kacl);
+	return call_int_hook(inode_set_acl, idmap, path, acl_name, kacl,
+			       file);
 }
 
 /**
@@ -2007,27 +2011,34 @@ void security_inode_post_set_acl(struct dentry *dentry, const char *acl_name,
 /**
  * security_inode_get_acl() - Check if reading posix acls is allowed
  * @idmap: idmap of the mount
- * @dentry: file
+ * @path: the object the posix acls are retrieved from (the VFS makes no
+ *        guarantees with regard to @path->mnt)
  * @acl_name: acl name
+ * @file: file through which the posix acls are retrieved, if any; it
+ *        refers to the same object as @path
  *
- * Check permission before getting osix acls, the posix acls are identified by
- * @acl_name.
+ * Check permission before getting posix acls, the posix acls are identified
+ * by @acl_name.
  *
  * Return: Returns 0 if permission is granted.
  */
 int security_inode_get_acl(const struct mnt_idmap *idmap,
-			   struct dentry *dentry, const char *acl_name)
+			   const struct path *path, const char *acl_name,
+			   struct file *file)
 {
-	if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
+	if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
 		return 0;
-	return call_int_hook(inode_get_acl, idmap, dentry, acl_name);
+	return call_int_hook(inode_get_acl, idmap, path, acl_name, file);
 }
 
 /**
  * security_inode_remove_acl() - Check if removing a posix acl is allowed
  * @idmap: idmap of the mount
- * @dentry: file
+ * @path: the object the posix acl is removed from (the VFS makes no
+ *        guarantees with regard to @path->mnt)
  * @acl_name: acl name
+ * @file: file through which the posix acl is removed, if any; it refers to
+ *        the same object as @path
  *
  * Check permission before removing posix acls, the posix acls are identified
  * by @acl_name.
@@ -2035,11 +2046,12 @@ int security_inode_get_acl(const struct mnt_idmap *idmap,
  * Return: Returns 0 if permission is granted.
  */
 int security_inode_remove_acl(const struct mnt_idmap *idmap,
-			      struct dentry *dentry, const char *acl_name)
+			      const struct path *path, const char *acl_name,
+			      struct file *file)
 {
-	if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
+	if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
 		return 0;
-	return call_int_hook(inode_remove_acl, idmap, dentry, acl_name);
+	return call_int_hook(inode_remove_acl, idmap, path, acl_name, file);
 }
 
 /**
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index f38105ccc1fb..bd7ae5433575 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3476,22 +3476,25 @@ static int selinux_inode_setxattr(const struct mnt_idmap *idmap,
 }
 
 static int selinux_inode_set_acl(const struct mnt_idmap *idmap,
-				 struct dentry *dentry, const char *acl_name,
-				 struct posix_acl *kacl)
+				 const struct path *path,
+				 const char *acl_name, struct posix_acl *kacl,
+				 struct file *file)
 {
-	return dentry_has_perm(current_cred(), dentry, FILE__SETATTR);
+	return dentry_has_perm(current_cred(), path->dentry, FILE__SETATTR);
 }
 
 static int selinux_inode_get_acl(const struct mnt_idmap *idmap,
-				 struct dentry *dentry, const char *acl_name)
+				 const struct path *path,
+				 const char *acl_name, struct file *file)
 {
-	return dentry_has_perm(current_cred(), dentry, FILE__GETATTR);
+	return dentry_has_perm(current_cred(), path->dentry, FILE__GETATTR);
 }
 
 static int selinux_inode_remove_acl(const struct mnt_idmap *idmap,
-				    struct dentry *dentry, const char *acl_name)
+				    const struct path *path,
+				    const char *acl_name, struct file *file)
 {
-	return dentry_has_perm(current_cred(), dentry, FILE__SETATTR);
+	return dentry_has_perm(current_cred(), path->dentry, FILE__SETATTR);
 }
 
 static void selinux_inode_post_setxattr(struct dentry *dentry, const char *name,
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index be522c236dbf..74c4a40ef028 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1548,68 +1548,77 @@ static int smack_inode_removexattr(const struct mnt_idmap *idmap,
 /**
  * smack_inode_set_acl - Smack check for setting posix acls
  * @idmap: idmap of the mnt this request came from
- * @dentry: the object
+ * @path: the object
  * @acl_name: name of the posix acl
  * @kacl: the posix acls
+ * @file: file through which the posix acls are set, if any
  *
  * Returns 0 if access is permitted, an error code otherwise
  */
 static int smack_inode_set_acl(const struct mnt_idmap *idmap,
-			       struct dentry *dentry, const char *acl_name,
-			       struct posix_acl *kacl)
+			       const struct path *path,
+			       const char *acl_name, struct posix_acl *kacl,
+			       struct file *file)
 {
 	struct smk_audit_info ad;
 	int rc;
 
 	smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_DENTRY);
-	smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
+	smk_ad_setfield_u_fs_path_dentry(&ad, path->dentry);
 
-	rc = smk_curacc(smk_of_inode(d_backing_inode(dentry)), MAY_WRITE, &ad);
-	rc = smk_bu_inode(d_backing_inode(dentry), MAY_WRITE, rc);
+	rc = smk_curacc(smk_of_inode(d_backing_inode(path->dentry)),
+			MAY_WRITE, &ad);
+	rc = smk_bu_inode(d_backing_inode(path->dentry), MAY_WRITE, rc);
 	return rc;
 }
 
 /**
  * smack_inode_get_acl - Smack check for getting posix acls
  * @idmap: idmap of the mnt this request came from
- * @dentry: the object
+ * @path: the object
  * @acl_name: name of the posix acl
+ * @file: file through which the posix acls are retrieved, if any
  *
  * Returns 0 if access is permitted, an error code otherwise
  */
 static int smack_inode_get_acl(const struct mnt_idmap *idmap,
-			       struct dentry *dentry, const char *acl_name)
+			       const struct path *path,
+			       const char *acl_name, struct file *file)
 {
 	struct smk_audit_info ad;
 	int rc;
 
 	smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_DENTRY);
-	smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
+	smk_ad_setfield_u_fs_path_dentry(&ad, path->dentry);
 
-	rc = smk_curacc(smk_of_inode(d_backing_inode(dentry)), MAY_READ, &ad);
-	rc = smk_bu_inode(d_backing_inode(dentry), MAY_READ, rc);
+	rc = smk_curacc(smk_of_inode(d_backing_inode(path->dentry)),
+			MAY_READ, &ad);
+	rc = smk_bu_inode(d_backing_inode(path->dentry), MAY_READ, rc);
 	return rc;
 }
 
 /**
  * smack_inode_remove_acl - Smack check for getting posix acls
  * @idmap: idmap of the mnt this request came from
- * @dentry: the object
+ * @path: the object
  * @acl_name: name of the posix acl
+ * @file: file through which the posix acls are removed, if any
  *
  * Returns 0 if access is permitted, an error code otherwise
  */
 static int smack_inode_remove_acl(const struct mnt_idmap *idmap,
-				  struct dentry *dentry, const char *acl_name)
+				  const struct path *path,
+				  const char *acl_name, struct file *file)
 {
 	struct smk_audit_info ad;
 	int rc;
 
 	smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_DENTRY);
-	smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
+	smk_ad_setfield_u_fs_path_dentry(&ad, path->dentry);
 
-	rc = smk_curacc(smk_of_inode(d_backing_inode(dentry)), MAY_WRITE, &ad);
-	rc = smk_bu_inode(d_backing_inode(dentry), MAY_WRITE, rc);
+	rc = smk_curacc(smk_of_inode(d_backing_inode(path->dentry)),
+			MAY_WRITE, &ad);
+	rc = smk_bu_inode(d_backing_inode(path->dentry), MAY_WRITE, rc);
 	return rc;
 }
 
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 07/17] LSM: pass struct path and struct file to the inode fileattr hooks
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
                   ` (5 preceding siblings ...)
  2026-11-17 15:05 ` [PATCH -next -v4 06/17] LSM: pass struct path and struct file to the inode posix acl hooks Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 14:51   ` sashiko-bot
  2026-11-17 15:05 ` [PATCH -next -v4 08/17] LSM: rename inode_setattr to path_setattr and pass struct path and file Cai Xinchen
                   ` (9 subsequent siblings)
  16 siblings, 1 reply; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

Switch vfs_fileattr_get(), vfs_fileattr_set(), the inode_file_getattr and
inode_file_setattr hooks and their SELinux implementations to take a
const struct path, and pass the struct file through which the operation
is requested when there is one.

vfs_fileattr_get() keeps checking i_op->fileattr_get before calling the
hook, so the -ENOIOCTLCMD fallback used by the ioctls is unchanged.  Add
an unchecked __vfs_fileattr_get() for the internal users: nfsd's casefold
probe, and the read of the current attributes in do_vfs_fileattr_set(),
which is authorized as a whole by the set hook.  ksmbd keeps using the
checked helpers, passing the file it holds or NULL for path-only probes;
stacking filesystems do the same, so overlayfs keeps its existing
file:ioctl/file:open workaround until the LSM semantics are agreed on.

Add strong definitions of the two bpf_lsm_* stubs naming the file
argument file__nullable.

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 Documentation/filesystems/porting.rst |  15 +++
 fs/ecryptfs/inode.c                   |  10 +-
 fs/file_attr.c                        | 136 +++++++++++++++++---------
 fs/nfsd/vfs.c                         |   2 +-
 fs/overlayfs/inode.c                  |  20 ++--
 fs/smb/server/smb2pdu.c               |   6 +-
 fs/smb/server/vfs.c                   |  15 +--
 fs/smb/server/vfs.h                   |   3 +-
 include/linux/fileattr.h              |  10 +-
 include/linux/lsm_hook_defs.h         |   6 +-
 include/linux/security.h              |  18 ++--
 kernel/bpf/bpf_lsm_proto.c            |  19 ++++
 security/security.c                   |  18 ++--
 security/selinux/hooks.c              |  14 +--
 14 files changed, 199 insertions(+), 93 deletions(-)

diff --git a/Documentation/filesystems/porting.rst b/Documentation/filesystems/porting.rst
index 01890bda8479..f3feb27e898c 100644
--- a/Documentation/filesystems/porting.rst
+++ b/Documentation/filesystems/porting.rst
@@ -1474,3 +1474,18 @@ to a different mount than the one the passed path was built from.
 vfs_set_acl(), vfs_get_acl() and vfs_remove_acl() also take a trailing
 struct file through which the operation is requested, or NULL for
 path-based callers.
+
+---
+
+**mandatory**
+
+vfs_fileattr_get() and vfs_fileattr_set() now take a const struct path *
+instead of a struct dentry *, and vfs_fileattr_set() keeps its mnt_idmap
+as a separate first argument.  The idmap is not derived from the path: it
+must be the idmap of the mount the operation is performed through, which
+for a stacking filesystem may belong to a different mount than the one
+the passed path was built from.  Both also take a trailing struct file
+through which the operation is requested, or NULL for path-based
+callers.  The fileattr_get() and fileattr_set() inode operations they
+call are unchanged.  The new __vfs_fileattr_get() helper is their
+counterpart without the security hook, for kernel-internal readers.
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index e4a1e2f346c8..566fbcbbf7df 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -1077,17 +1077,19 @@ static int ecryptfs_removexattr(struct dentry *dentry, struct inode *inode,
 
 static int ecryptfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
 {
-	return vfs_fileattr_get(ecryptfs_dentry_to_lower(dentry), fa);
+	struct path lower_path = ecryptfs_lower_path(dentry);
+
+	return vfs_fileattr_get(&lower_path, fa, NULL);
 }
 
 static int ecryptfs_fileattr_set(const struct mnt_idmap *idmap,
 				 struct dentry *dentry, struct file_kattr *fa)
 {
-	struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
+	struct path lower_path = ecryptfs_lower_path(dentry);
 	int rc;
 
-	rc = vfs_fileattr_set(&nop_mnt_idmap, lower_dentry, fa);
-	fsstack_copy_attr_all(d_inode(dentry), d_inode(lower_dentry));
+	rc = vfs_fileattr_set(&nop_mnt_idmap, &lower_path, fa, NULL);
+	fsstack_copy_attr_all(d_inode(dentry), d_inode(lower_path.dentry));
 
 	return rc;
 }
diff --git a/fs/file_attr.c b/fs/file_attr.c
index 833e03810b24..846847e64ad3 100644
--- a/fs/file_attr.c
+++ b/fs/file_attr.c
@@ -75,27 +75,65 @@ void fileattr_fill_flags(struct file_kattr *fa, u32 flags)
 EXPORT_SYMBOL(fileattr_fill_flags);
 
 /**
- * vfs_fileattr_get - retrieve miscellaneous file attributes
+ * __vfs_fileattr_get - retrieve miscellaneous file attributes
  * @dentry:	the object to retrieve from
  * @fa:		fileattr pointer
  *
- * Call i_op->fileattr_get() callback, if exists.
+ * Call i_op->fileattr_get() callback, if exists.  Unlike
+ * vfs_fileattr_get(), no security hook is called.  This is for
+ * kernel-internal users that do not authorize the operation through the
+ * fileattr hooks themselves: nfsd's casefold probe, and the read of the
+ * current attributes performed as part of a user-facing change, which
+ * do_vfs_fileattr_set() authorizes as a whole through the file attribute
+ * set hook.
+ *
+ * Callers may or may not hold the inode lock: do_vfs_fileattr_set() calls
+ * this with the lock held, while nfsd_get_case_info() calls it without.
+ * ->fileattr_get() must cope with both, as documented in
+ * Documentation/filesystems/locking.rst.
  *
  * Return: 0 on success, or a negative error on failure.
  */
-int vfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
+int __vfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
 {
 	struct inode *inode = d_inode(dentry);
+
+	if (!inode->i_op->fileattr_get)
+		return -ENOIOCTLCMD;
+
+	return inode->i_op->fileattr_get(dentry, fa);
+}
+EXPORT_SYMBOL(__vfs_fileattr_get);
+
+/**
+ * vfs_fileattr_get - retrieve miscellaneous file attributes
+ * @path:	the object to retrieve from
+ * @fa:		fileattr pointer
+ * @file:	file through which the attributes are retrieved, if any
+ *
+ * Call i_op->fileattr_get() callback, if exists.
+ *
+ * Return: 0 on success, or a negative error on failure.
+ */
+int vfs_fileattr_get(const struct path *path, struct file_kattr *fa,
+		     struct file *file)
+{
+	struct inode *inode = d_inode(path->dentry);
 	int error;
 
+	/*
+	 * Keep the -ENOIOCTLCMD fallback for filesystems that do not
+	 * implement fileattr_get before running the security hook, as
+	 * ioctl_getflags() and friends rely on it.
+	 */
 	if (!inode->i_op->fileattr_get)
 		return -ENOIOCTLCMD;
 
-	error = security_inode_file_getattr(dentry, fa);
+	error = security_inode_file_getattr(path, fa, file);
 	if (error)
 		return error;
 
-	return inode->i_op->fileattr_get(dentry, fa);
+	return __vfs_fileattr_get(path->dentry, fa);
 }
 EXPORT_SYMBOL(vfs_fileattr_get);
 
@@ -254,25 +292,12 @@ static int fileattr_set_prepare(struct inode *inode,
 	return 0;
 }
 
-/**
- * vfs_fileattr_set - change miscellaneous file attributes
- * @idmap:	idmap of the mount
- * @dentry:	the object to change
- * @fa:		fileattr pointer
- *
- * After verifying permissions, call i_op->fileattr_set() callback, if
- * exists.
- *
- * Verifying attributes involves retrieving current attributes with
- * i_op->fileattr_get(), this also allows initializing attributes that have
- * not been set by the caller to current values.  Inode lock is held
- * thoughout to prevent racing with another instance.
- *
- * Return: 0 on success, or a negative error on failure.
- */
-int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
-		     struct file_kattr *fa)
+static int do_vfs_fileattr_set(const struct path *const path,
+			       const struct mnt_idmap *const idmap,
+			       struct file_kattr *const fa,
+			       struct file *const file)
 {
+	struct dentry *const dentry = path->dentry;
 	struct inode *inode = d_inode(dentry);
 	struct file_kattr old_ma = {};
 	int err;
@@ -284,7 +309,7 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
 		return -EPERM;
 
 	inode_lock(inode);
-	err = vfs_fileattr_get(dentry, &old_ma);
+	err = __vfs_fileattr_get(dentry, &old_ma);
 	if (!err) {
 		/* initialize missing bits from old_ma */
 		if (fa->flags_valid) {
@@ -300,7 +325,7 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
 		err = fileattr_set_prepare(inode, &old_ma, fa);
 		if (err)
 			goto out;
-		err = security_inode_file_setattr(dentry, fa);
+		err = security_inode_file_setattr(path, fa, file);
 		if (err)
 			goto out;
 		err = inode->i_op->fileattr_set(idmap, dentry, fa);
@@ -313,6 +338,24 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
 	inode_unlock(inode);
 	return err;
 }
+
+/**
+ * vfs_fileattr_set - change miscellaneous file attributes
+ * @idmap:	idmap of the mount
+ * @path:	the object to change
+ * @fa:		fileattr pointer
+ * @file:	file through which the attributes are set, if any
+ *
+ * After verifying permissions, call i_op->fileattr_set() callback, if
+ * exists.
+ *
+ * Return: 0 on success, or a negative error on failure.
+ */
+int vfs_fileattr_set(const struct mnt_idmap *idmap, const struct path *path,
+		     struct file_kattr *fa, struct file *file)
+{
+	return do_vfs_fileattr_set(path, idmap, fa, file);
+}
 EXPORT_SYMBOL(vfs_fileattr_set);
 
 int ioctl_getflags(struct file *file, unsigned int __user *argp)
@@ -320,7 +363,7 @@ int ioctl_getflags(struct file *file, unsigned int __user *argp)
 	struct file_kattr fa = { .flags_valid = true }; /* hint only */
 	int err;
 
-	err = vfs_fileattr_get(file->f_path.dentry, &fa);
+	err = vfs_fileattr_get(&file->f_path, &fa, file);
 	if (!err)
 		err = put_user(fa.flags, argp);
 	return err;
@@ -329,7 +372,6 @@ int ioctl_getflags(struct file *file, unsigned int __user *argp)
 int ioctl_setflags(struct file *file, unsigned int __user *argp)
 {
 	const struct mnt_idmap *idmap = file_mnt_idmap(file);
-	struct dentry *dentry = file->f_path.dentry;
 	struct file_kattr fa = {};
 	unsigned int flags;
 	int err;
@@ -339,7 +381,7 @@ int ioctl_setflags(struct file *file, unsigned int __user *argp)
 		err = mnt_want_write_file(file);
 		if (!err) {
 			fileattr_fill_flags(&fa, flags);
-			err = vfs_fileattr_set(idmap, dentry, &fa);
+			err = vfs_fileattr_set(idmap, &file->f_path, &fa, file);
 			mnt_drop_write_file(file);
 		}
 	}
@@ -351,7 +393,7 @@ int ioctl_fsgetxattr(struct file *file, void __user *argp)
 	struct file_kattr fa = { .fsx_valid = true }; /* hint only */
 	int err;
 
-	err = vfs_fileattr_get(file->f_path.dentry, &fa);
+	err = vfs_fileattr_get(&file->f_path, &fa, file);
 	if (!err)
 		err = copy_fsxattr_to_user(&fa, argp);
 
@@ -361,7 +403,6 @@ int ioctl_fsgetxattr(struct file *file, void __user *argp)
 int ioctl_fssetxattr(struct file *file, void __user *argp)
 {
 	const struct mnt_idmap *idmap = file_mnt_idmap(file);
-	struct dentry *dentry = file->f_path.dentry;
 	struct file_kattr fa = {};
 	int err;
 
@@ -369,7 +410,7 @@ int ioctl_fssetxattr(struct file *file, void __user *argp)
 	if (!err) {
 		err = mnt_want_write_file(file);
 		if (!err) {
-			err = vfs_fileattr_set(idmap, dentry, &fa);
+			err = vfs_fileattr_set(idmap, &file->f_path, &fa, file);
 			mnt_drop_write_file(file);
 		}
 	}
@@ -407,16 +448,16 @@ SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename,
 		if (fd_empty(f))
 			return -EBADF;
 
-		filepath = fd_file(f)->f_path;
-		path_get(&filepath);
+		error = vfs_fileattr_get(&fd_file(f)->f_path, &fa,
+					 fd_file(f));
 	} else {
 		error = filename_lookup(dfd, name, lookup_flags, &filepath,
 					NULL);
 		if (error)
 			return error;
-	}
 
-	error = vfs_fileattr_get(filepath.dentry, &fa);
+		error = vfs_fileattr_get(&filepath, &fa, NULL);
+	}
 	if (error == -ENOIOCTLCMD || error == -ENOTTY)
 		error = -EOPNOTSUPP;
 	if (error)
@@ -469,23 +510,28 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename,
 		if (fd_empty(f))
 			return -EBADF;
 
-		filepath = fd_file(f)->f_path;
-		path_get(&filepath);
+		error = mnt_want_write_file(fd_file(f));
+		if (!error) {
+			error = vfs_fileattr_set(file_mnt_idmap(fd_file(f)),
+						 &fd_file(f)->f_path, &fa,
+						 fd_file(f));
+			mnt_drop_write_file(fd_file(f));
+		}
 	} else {
 		error = filename_lookup(dfd, name, lookup_flags, &filepath,
 					NULL);
 		if (error)
 			return error;
-	}
 
-	error = mnt_want_write(filepath.mnt);
-	if (!error) {
-		error = vfs_fileattr_set(mnt_idmap(filepath.mnt),
-					 filepath.dentry, &fa);
-		if (error == -ENOIOCTLCMD || error == -ENOTTY)
-			error = -EOPNOTSUPP;
-		mnt_drop_write(filepath.mnt);
+		error = mnt_want_write(filepath.mnt);
+		if (!error) {
+			error = vfs_fileattr_set(mnt_idmap(filepath.mnt),
+						 &filepath, &fa, NULL);
+			mnt_drop_write(filepath.mnt);
+		}
 	}
+	if (error == -ENOIOCTLCMD || error == -ENOTTY)
+		error = -EOPNOTSUPP;
 
 	return error;
 }
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 382bb24ddc9e..371c3d716112 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -3011,7 +3011,7 @@ nfsd_get_case_info(struct dentry *dentry, bool *case_insensitive,
 	}
 	saved = override_creds(probe);
 
-	err = vfs_fileattr_get(cd, &fa);
+	err = __vfs_fileattr_get(cd, &fa);
 
 	put_cred(revert_creds(saved));
 out:
diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index 1700cc74ef01..2f480ab05c88 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -609,12 +609,12 @@ static int ovl_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 }
 
 /*
- * Work around the fact that security_file_ioctl() takes a file argument.
- * Introducing security_inode_fileattr_get/set() hooks would solve this issue
- * properly.
+ * The inode hooks only see the layer inode, while the operation was
+ * requested through an ioctl on the overlay file.  Run the file-based
+ * checks that an ioctl on the real file would have carried.
  */
-static int ovl_security_fileattr(const struct path *realpath, struct file_kattr *fa,
-				 bool set)
+static int ovl_security_fileattr(const struct path *realpath,
+				 struct file_kattr *fa, bool set)
 {
 	struct file *file;
 	unsigned int cmd;
@@ -648,7 +648,13 @@ int ovl_real_fileattr_set(const struct path *realpath, struct file_kattr *fa)
 	if (err)
 		return err;
 
-	return vfs_fileattr_set(mnt_idmap(realpath->mnt), realpath->dentry, fa);
+	/*
+	 * Run the security hook on the underlying path as well: the
+	 * lower/upper layer can carry a different security label than the
+	 * overlay inode, and the copy-up caller does not go through the
+	 * overlay path at all.
+	 */
+	return vfs_fileattr_set(mnt_idmap(realpath->mnt), realpath, fa, NULL);
 }
 
 int ovl_fileattr_set(const struct mnt_idmap *idmap,
@@ -730,7 +736,7 @@ int ovl_real_fileattr_get(const struct path *realpath, struct file_kattr *fa)
 	if (err)
 		return err;
 
-	err = vfs_fileattr_get(realpath->dentry, fa);
+	err = vfs_fileattr_get(realpath, fa, NULL);
 	if (err == -ENOIOCTLCMD)
 		err = -ENOTTY;
 	return err;
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index a36ad354b37b..9ba1ae94b283 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -3840,7 +3840,7 @@ static bool smb2_parent_compressed(struct ksmbd_tree_connect *tcon,
 	bool compressed = false;
 	int rc;
 
-	rc = vfs_fileattr_get(parent, &fa);
+	rc = vfs_fileattr_get(&parent_path, &fa, NULL);
 	if (!rc && fa.flags & FS_COMPR_FL) {
 		compressed = true;
 		goto out;
@@ -5505,7 +5505,7 @@ int smb2_open(struct ksmbd_work *work)
 		smb2_new_xattrs(tcon, &path, fp);
 	}
 
-	ksmbd_vfs_update_compressed_fattr(path.dentry, &fp->f_ci->m_fattr);
+	ksmbd_vfs_update_compressed_fattr(&path, fp->filp, &fp->f_ci->m_fattr);
 
 	if (created) {
 		if (fp->coption & FILE_NO_COMPRESSION_LE) {
@@ -8227,7 +8227,7 @@ static int smb2_get_info_filesystem(struct ksmbd_work *work,
 			FILE_SUPPORTS_SPARSE_FILES |
 			FILE_SUPPORTS_BLOCK_REFCOUNTING;
 
-		err = vfs_fileattr_get(path.dentry, &fa);
+		err = vfs_fileattr_get(&path, &fa, NULL);
 		/*
 		 * -EINVAL, -EOPNOTSUPP: ntfs-3g and other FUSE
 		 * filesystems that lack FS_IOC_FSGETXATTR support.
diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
index efb66a914a8e..c7052cd96d0c 100644
--- a/fs/smb/server/vfs.c
+++ b/fs/smb/server/vfs.c
@@ -2390,12 +2390,13 @@ int ksmbd_vfs_inherit_posix_acl(const struct mnt_idmap *idmap,
 	return 0;
 }
 
-void ksmbd_vfs_update_compressed_fattr(struct dentry *dentry, __le32 *fattr)
+void ksmbd_vfs_update_compressed_fattr(const struct path *path,
+				       struct file *file, __le32 *fattr)
 {
 	int rc;
 	struct file_kattr fa = { .flags_valid = true };
 
-	rc = vfs_fileattr_get(dentry, &fa);
+	rc = vfs_fileattr_get(path, &fa, file);
 	if (rc)
 		return;
 
@@ -2408,7 +2409,7 @@ int ksmbd_vfs_get_compression(struct ksmbd_file *fp, u16 *fmt)
 	struct file_kattr fa = { .flags_valid = true };
 	int rc;
 
-	rc = vfs_fileattr_get(fp->filp->f_path.dentry, &fa);
+	rc = vfs_fileattr_get(&fp->filp->f_path, &fa, fp->filp);
 	if (rc == -ENOIOCTLCMD || rc == -ENOTTY || rc == -EINVAL ||
 	    rc == -EOPNOTSUPP) {
 		if (fp->f_ci->m_fattr & FILE_ATTRIBUTE_COMPRESSED_LE)
@@ -2435,9 +2436,8 @@ static int __ksmbd_vfs_set_compression(struct ksmbd_work *work,
 				       bool check_access)
 {
 	const struct cred *saved_cred = NULL;
-	struct file_kattr fa;
-	struct dentry *dentry = fp->filp->f_path.dentry;
 	const struct mnt_idmap *idmap = file_mnt_idmap(fp->filp);
+	struct file_kattr fa;
 	u32 flags;
 	__le32 old_fattr;
 	int rc;
@@ -2455,7 +2455,7 @@ static int __ksmbd_vfs_set_compression(struct ksmbd_work *work,
 	}
 
 	saved_cred = override_creds(fp->filp->f_cred);
-	rc = vfs_fileattr_get(dentry, &fa);
+	rc = vfs_fileattr_get(&fp->filp->f_path, &fa, fp->filp);
 	if (rc == -ENOIOCTLCMD || rc == -ENOTTY || rc == -EINVAL ||
 	    rc == -EOPNOTSUPP)
 		goto update_fattr;
@@ -2476,7 +2476,8 @@ static int __ksmbd_vfs_set_compression(struct ksmbd_work *work,
 		if (rc)
 			goto out;
 
-		rc = vfs_fileattr_set(idmap, dentry, &fa);
+		rc = vfs_fileattr_set(idmap, &fp->filp->f_path, &fa,
+				      fp->filp);
 		mnt_drop_write_file(fp->filp);
 		if (rc == -ENOIOCTLCMD || rc == -ENOTTY || rc == -EINVAL ||
 		    rc == -EOPNOTSUPP)
diff --git a/fs/smb/server/vfs.h b/fs/smb/server/vfs.h
index c1ea94cf153f..257975036b94 100644
--- a/fs/smb/server/vfs.h
+++ b/fs/smb/server/vfs.h
@@ -182,7 +182,8 @@ int ksmbd_vfs_set_init_posix_acl(const struct mnt_idmap *idmap,
 int ksmbd_vfs_inherit_posix_acl(const struct mnt_idmap *idmap,
 				const struct path *path,
 				struct inode *parent_inode);
-void ksmbd_vfs_update_compressed_fattr(struct dentry *dentry, __le32 *fattr);
+void ksmbd_vfs_update_compressed_fattr(const struct path *path,
+				       struct file *file, __le32 *fattr);
 int ksmbd_vfs_get_compression(struct ksmbd_file *fp, u16 *fmt);
 int ksmbd_vfs_set_compression(struct ksmbd_work *work, struct ksmbd_file *fp, u16 fmt);
 int ksmbd_vfs_set_compression_create(struct ksmbd_work *work,
diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
index 09e32b84e02a..e16dcee8e8fd 100644
--- a/include/linux/fileattr.h
+++ b/include/linux/fileattr.h
@@ -3,6 +3,8 @@
 #ifndef _LINUX_FILEATTR_H
 #define _LINUX_FILEATTR_H
 
+struct path;
+
 /* Flags shared betwen flags/xflags */
 #define FS_COMMON_FL \
 	(FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \
@@ -73,9 +75,11 @@ static inline bool fileattr_has_fsx(const struct file_kattr *fa)
 		 fa->fsx_projid != 0 ||	fa->fsx_cowextsize != 0);
 }
 
-int vfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
-int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
-		     struct file_kattr *fa);
+int __vfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
+int vfs_fileattr_get(const struct path *path, struct file_kattr *fa,
+		     struct file *file);
+int vfs_fileattr_set(const struct mnt_idmap *idmap, const struct path *path,
+		     struct file_kattr *fa, struct file *file);
 int ioctl_getflags(struct file *file, unsigned int __user *argp);
 int ioctl_setflags(struct file *file, unsigned int __user *argp);
 int ioctl_fsgetxattr(struct file *file, void __user *argp);
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index 229eaee0a0dd..81a304ce87a3 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -166,8 +166,10 @@ LSM_HOOK(int, 0, inode_removexattr, const struct mnt_idmap *idmap,
 	 const struct path *path, const char *name, struct file *file)
 LSM_HOOK(void, LSM_RET_VOID, inode_post_removexattr, struct dentry *dentry,
 	 const char *name)
-LSM_HOOK(int, 0, inode_file_setattr, struct dentry *dentry, struct file_kattr *fa)
-LSM_HOOK(int, 0, inode_file_getattr, struct dentry *dentry, struct file_kattr *fa)
+LSM_HOOK(int, 0, inode_file_setattr, const struct path *path,
+	 struct file_kattr *fa, struct file *file)
+LSM_HOOK(int, 0, inode_file_getattr, const struct path *path,
+	 struct file_kattr *fa, struct file *file)
 LSM_HOOK(int, 0, inode_set_acl, const struct mnt_idmap *idmap,
 	 const struct path *path, const char *acl_name,
 	 struct posix_acl *kacl, struct file *file)
diff --git a/include/linux/security.h b/include/linux/security.h
index cbd50cd38255..3c52a5d2c708 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -463,10 +463,10 @@ int security_inode_removexattr(const struct mnt_idmap *idmap,
 			       const struct path *path, const char *name,
 			       struct file *file);
 void security_inode_post_removexattr(struct dentry *dentry, const char *name);
-int security_inode_file_setattr(struct dentry *dentry,
-			      struct file_kattr *fa);
-int security_inode_file_getattr(struct dentry *dentry,
-			      struct file_kattr *fa);
+int security_inode_file_setattr(const struct path *path,
+				struct file_kattr *fa, struct file *file);
+int security_inode_file_getattr(const struct path *path,
+				struct file_kattr *fa, struct file *file);
 int security_inode_need_killpriv(struct dentry *dentry);
 int security_inode_killpriv(const struct mnt_idmap *idmap, struct dentry *dentry);
 int security_inode_getsecurity(const struct mnt_idmap *idmap,
@@ -1090,14 +1090,16 @@ static inline void security_inode_post_removexattr(struct dentry *dentry,
 						   const char *name)
 { }
 
-static inline int security_inode_file_setattr(struct dentry *dentry,
-					      struct file_kattr *fa)
+static inline int security_inode_file_setattr(const struct path *path,
+					      struct file_kattr *fa,
+					      struct file *file)
 {
 	return 0;
 }
 
-static inline int security_inode_file_getattr(struct dentry *dentry,
-					      struct file_kattr *fa)
+static inline int security_inode_file_getattr(const struct path *path,
+					      struct file_kattr *fa,
+					      struct file *file)
 {
 	return 0;
 }
diff --git a/kernel/bpf/bpf_lsm_proto.c b/kernel/bpf/bpf_lsm_proto.c
index 4454c1fdbe6b..814a30a7959e 100644
--- a/kernel/bpf/bpf_lsm_proto.c
+++ b/kernel/bpf/bpf_lsm_proto.c
@@ -94,3 +94,22 @@ noinline int bpf_lsm_inode_remove_acl(const struct mnt_idmap *idmap,
 {
 	return 0;
 }
+
+/*
+ * Strong definitions of the inode fileattr BPF LSM hooks.  The file argument
+ * is only set for file descriptor-based operations and is NULL for path-based
+ * and in-kernel callers, so mark it as PTR_MAYBE_NULL.
+ */
+noinline int bpf_lsm_inode_file_setattr(const struct path *path,
+					struct file_kattr *fa,
+					struct file *file__nullable)
+{
+	return 0;
+}
+
+noinline int bpf_lsm_inode_file_getattr(const struct path *path,
+					struct file_kattr *fa,
+					struct file *file__nullable)
+{
+	return 0;
+}
diff --git a/security/security.c b/security/security.c
index b62a6e63dea1..6d2bdfaf234d 100644
--- a/security/security.c
+++ b/security/security.c
@@ -2184,32 +2184,38 @@ void security_inode_post_removexattr(struct dentry *dentry, const char *name)
 
 /**
  * security_inode_file_setattr() - check if setting fsxattr is allowed
- * @dentry: file to set filesystem extended attributes on
+ * @path: file to set filesystem extended attributes on (the VFS makes no
+ *        guarantees with regard to @path->mnt)
  * @fa: extended attributes to set on the inode
+ * @file: file through which the file attributes are set, if any
  *
  * Called when file_setattr() syscall or FS_IOC_FSSETXATTR ioctl() is called on
  * inode
  *
  * Return: Returns 0 if permission is granted.
  */
-int security_inode_file_setattr(struct dentry *dentry, struct file_kattr *fa)
+int security_inode_file_setattr(const struct path *path,
+				struct file_kattr *fa, struct file *file)
 {
-	return call_int_hook(inode_file_setattr, dentry, fa);
+	return call_int_hook(inode_file_setattr, path, fa, file);
 }
 
 /**
  * security_inode_file_getattr() - check if retrieving fsxattr is allowed
- * @dentry: file to retrieve filesystem extended attributes from
+ * @path: file to retrieve filesystem extended attributes from (the VFS makes no
+ *        guarantees with regard to @path->mnt)
  * @fa: extended attributes to get
+ * @file: file through which the file attributes are retrieved, if any
  *
  * Called when file_getattr() syscall or FS_IOC_FSGETXATTR ioctl() is called on
  * inode
  *
  * Return: Returns 0 if permission is granted.
  */
-int security_inode_file_getattr(struct dentry *dentry, struct file_kattr *fa)
+int security_inode_file_getattr(const struct path *path,
+				struct file_kattr *fa, struct file *file)
 {
-	return call_int_hook(inode_file_getattr, dentry, fa);
+	return call_int_hook(inode_file_getattr, path, fa, file);
 }
 
 /**
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index bd7ae5433575..85b18c155a17 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3569,16 +3569,18 @@ static int selinux_inode_removexattr(const struct mnt_idmap *idmap,
 	return -EACCES;
 }
 
-static int selinux_inode_file_setattr(struct dentry *dentry,
-				      struct file_kattr *fa)
+static int selinux_inode_file_setattr(const struct path *path,
+				      struct file_kattr *fa,
+				      struct file *file)
 {
-	return dentry_has_perm(current_cred(), dentry, FILE__SETATTR);
+	return dentry_has_perm(current_cred(), path->dentry, FILE__SETATTR);
 }
 
-static int selinux_inode_file_getattr(struct dentry *dentry,
-				      struct file_kattr *fa)
+static int selinux_inode_file_getattr(const struct path *path,
+				      struct file_kattr *fa,
+				      struct file *file)
 {
-	return dentry_has_perm(current_cred(), dentry, FILE__GETATTR);
+	return dentry_has_perm(current_cred(), path->dentry, FILE__GETATTR);
 }
 
 static int selinux_path_notify(const struct path *path, u64 mask,
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 08/17] LSM: rename inode_setattr to path_setattr and pass struct path and file
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
                   ` (6 preceding siblings ...)
  2026-11-17 15:05 ` [PATCH -next -v4 07/17] LSM: pass struct path and struct file to the inode fileattr hooks Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 15:11   ` sashiko-bot
  2026-11-17 15:05 ` [PATCH -next -v4 09/17] LSM: rename inode_getattr to path_getattr and pass struct file Cai Xinchen
                   ` (8 subsequent siblings)
  16 siblings, 1 reply; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

The inode_setattr hook is called from notify_change(), which now holds a
struct path and a struct file.  Pass both, next to the target dentry and
the idmap: path-based checks must use the caller-supplied path, while
inode-based checks must authorize the target dentry, which can differ
when a filesystem forwards a change (NTFS named streams).

Rename the hook and security_inode_setattr() to path_setattr to follow
the path_* convention.  The rename cannot be deferred: BPF LSM programs
are not verified against the argument list, and the attr argument moves
from ctx slot 2 to slot 3 while slot 2 becomes a dentry whose d_flags is
a u32 at offset 0, so a program reading iattr->ia_valid would silently
read DCACHE_OP_HASH instead of failing to load.

do_fchmodat(), do_fchownat() and do_utimes_path() now dispatch an empty
path with AT_EMPTY_PATH to the file descriptor-based helpers, following
the vfs_fstatat() pattern, so that AT_EMPTY_PATH keeps accepting O_PATH
descriptors; vfs_utimes() audits the request once when it is given a
file.

Also make the new arguments usable from BPF: mark path->dentry trusted in
the verifier, name the file argument file__nullable in the strong stub,
and add the already-locked sleepable path hooks to d_inode_locked_hooks.
path_link, path_rename, path_rmdir and path_unlink stay out of it, as
their path and dentry arguments name different inodes.

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 Documentation/filesystems/porting.rst | 11 ++++-
 drivers/base/devtmpfs.c               |  4 +-
 fs/attr.c                             | 28 +++++++-----
 fs/bpf_fs_kfuncs.c                    | 54 +++++++++++++++++++++-
 fs/btrfs/volumes.c                    |  2 +-
 fs/ecryptfs/inode.c                   |  4 +-
 fs/exfat/file.c                       |  5 ++-
 fs/fat/file.c                         |  5 ++-
 fs/init.c                             |  6 +--
 fs/inode.c                            |  2 +-
 fs/internal.h                         |  6 ++-
 fs/nfsd/nfs4state.c                   |  4 +-
 fs/nfsd/vfs.c                         |  4 +-
 fs/ntfs/named_stream.c                |  3 +-
 fs/open.c                             | 64 ++++++++++++++++++++++-----
 fs/overlayfs/overlayfs.h              |  2 +-
 fs/smb/server/smb2pdu.c               |  2 +-
 fs/smb/server/smbacl.c                |  2 +-
 fs/utimes.c                           | 36 ++++++++++++---
 include/linux/fs.h                    |  9 ++--
 include/linux/lsm_hook_defs.h         | 17 ++++++-
 include/linux/security.h              | 13 +++---
 init/initramfs.c                      |  2 +-
 kernel/bpf/bpf_lsm.c                  |  2 +-
 kernel/bpf/bpf_lsm_proto.c            | 16 +++++++
 kernel/bpf/verifier.c                 | 13 ++++++
 security/integrity/evm/evm_main.c     | 13 +++---
 security/security.c                   | 16 ++++---
 security/selinux/hooks.c              |  8 ++--
 security/smack/smack_lsm.c            | 14 +++---
 30 files changed, 283 insertions(+), 84 deletions(-)

diff --git a/Documentation/filesystems/porting.rst b/Documentation/filesystems/porting.rst
index f3feb27e898c..396e23af4c1f 100644
--- a/Documentation/filesystems/porting.rst
+++ b/Documentation/filesystems/porting.rst
@@ -1446,7 +1446,16 @@ dentry must provide a struct path.  struct iattr has a new ia_path member,
 which notify_change() sets for the duration of the call; it must not be
 stored beyond that.  Filesystems that forward a change to another inode
 can use notify_change_target() to update the target dentry while keeping
-the caller-supplied path in ia_path.
+the caller-supplied path in ia_path; path-based LSM checks are performed
+on that path, and the setattr LSM hook receives both it and the target
+dentry, so inode-based LSMs keep authorizing the inode that is actually
+changed.  notify_change() also takes the struct file through which the
+change was requested, if any.  vfs_utimes() takes the same trailing struct
+file argument.  The inode_setattr LSM hook is renamed to
+path_setattr and now receives the struct path and the target dentry
+before struct iattr, plus a trailing struct file (NULL for path-based
+and kernel-internal callers); the security_inode_setattr() wrapper is
+renamed to security_path_setattr() accordingly.
 
 ---
 
diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
index 410906a66ee9..00f2e3e7e27e 100644
--- a/drivers/base/devtmpfs.c
+++ b/drivers/base/devtmpfs.c
@@ -291,7 +291,7 @@ static int handle_create(const char *nodename, umode_t mode, kuid_t uid,
 		newattrs.ia_gid = gid;
 		newattrs.ia_valid = ATTR_MODE|ATTR_UID|ATTR_GID;
 		inode_lock(d_inode(dentry));
-		notify_change(&nop_mnt_idmap, &attr_path, &newattrs, NULL);
+		notify_change(&nop_mnt_idmap, &attr_path, &newattrs, NULL, NULL);
 		inode_unlock(d_inode(dentry));
 
 		/* mark as kernel-created inode */
@@ -392,7 +392,7 @@ static int handle_remove(const char *nodename, struct device *dev)
 		newattrs.ia_valid =
 			ATTR_UID|ATTR_GID|ATTR_MODE;
 		inode_lock(d_inode(dentry));
-		notify_change(&nop_mnt_idmap, &attr_path, &newattrs, NULL);
+		notify_change(&nop_mnt_idmap, &attr_path, &newattrs, NULL, NULL);
 		inode_unlock(d_inode(dentry));
 		err = vfs_unlink(&nop_mnt_idmap, d_inode(parent.dentry),
 				 dentry, NULL);
diff --git a/fs/attr.c b/fs/attr.c
index f8fd0f061612..8d2495728b1b 100644
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -401,7 +401,8 @@ static int do_notify_change(const struct path *const path,
 			    const struct mnt_idmap *const idmap,
 			    struct dentry *const dentry,
 			    struct iattr *attr,
-			    struct delegated_inode *delegated_inode)
+			    struct delegated_inode *delegated_inode,
+			    struct file *const file)
 {
 	struct inode *inode = dentry->d_inode;
 	umode_t mode = inode->i_mode;
@@ -513,7 +514,7 @@ static int do_notify_change(const struct path *const path,
 	    !vfsgid_valid(i_gid_into_vfsgid(idmap, inode)))
 		return -EOVERFLOW;
 
-	error = security_inode_setattr(idmap, dentry, attr);
+	error = security_path_setattr(idmap, path, dentry, attr, file);
 	if (error)
 		return error;
 
@@ -557,6 +558,7 @@ static int do_notify_change(const struct path *const path,
  * @path:	object affected
  * @attr:	new attributes
  * @delegated_inode: returns inode, if the inode is delegated
+ * @file:	file through which the attribute change is requested, if any
  *
  * The caller must hold the i_rwsem exclusively on the affected object.
  *
@@ -581,10 +583,11 @@ static int do_notify_change(const struct path *const path,
  * Return: 0 on success, or a negative error on failure.
  */
 int notify_change(const struct mnt_idmap *idmap, const struct path *path,
-		  struct iattr *attr, struct delegated_inode *delegated_inode)
+		  struct iattr *attr, struct delegated_inode *delegated_inode,
+		  struct file *file)
 {
 	return do_notify_change(path, idmap, path->dentry, attr,
-				delegated_inode);
+				delegated_inode, file);
 }
 EXPORT_SYMBOL(notify_change);
 
@@ -595,24 +598,29 @@ EXPORT_SYMBOL(notify_change);
  * @target: dentry of the inode whose attributes are changed
  * @attr: attributes to change
  * @delegated_inode: returns inode needing a delegation break
+ * @file: file through which the change was requested, if any
  *
  * This is for filesystems that apply a metadata change to an inode other
  * than the one the caller named (e.g. NTFS named streams).  The path the
  * change was requested through is recorded in @attr->ia_path so that the
- * caller can pass it back when it forwards the change; @target supplies
- * the inode to update.  @target must be the inode of the same file as
- * @path, e.g. the base inode of a named stream.  The caller must hold the
- * i_rwsem exclusively on @target.
+ * caller can pass it back when it forwards the change; path-based LSM
+ * checks are then performed on @path, while inode-based LSM checks and the
+ * update itself use @target.  @target must be the inode of the same file
+ * as @path, e.g. the base inode of a named stream.  The caller must hold
+ * the i_rwsem exclusively on @target, and on @path->dentry->d_inode, which
+ * ->setattr already holds: the LSM hook is called with both inodes locked.
  *
  * Return: 0 on success, or a negative error on failure.
  */
 int notify_change_target(const struct mnt_idmap *idmap,
 			 const struct path *path, struct dentry *target,
 			 struct iattr *attr,
-			 struct delegated_inode *delegated_inode)
+			 struct delegated_inode *delegated_inode,
+			 struct file *file)
 {
 	if (WARN_ON_ONCE(!target))
 		return -EINVAL;
-	return do_notify_change(path, idmap, target, attr, delegated_inode);
+	return do_notify_change(path, idmap, target, attr, delegated_inode,
+				file);
 }
 EXPORT_SYMBOL_GPL(notify_change_target);
diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c
index 35ccd98a4de6..a28a6eaaa145 100644
--- a/fs/bpf_fs_kfuncs.c
+++ b/fs/bpf_fs_kfuncs.c
@@ -527,6 +527,34 @@ BTF_SET_START(bpf_inode_init_xattr_hooks)
 BTF_ID(func, bpf_lsm_inode_init_security)
 BTF_SET_END(bpf_inode_init_xattr_hooks)
 
+/*
+ * Hooks that expose two dentries, only one of which is locked: the path
+ * argument names the parent directory, which the caller already write-locked,
+ * while the dentry argument is the victim, whose inode is only locked later
+ * by vfs_link(), vfs_rename(), vfs_rmdir() or vfs_unlink().
+ *
+ * The dentry xattr kfuncs cannot pick a correct variant for such a hook, and
+ * the verifier cannot tell which dentry a program passes: the locking variant
+ * would update the victim without i_rwsem, and the non-locking one would
+ * deadlock on the parent.  Reject both kfuncs for these hooks.
+ *
+ * inode_getattr() is also reached both with and without i_rwsem: path-based
+ * callers such as stat(2) hold no lock, while nfsd fills the pre-operation
+ * attributes from nfsd_setattr() with the inode already write-locked.
+ */
+BTF_ID_LIST_SINGLE(bpf_set_dentry_xattr_ids, func, bpf_set_dentry_xattr)
+BTF_ID_LIST_SINGLE(bpf_remove_dentry_xattr_ids, func, bpf_remove_dentry_xattr)
+
+BTF_SET_START(d_inode_ambiguous_hooks)
+BTF_ID(func, bpf_lsm_inode_getattr)
+#ifdef CONFIG_SECURITY_PATH
+BTF_ID(func, bpf_lsm_path_link)
+BTF_ID(func, bpf_lsm_path_rename)
+BTF_ID(func, bpf_lsm_path_rmdir)
+BTF_ID(func, bpf_lsm_path_unlink)
+#endif /* CONFIG_SECURITY_PATH */
+BTF_SET_END(d_inode_ambiguous_hooks)
+
 static int bpf_fs_kfuncs_filter(const struct bpf_prog *prog, u32 kfunc_id)
 {
 	if (!btf_id_set8_contains(&bpf_fs_kfunc_set_ids, kfunc_id))
@@ -539,8 +567,14 @@ static int bpf_fs_kfuncs_filter(const struct bpf_prog *prog, u32 kfunc_id)
 			return -EACCES;
 		return 0;
 	}
-	if (prog->type == BPF_PROG_TYPE_LSM)
+	if (prog->type == BPF_PROG_TYPE_LSM) {
+		if ((kfunc_id == bpf_set_dentry_xattr_ids[0] ||
+		     kfunc_id == bpf_remove_dentry_xattr_ids[0]) &&
+		    btf_id_set_contains(&d_inode_ambiguous_hooks,
+					prog->aux->attach_btf_id))
+			return -EACCES;
 		return 0;
+	}
 	if (prog->type != BPF_PROG_TYPE_STRUCT_OPS)
 		return -EACCES;
 	/* ->st_ops is unset during the cfg pass; enforced once it is set. */
@@ -568,9 +602,25 @@ BTF_ID(func, bpf_lsm_inode_post_setattr)
 BTF_ID(func, bpf_lsm_inode_post_setxattr)
 BTF_ID(func, bpf_lsm_inode_removexattr)
 BTF_ID(func, bpf_lsm_inode_rmdir)
-BTF_ID(func, bpf_lsm_inode_setattr)
+BTF_ID(func, bpf_lsm_path_setattr)
 BTF_ID(func, bpf_lsm_inode_setxattr)
 BTF_ID(func, bpf_lsm_inode_unlink)
+/*
+ * Path hooks whose path argument is already locked by the caller.  They can
+ * run sleepable programs (see sleepable_lsm_hooks), so the dentry xattr
+ * kfuncs must use their _locked variants there.
+ *
+ * path_link, path_rename, path_rmdir and path_unlink hand over both a locked
+ * parent (the path) and an unlocked victim (the dentry), so the dentry xattr
+ * kfuncs are rejected for programs attached to them (see
+ * d_inode_ambiguous_hooks).
+ */
+#ifdef CONFIG_SECURITY_PATH
+BTF_ID(func, bpf_lsm_path_chmod)
+BTF_ID(func, bpf_lsm_path_chown)
+BTF_ID(func, bpf_lsm_path_mkdir)
+BTF_ID(func, bpf_lsm_path_symlink)
+#endif /* CONFIG_SECURITY_PATH */
 BTF_SET_END(d_inode_locked_hooks)
 
 bool bpf_lsm_has_d_inode_locked(const struct bpf_prog *prog)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 3d4ef6725de0..a230f7c43c06 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2152,7 +2152,7 @@ static void update_dev_time(const char *device_path)
 	}
 
 	if (!err) {
-		vfs_utimes(&path, NULL);
+		vfs_utimes(&path, NULL, NULL);
 		path_put(&path);
 	}
 }
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index 566fbcbbf7df..0f029435c6a6 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -822,7 +822,7 @@ static int __ecryptfs_truncate(struct dentry *dentry, const struct iattr *ia)
 set_size:
 	lower_ia.ia_valid |= ATTR_SIZE;
 	inode_lock(d_inode(lower_dentry));
-	rc = notify_change(&nop_mnt_idmap, &lower_path, &lower_ia, NULL);
+	rc = notify_change(&nop_mnt_idmap, &lower_path, &lower_ia, NULL, NULL);
 	inode_unlock(d_inode(lower_dentry));
 out:
 	ecryptfs_put_lower_file(inode);
@@ -932,7 +932,7 @@ static int ecryptfs_setattr(const struct mnt_idmap *idmap,
 
 		inode_lock(d_inode(lower_path.dentry));
 		rc = notify_change(&nop_mnt_idmap, &lower_path, &lower_ia,
-				   NULL);
+				   NULL, NULL);
 		inode_unlock(d_inode(lower_path.dentry));
 	}
 out:
diff --git a/fs/exfat/file.c b/fs/exfat/file.c
index 18ac88c979fc..ddf5c47176bd 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -551,8 +551,9 @@ static int exfat_ioctl_set_attributes(struct file *file, u32 __user *user_attr)
 	 * out the RO attribute for checking by the security
 	 * module, just because it maps to a file mode.
 	 */
-	err = security_inode_setattr(file_mnt_idmap(file),
-				     file->f_path.dentry, &ia);
+	err = security_path_setattr(file_mnt_idmap(file),
+				    &file->f_path, file->f_path.dentry,
+				    &ia, file);
 	if (err)
 		goto out_unlock_inode;
 
diff --git a/fs/fat/file.c b/fs/fat/file.c
index 70583e791bdc..4ca635cd2bd4 100644
--- a/fs/fat/file.c
+++ b/fs/fat/file.c
@@ -92,8 +92,9 @@ static int fat_ioctl_set_attributes(struct file *file, u32 __user *user_attr)
 	 * out the RO attribute for checking by the security
 	 * module, just because it maps to a file mode.
 	 */
-	err = security_inode_setattr(file_mnt_idmap(file),
-				     file->f_path.dentry, &ia);
+	err = security_path_setattr(file_mnt_idmap(file),
+				    &file->f_path, file->f_path.dentry,
+				    &ia, file);
 	if (err)
 		goto out_unlock_inode;
 
diff --git a/fs/init.c b/fs/init.c
index 33e312d74f58..b65e47e59ee0 100644
--- a/fs/init.c
+++ b/fs/init.c
@@ -107,7 +107,7 @@ int __init init_chown(const char *filename, uid_t user, gid_t group, int flags)
 		return error;
 	error = mnt_want_write(path.mnt);
 	if (!error) {
-		error = chown_common(&path, user, group);
+		error = chown_common(&path, user, group, NULL);
 		mnt_drop_write(path.mnt);
 	}
 	path_put(&path);
@@ -122,7 +122,7 @@ int __init init_chmod(const char *filename, umode_t mode)
 	error = kern_path(filename, LOOKUP_FOLLOW, &path);
 	if (error)
 		return error;
-	error = chmod_common(&path, mode);
+	error = chmod_common(&path, mode, NULL);
 	path_put(&path);
 	return error;
 }
@@ -201,7 +201,7 @@ int __init init_utimes(char *filename, struct timespec64 *ts)
 	error = kern_path(filename, 0, &path);
 	if (error)
 		return error;
-	error = vfs_utimes(&path, ts);
+	error = vfs_utimes(&path, ts, NULL);
 	path_put(&path);
 	return error;
 }
diff --git a/fs/inode.c b/fs/inode.c
index e4af8a44932b..ff4a6b50ee84 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -2388,7 +2388,7 @@ static int __remove_privs(const struct mnt_idmap *idmap,
 	 * Note we call this on write, so notify_change will not
 	 * encounter any conflicting delegations:
 	 */
-	return notify_change(idmap, path, &newattrs, NULL);
+	return notify_change(idmap, path, &newattrs, NULL, NULL);
 }
 
 static int file_remove_privs_flags(struct file *file, unsigned int flags)
diff --git a/fs/internal.h b/fs/internal.h
index d6a3b48f1633..79a18e8ad29e 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -201,10 +201,12 @@ struct file *file_close_fd_locked(struct files_struct *files, unsigned fd);
 int filp_close_sync(struct file *filp, fl_owner_t id);
 
 int do_ftruncate(struct file *file, loff_t length, unsigned int flags);
-int chmod_common(const struct path *path, umode_t mode);
+int chmod_common(const struct path *path, umode_t mode,
+		  struct file *file);
 int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group,
 		int flag);
-int chown_common(const struct path *path, uid_t user, gid_t group);
+int chown_common(const struct path *path, uid_t user, gid_t group,
+		  struct file *file);
 extern int vfs_open(const struct path *, struct file *);
 int vfs_open_consume(struct path *, struct file *);
 struct file *task_path_open(const struct path *path);
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index b89898fe6323..844942c5dd8a 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -10550,7 +10550,7 @@ static int cb_getattr_update_times(const struct path *path,
 
 	attrs.ia_valid |= ATTR_DELEG;
 	inode_lock(inode);
-	ret = notify_change(&nop_mnt_idmap, path, &attrs, NULL);
+	ret = notify_change(&nop_mnt_idmap, path, &attrs, NULL, NULL);
 	inode_unlock(inode);
 	return ret;
 }
@@ -10831,7 +10831,7 @@ void nfsd_update_cmtime_attr(struct file *f, unsigned int flags)
 	};
 
 	inode_lock(inode);
-	ret = notify_change(&nop_mnt_idmap, &f->f_path, &attr, NULL);
+	ret = notify_change(&nop_mnt_idmap, &f->f_path, &attr, NULL, NULL);
 	inode_unlock(inode);
 	if (ret)
 		pr_notice_ratelimited("nfsd: Unable to update timestamps on "
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 371c3d716112..9eae731ecb26 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -478,7 +478,7 @@ static int __nfsd_setattr(const struct path *path, struct iattr *iap)
 			return -EFBIG;
 
 		host_err = notify_change(&nop_mnt_idmap, path, &size_attr,
-					  NULL);
+					  NULL, NULL);
 		if (host_err)
 			return host_err;
 		iap->ia_valid &= ~ATTR_SIZE;
@@ -504,7 +504,7 @@ static int __nfsd_setattr(const struct path *path, struct iattr *iap)
 	if (!(iap->ia_valid & ATTR_DELEG))
 		iap->ia_valid |= ATTR_CTIME;
 
-	return notify_change(&nop_mnt_idmap, path, iap, NULL);
+	return notify_change(&nop_mnt_idmap, path, iap, NULL, NULL);
 }
 
 /**
diff --git a/fs/ntfs/named_stream.c b/fs/ntfs/named_stream.c
index 1c55588df5ba..05cac62fca1d 100644
--- a/fs/ntfs/named_stream.c
+++ b/fs/ntfs/named_stream.c
@@ -901,7 +901,8 @@ static int ntfs_stream_setattr_common(const struct mnt_idmap *idmap,
 				err = -EINVAL;
 			} else {
 				err = notify_change_target(idmap, attr->ia_path,
-							   base_dentry, &base_attr, NULL);
+							   base_dentry, &base_attr,
+							   NULL, NULL);
 			}
 		} else {
 			err = 0;
diff --git a/fs/open.c b/fs/open.c
index a96d490915f6..52301fb3536c 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -65,8 +65,13 @@ int do_truncate(const struct mnt_idmap *idmap, const struct path *path,
 	if (ret)
 		return ret;
 
-	/* Note any delegations or leases have already been broken: */
-	ret = notify_change(idmap, path, &newattrs, NULL);
+	/*
+	 * Note any delegations or leases have already been broken.  The
+	 * truncate hooks authorize the size change on the syscall paths
+	 * (truncate(2), ftruncate(2) and open(O_TRUNC)) before they get
+	 * here, so no struct file is passed to the setattr hook.
+	 */
+	ret = notify_change(idmap, path, &newattrs, NULL, NULL);
 	inode_unlock(dentry->d_inode);
 	return ret;
 }
@@ -665,7 +670,7 @@ SYSCALL_DEFINE2(fchroot, int, fd, unsigned int, flags)
 	return error;
 }
 
-int chmod_common(const struct path *path, umode_t mode)
+int chmod_common(const struct path *path, umode_t mode, struct file *file)
 {
 	struct inode *inode = path->dentry->d_inode;
 	struct delegated_inode delegated_inode = { };
@@ -685,7 +690,7 @@ int chmod_common(const struct path *path, umode_t mode)
 	newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
 	newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
 	error = notify_change(mnt_idmap(path->mnt), path, &newattrs,
-			      &delegated_inode);
+			      &delegated_inode, file);
 out_unlock:
 	inode_unlock(inode);
 	if (is_delegated(&delegated_inode)) {
@@ -701,7 +706,7 @@ int chmod_common(const struct path *path, umode_t mode)
 int vfs_fchmod(struct file *file, umode_t mode)
 {
 	audit_file(file);
-	return chmod_common(&file->f_path, mode);
+	return chmod_common(&file->f_path, mode, file);
 }
 
 SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
@@ -723,13 +728,30 @@ static int do_fchmodat(int dfd, const char __user *filename, umode_t mode,
 
 	if (unlikely(flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)))
 		return -EINVAL;
+	/*
+	 * A NULL pathname is rejected with EFAULT for these system calls,
+	 * even with AT_EMPTY_PATH: getname_maybe_null() would otherwise
+	 * treat it like an empty path and act on the file descriptor.
+	 */
+	if (!filename)
+		return -EFAULT;
+
+	CLASS(filename_maybe_null, name)(filename, flags);
+
+	if (!name && dfd >= 0) {
+		CLASS(fd_raw, f)(dfd);
+
+		if (fd_empty(f))
+			return -EBADF;
+
+		return vfs_fchmod(fd_file(f), mode);
+	}
 
 	lookup_flags = (flags & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW;
-	CLASS(filename_uflags, name)(filename, flags);
 retry:
 	error = filename_lookup(dfd, name, lookup_flags, &path, NULL);
 	if (!error) {
-		error = chmod_common(&path, mode);
+		error = chmod_common(&path, mode, NULL);
 		path_put(&path);
 		if (retry_estale(error, lookup_flags)) {
 			lookup_flags |= LOOKUP_REVAL;
@@ -786,7 +808,8 @@ static inline bool setattr_vfsgid(struct iattr *attr, kgid_t kgid)
 	return true;
 }
 
-int chown_common(const struct path *path, uid_t user, gid_t group)
+int chown_common(const struct path *path, uid_t user, gid_t group,
+		 struct file *file)
 {
 	const struct mnt_idmap *idmap;
 	struct user_namespace *fs_userns;
@@ -824,7 +847,7 @@ int chown_common(const struct path *path, uid_t user, gid_t group)
 		from_vfsgid(idmap, fs_userns, newattrs.ia_vfsgid));
 	if (!error)
 		error = notify_change(idmap, path, &newattrs,
-				      &delegated_inode);
+				      &delegated_inode, file);
 	inode_unlock(inode);
 	if (is_delegated(&delegated_inode)) {
 		error = break_deleg_wait(&delegated_inode);
@@ -843,15 +866,32 @@ int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group,
 
 	if ((flag & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
 		return -EINVAL;
+	/*
+	 * A NULL pathname is rejected with EFAULT for these system calls,
+	 * even with AT_EMPTY_PATH: getname_maybe_null() would otherwise
+	 * treat it like an empty path and act on the file descriptor.
+	 */
+	if (!filename)
+		return -EFAULT;
+
+	CLASS(filename_maybe_null, name)(filename, flag);
+
+	if (!name && dfd >= 0) {
+		CLASS(fd_raw, f)(dfd);
+
+		if (fd_empty(f))
+			return -EBADF;
+
+		return vfs_fchown(fd_file(f), user, group);
+	}
 
 	lookup_flags = (flag & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW;
-	CLASS(filename_uflags, name)(filename, flag);
 retry:
 	error = filename_lookup(dfd, name, lookup_flags, &path, NULL);
 	if (!error) {
 		error = mnt_want_write(path.mnt);
 		if (!error) {
-			error = chown_common(&path, user, group);
+			error = chown_common(&path, user, group, NULL);
 			mnt_drop_write(path.mnt);
 		}
 		path_put(&path);
@@ -888,7 +928,7 @@ int vfs_fchown(struct file *file, uid_t user, gid_t group)
 	if (error)
 		return error;
 	audit_file(file);
-	error = chown_common(&file->f_path, user, group);
+	error = chown_common(&file->f_path, user, group, file);
 	mnt_drop_write_file(file);
 	return error;
 }
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index 71885794421e..d8b16b3a51b4 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -219,7 +219,7 @@ static inline int ovl_do_notify_change(struct ovl_fs *ofs,
 		.dentry = upperdentry,
 	};
 
-	return notify_change(ovl_upper_mnt_idmap(ofs), &path, attr, NULL);
+	return notify_change(ovl_upper_mnt_idmap(ofs), &path, attr, NULL, NULL);
 }
 
 static inline int ovl_do_rmdir(struct ovl_fs *ofs,
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 9ba1ae94b283..5be89216f5f6 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -9079,7 +9079,7 @@ static int set_file_basic_info(struct ksmbd_file *fp,
 		}
 
 		inode_lock(inode);
-		rc = notify_change(idmap, &filp->f_path, &attrs, NULL);
+		rc = notify_change(idmap, &filp->f_path, &attrs, NULL, filp);
 		inode_unlock(inode);
 	}
 out:
diff --git a/fs/smb/server/smbacl.c b/fs/smb/server/smbacl.c
index 9fcc7f412e45..a491e32e1e7b 100644
--- a/fs/smb/server/smbacl.c
+++ b/fs/smb/server/smbacl.c
@@ -1975,7 +1975,7 @@ int set_info_sec(struct ksmbd_conn *conn, struct ksmbd_tree_connect *tcon,
 	}
 
 	inode_lock(inode);
-	rc = notify_change(idmap, path, &newattrs, NULL);
+	rc = notify_change(idmap, path, &newattrs, NULL, NULL);
 	inode_unlock(inode);
 	if (get_write)
 		mnt_drop_write(path->mnt);
diff --git a/fs/utimes.c b/fs/utimes.c
index 5193d504d289..94a3946a41ce 100644
--- a/fs/utimes.c
+++ b/fs/utimes.c
@@ -7,6 +7,7 @@
 #include <linux/uaccess.h>
 #include <linux/compat.h>
 #include <asm/unistd.h>
+#include <linux/audit.h>
 #include <linux/filelock.h>
 #include "internal.h"
 
@@ -18,7 +19,8 @@ static bool nsec_valid(long nsec)
 	return nsec >= 0 && nsec <= 999999999;
 }
 
-int vfs_utimes(const struct path *path, struct timespec64 *times)
+int vfs_utimes(const struct path *path, struct timespec64 *times,
+	       struct file *file)
 {
 	int error;
 	struct iattr newattrs;
@@ -34,6 +36,13 @@ int vfs_utimes(const struct path *path, struct timespec64 *times)
 			times = NULL;
 	}
 
+	/*
+	 * Like vfs_fchmod(), audit the request once for the file
+	 * descriptor based spellings; path based callers pass no file.
+	 */
+	if (file)
+		audit_file(file);
+
 	error = mnt_want_write(path->mnt);
 	if (error)
 		goto out;
@@ -65,7 +74,7 @@ int vfs_utimes(const struct path *path, struct timespec64 *times)
 retry_deleg:
 	inode_lock(inode);
 	error = notify_change(mnt_idmap(path->mnt), path, &newattrs,
-			      &delegated_inode);
+			      &delegated_inode, file);
 	inode_unlock(inode);
 	if (is_delegated(&delegated_inode)) {
 		error = break_deleg_wait(&delegated_inode);
@@ -87,16 +96,33 @@ static int do_utimes_path(int dfd, const char __user *filename,
 
 	if (flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH))
 		return -EINVAL;
+	/*
+	 * A NULL pathname is rejected with EFAULT for these system calls,
+	 * even with AT_EMPTY_PATH: getname_maybe_null() would otherwise
+	 * treat it like an empty path and act on the file descriptor.
+	 */
+	if (!filename)
+		return -EFAULT;
+
+	CLASS(filename_maybe_null, name)(filename, flags);
+
+	if (!name && dfd >= 0) {
+		CLASS(fd_raw, f)(dfd);
+
+		if (fd_empty(f))
+			return -EBADF;
+
+		return vfs_utimes(&fd_file(f)->f_path, times, fd_file(f));
+	}
 
 	if (!(flags & AT_SYMLINK_NOFOLLOW))
 		lookup_flags |= LOOKUP_FOLLOW;
 
-	CLASS(filename_uflags, name)(filename, flags);
 retry:
 	error = filename_lookup(dfd, name, lookup_flags, &path, NULL);
 	if (error)
 		return error;
-	error = vfs_utimes(&path, times);
+	error = vfs_utimes(&path, times, NULL);
 	path_put(&path);
 	if (retry_estale(error, lookup_flags)) {
 		lookup_flags |= LOOKUP_REVAL;
@@ -113,7 +139,7 @@ static int do_utimes_fd(int fd, struct timespec64 *times, int flags)
 	CLASS(fd, f)(fd);
 	if (fd_empty(f))
 		return -EBADF;
-	return vfs_utimes(&fd_file(f)->f_path, times);
+	return vfs_utimes(&fd_file(f)->f_path, times, fd_file(f));
 }
 
 /*
diff --git a/include/linux/fs.h b/include/linux/fs.h
index cd19aa264a98..d501d3d9ef0d 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1831,7 +1831,8 @@ int vfs_mkobj(struct dentry *, umode_t,
 
 int vfs_fchown(struct file *file, uid_t user, gid_t group);
 int vfs_fchmod(struct file *file, umode_t mode);
-int vfs_utimes(const struct path *path, struct timespec64 *times);
+int vfs_utimes(const struct path *path, struct timespec64 *times,
+		struct file *file);
 
 #ifdef CONFIG_COMPAT
 extern long compat_ptr_ioctl(struct file *file, unsigned int cmd,
@@ -2730,11 +2731,13 @@ static inline int bmap(struct inode *inode,  sector_t *block)
 #endif
 
 int notify_change(const struct mnt_idmap *, const struct path *,
-		  struct iattr *, struct delegated_inode *);
+		  struct iattr *, struct delegated_inode *,
+		  struct file *);
 int notify_change_target(const struct mnt_idmap *idmap,
 			 const struct path *path, struct dentry *target,
 			 struct iattr *attr,
-			 struct delegated_inode *delegated_inode);
+			 struct delegated_inode *delegated_inode,
+			 struct file *file);
 int inode_permission(const struct mnt_idmap *, struct inode *, int);
 int generic_permission(const struct mnt_idmap *, struct inode *, int);
 static inline int file_permission(struct file *file, int mask)
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index 81a304ce87a3..180d2427e5f9 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -147,8 +147,21 @@ LSM_HOOK(int, 0, inode_follow_link, struct dentry *dentry, struct inode *inode,
 	 bool rcu)
 LSM_HOOK(int, 0, inode_permission, const struct mnt_idmap *idmap,
 	 struct inode *inode, int mask)
-LSM_HOOK(int, 0, inode_setattr, const struct mnt_idmap *idmap, struct dentry *dentry,
-	 struct iattr *attr)
+/*
+ * The struct file argument of the hooks below is NULL when the operation
+ * is not performed through a file descriptor.  It is a borrowed reference
+ * that is only valid for the duration of the hook call: implementations
+ * must neither take a reference on it nor use it after the hook returns.
+ *
+ * path_setattr runs with the i_rwsem held exclusively on the inode of both
+ * @dentry and @path->dentry: the VFS locks the inode named by @path before
+ * calling ->setattr, and a filesystem forwarding the change locks the target
+ * inode before notify_change_target() invokes the hook.  BPF LSM programs
+ * attached to this hook therefore use the locked dentry xattr kfuncs.
+ */
+LSM_HOOK(int, 0, path_setattr, const struct mnt_idmap *idmap,
+	 const struct path *path, struct dentry *dentry,
+	 struct iattr *attr, struct file *file)
 LSM_HOOK(void, LSM_RET_VOID, inode_post_setattr, const struct mnt_idmap *idmap,
 	 struct dentry *dentry, int ia_valid)
 LSM_HOOK(int, 0, inode_getattr, const struct path *path)
diff --git a/include/linux/security.h b/include/linux/security.h
index 3c52a5d2c708..e929ef320888 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -430,8 +430,9 @@ int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
 			       bool rcu);
 int security_inode_permission(const struct mnt_idmap *idmap,
 			      struct inode *inode, int mask);
-int security_inode_setattr(const struct mnt_idmap *idmap,
-			   struct dentry *dentry, struct iattr *attr);
+int security_path_setattr(const struct mnt_idmap *idmap,
+			  const struct path *path, struct dentry *dentry,
+			  struct iattr *attr, struct file *file);
 void security_inode_post_setattr(const struct mnt_idmap *idmap, struct dentry *dentry,
 				 int ia_valid);
 int security_inode_getattr(const struct path *path);
@@ -1002,9 +1003,11 @@ static inline int security_inode_permission(const struct mnt_idmap *idmap,
 	return 0;
 }
 
-static inline int security_inode_setattr(const struct mnt_idmap *idmap,
-					 struct dentry *dentry,
-					 struct iattr *attr)
+static inline int security_path_setattr(const struct mnt_idmap *idmap,
+					const struct path *path,
+					struct dentry *dentry,
+					struct iattr *attr,
+					struct file *file)
 {
 	return 0;
 }
diff --git a/init/initramfs.c b/init/initramfs.c
index ebddde9c8f0d..c8172440276e 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -144,7 +144,7 @@ static void __init do_utime(char *filename, time64_t mtime)
 static void __init do_utime_path(const struct path *path, time64_t mtime)
 {
 	struct timespec64 t[2] = { { .tv_sec = mtime }, { .tv_sec = mtime } };
-	vfs_utimes(path, t);
+	vfs_utimes(path, t, NULL);
 }
 
 static __initdata LIST_HEAD(dir_list);
diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c
index 25b65557731d..c8d25b7ba2ea 100644
--- a/kernel/bpf/bpf_lsm.c
+++ b/kernel/bpf/bpf_lsm.c
@@ -352,7 +352,7 @@ BTF_ID(func, bpf_lsm_inode_readlink)
 BTF_ID(func, bpf_lsm_inode_removexattr)
 BTF_ID(func, bpf_lsm_inode_rename)
 BTF_ID(func, bpf_lsm_inode_rmdir)
-BTF_ID(func, bpf_lsm_inode_setattr)
+BTF_ID(func, bpf_lsm_path_setattr)
 BTF_ID(func, bpf_lsm_inode_setxattr)
 BTF_ID(func, bpf_lsm_inode_symlink)
 BTF_ID(func, bpf_lsm_inode_unlink)
diff --git a/kernel/bpf/bpf_lsm_proto.c b/kernel/bpf/bpf_lsm_proto.c
index 814a30a7959e..5d4e9ccd0078 100644
--- a/kernel/bpf/bpf_lsm_proto.c
+++ b/kernel/bpf/bpf_lsm_proto.c
@@ -33,6 +33,22 @@ noinline int bpf_lsm_inode_init_security(struct inode *inode, struct inode *dir,
 	return -EOPNOTSUPP;
 }
 
+/*
+ * Strong definition of the path_setattr() BPF LSM hook.  @dentry is the
+ * inode whose attributes are changed and can differ from @path->dentry for
+ * filesystems that forward the change.  The file argument is only set for
+ * file descriptor-based operations and is NULL for path-based and in-kernel
+ * callers, so mark it as PTR_MAYBE_NULL.
+ */
+noinline int bpf_lsm_path_setattr(const struct mnt_idmap *idmap,
+				  const struct path *path,
+				  struct dentry *dentry,
+				  struct iattr *attr,
+				  struct file *file__nullable)
+{
+	return 0;
+}
+
 /*
  * Strong definitions of the inode xattr BPF LSM hooks.  The file argument is
  * only set for file descriptor-based operations and is NULL for path-based
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 72a4372ad814..d08e95823dd6 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -6687,6 +6687,18 @@ BTF_TYPE_SAFE_TRUSTED(struct file) {
 	struct inode *f_inode;
 };
 
+/*
+ * LSM hooks that take a struct path hand over a path that is valid for the
+ * duration of the hook, so that BPF LSM programs can safely reach its dentry
+ * (e.g. to call the dentry xattr kfuncs).  Only the dentry is marked as
+ * trusted: the template applies to every trusted struct path, and some
+ * callers (e.g. the Landlock tracepoints) build one with mnt left NULL, which
+ * a trusted pointer would make dereferenceable without a fault check.
+ */
+BTF_TYPE_SAFE_TRUSTED(struct path) {
+	struct dentry *dentry;
+};
+
 /*
  * The pointer fields in the sched_ext ops argument containers are pinned by the
  * callers for the duration of the ops calls and are never NULL.
@@ -6757,6 +6769,7 @@ static bool type_is_trusted(struct bpf_verifier_env *env,
 	BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED(struct bpf_iter__task));
 	BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED(struct linux_binprm));
 	BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED(struct file));
+	BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED(struct path));
 	BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED(struct scx_init_task_args));
 	BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED(struct scx_cpu_release_args));
 	BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED(struct scx_sub_attach_args));
diff --git a/security/integrity/evm/evm_main.c b/security/integrity/evm/evm_main.c
index 963a1bc89a7d..8a7a150e180c 100644
--- a/security/integrity/evm/evm_main.c
+++ b/security/integrity/evm/evm_main.c
@@ -982,16 +982,19 @@ static int evm_attr_change(const struct mnt_idmap *idmap,
 }
 
 /**
- * evm_inode_setattr - prevent updating an invalid EVM extended attribute
+ * evm_path_setattr - prevent updating an invalid EVM extended attribute
  * @idmap: idmap of the mount
- * @dentry: pointer to the affected dentry
+ * @path: pointer to the affected object
+ * @dentry: inode whose attributes are changed
  * @attr: iattr structure containing the new file attributes
+ * @file: file through which the attribute change is requested, if any
  *
  * Permit update of file attributes when files have a valid EVM signature,
  * except in the case of them having an immutable portable signature.
  */
-static int evm_inode_setattr(const struct mnt_idmap *idmap, struct dentry *dentry,
-			     struct iattr *attr)
+static int evm_path_setattr(const struct mnt_idmap *idmap,
+			    const struct path *path, struct dentry *dentry,
+			    struct iattr *attr, struct file *file)
 {
 	unsigned int ia_valid = attr->ia_valid;
 	enum integrity_status evm_status;
@@ -1229,7 +1232,7 @@ static int __init init_evm(void)
 }
 
 static struct security_hook_list evm_hooks[] __ro_after_init = {
-	LSM_HOOK_INIT(inode_setattr, evm_inode_setattr),
+	LSM_HOOK_INIT(path_setattr, evm_path_setattr),
 	LSM_HOOK_INIT(inode_post_setattr, evm_inode_post_setattr),
 	LSM_HOOK_INIT(inode_copy_up_xattr, evm_inode_copy_up_xattr),
 	LSM_HOOK_INIT(inode_setxattr, evm_inode_setxattr),
diff --git a/security/security.c b/security/security.c
index 6d2bdfaf234d..e27add36b0a6 100644
--- a/security/security.c
+++ b/security/security.c
@@ -1866,10 +1866,13 @@ int security_inode_permission(const struct mnt_idmap *idmap,
 }
 
 /**
- * security_inode_setattr() - Check if setting file attributes is allowed
+ * security_path_setattr() - Check if setting file attributes is allowed
  * @idmap: idmap of the mount
- * @dentry: file
+ * @path: file (the VFS makes no guarantees with regard to @path->mnt)
+ * @dentry: inode whose attributes are changed; this can differ from
+ *          @path->dentry when a filesystem forwards the change
  * @attr: new attributes
+ * @file: file through which the attribute change is requested, if any
  *
  * Check permission before setting file attributes.  Note that the kernel call
  * to notify_change is performed from several locations, whenever file
@@ -1878,14 +1881,15 @@ int security_inode_permission(const struct mnt_idmap *idmap,
  *
  * Return: Returns 0 if permission is granted.
  */
-int security_inode_setattr(const struct mnt_idmap *idmap,
-			   struct dentry *dentry, struct iattr *attr)
+int security_path_setattr(const struct mnt_idmap *idmap,
+			  const struct path *path, struct dentry *dentry,
+			  struct iattr *attr, struct file *file)
 {
 	if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
 		return 0;
-	return call_int_hook(inode_setattr, idmap, dentry, attr);
+	return call_int_hook(path_setattr, idmap, path, dentry, attr, file);
 }
-EXPORT_SYMBOL_GPL(security_inode_setattr);
+EXPORT_SYMBOL_GPL(security_path_setattr);
 
 /**
  * security_inode_post_setattr() - Update the inode after a setattr operation
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 85b18c155a17..0d55906f62e5 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3317,8 +3317,10 @@ static int selinux_inode_permission(const struct mnt_idmap *idmap,
 	return rc;
 }
 
-static int selinux_inode_setattr(const struct mnt_idmap *idmap, struct dentry *dentry,
-				 struct iattr *iattr)
+static int selinux_path_setattr(const struct mnt_idmap *idmap,
+				const struct path *path,
+				struct dentry *dentry,
+				struct iattr *iattr, struct file *file)
 {
 	const struct cred *cred = current_cred();
 	struct inode *inode = d_backing_inode(dentry);
@@ -7737,7 +7739,7 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(inode_readlink, selinux_inode_readlink),
 	LSM_HOOK_INIT(inode_follow_link, selinux_inode_follow_link),
 	LSM_HOOK_INIT(inode_permission, selinux_inode_permission),
-	LSM_HOOK_INIT(inode_setattr, selinux_inode_setattr),
+	LSM_HOOK_INIT(path_setattr, selinux_path_setattr),
 	LSM_HOOK_INIT(inode_getattr, selinux_inode_getattr),
 	LSM_HOOK_INIT(inode_xattr_skipcap, selinux_inode_xattr_skipcap),
 	LSM_HOOK_INIT(inode_setxattr, selinux_inode_setxattr),
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 74c4a40ef028..c66cdb8a45d7 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1265,15 +1265,19 @@ static int smack_inode_permission(const struct mnt_idmap *idmap, struct inode *i
 }
 
 /**
- * smack_inode_setattr - Smack check for setting attributes
+ * smack_path_setattr - Smack check for setting attributes
  * @idmap: idmap of the mount
- * @dentry: the object
+ * @path: the object
+ * @dentry: inode whose attributes are changed
  * @iattr: for the force flag
+ * @file: file through which the attribute change is requested, if any
  *
  * Returns 0 if access is permitted, an error code otherwise
  */
-static int smack_inode_setattr(const struct mnt_idmap *idmap, struct dentry *dentry,
-			       struct iattr *iattr)
+static int smack_path_setattr(const struct mnt_idmap *idmap,
+			      const struct path *path,
+			      struct dentry *dentry,
+			      struct iattr *iattr, struct file *file)
 {
 	struct smk_audit_info ad;
 	int rc;
@@ -5200,7 +5204,7 @@ static struct security_hook_list smack_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(inode_rmdir, smack_inode_rmdir),
 	LSM_HOOK_INIT(inode_rename, smack_inode_rename),
 	LSM_HOOK_INIT(inode_permission, smack_inode_permission),
-	LSM_HOOK_INIT(inode_setattr, smack_inode_setattr),
+	LSM_HOOK_INIT(path_setattr, smack_path_setattr),
 	LSM_HOOK_INIT(inode_getattr, smack_inode_getattr),
 	LSM_HOOK_INIT(inode_xattr_skipcap, smack_inode_xattr_skipcap),
 	LSM_HOOK_INIT(inode_setxattr, smack_inode_setxattr),
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 09/17] LSM: rename inode_getattr to path_getattr and pass struct file
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
                   ` (7 preceding siblings ...)
  2026-11-17 15:05 ` [PATCH -next -v4 08/17] LSM: rename inode_setattr to path_setattr and pass struct path and file Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 15:30   ` sashiko-bot
  2026-11-17 15:05 ` [PATCH -next -v4 10/17] LSM: rename the inode xattr hooks to path_xattr hooks Cai Xinchen
                   ` (7 subsequent siblings)
  16 siblings, 1 reply; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

The inode_getattr hook already receives a struct path, so rename it to
path_getattr to follow the path_* convention, and rename
security_inode_getattr() and its SELinux, Smack, AppArmor and TOMOYO
implementations accordingly.

Also pass the struct file through which the attributes are requested,
when there is one, for the same reason as the other metadata hooks.
vfs_getattr() keeps its signature and delegates to the new exported
vfs_getattr_file(), which takes the file and passes it to the hook;
callers that already hold the file use it directly, the others pass NULL.

Update the BPF selftests, the d_path BTF allowlist and the BPF_PROG()
argument lists to the new names and signature.

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 drivers/block/loop.c                          | 12 +++-
 drivers/block/zloop.c                         | 14 +++-
 fs/bpf_fs_kfuncs.c                            |  4 +-
 fs/stat.c                                     | 68 ++++++++++++++-----
 fs/xfs/xfs_ioctl.c                            |  2 +-
 include/linux/fs.h                            |  3 +
 include/linux/lsm_hook_defs.h                 |  3 +-
 include/linux/security.h                      |  5 +-
 kernel/bpf/bpf_lsm.c                          |  2 +-
 kernel/bpf/bpf_lsm_proto.c                    | 11 +++
 kernel/trace/bpf_trace.c                      |  2 +-
 security/apparmor/lsm.c                       |  5 +-
 security/security.c                           |  9 +--
 security/selinux/hooks.c                      |  5 +-
 security/smack/smack_lsm.c                    |  8 ++-
 security/tomoyo/tomoyo.c                      |  8 ++-
 .../testing/selftests/bpf/prog_tests/d_path.c |  2 +-
 .../testing/selftests/bpf/progs/test_d_path.c |  5 +-
 .../bpf/progs/test_d_path_check_rdonly_mem.c  |  5 +-
 .../bpf/progs/test_d_path_check_types.c       |  5 +-
 .../selftests/bpf/progs/verifier_vfs_accept.c |  2 +-
 21 files changed, 125 insertions(+), 55 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index a3325ceab484..d4d4d1fce05c 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -462,7 +462,7 @@ static void loop_update_dio_alignment(struct loop_device *lo)
 	 * file can't be used for direct-io at all, so fall back to the block
 	 * device limits in that case.
 	 */
-	if (!vfs_getattr(&file->f_path, &st, STATX_DIOALIGN, 0) &&
+	if (!vfs_getattr_file(&file->f_path, &st, STATX_DIOALIGN, 0, file) &&
 	    (st.result_mask & STATX_DIOALIGN) && st.dio_mem_align) {
 		lo->lo_min_dio_size = st.dio_offset_align;
 		lo->lo_dio_mem_align = min(st.dio_mem_align - 1, PAGE_SIZE - 1);
@@ -1220,7 +1220,15 @@ loop_get_status(struct loop_device *lo, struct loop_info64 *info)
 	path = lo->lo_backing_file->f_path;
 	path_get(&path);
 	mutex_unlock(&lo->lo_mutex);
-	ret = vfs_getattr(&path, &stat, STATX_INO, AT_STATX_SYNC_AS_STAT);
+	/*
+	 * The backing file was opened by the task that configured the
+	 * device, not by the one querying it, and the attributes are
+	 * returned to the requester: do not hand the file over to the LSM
+	 * hook, the metadata read is checked against the requester's
+	 * domain instead.
+	 */
+	ret = vfs_getattr_file(&path, &stat, STATX_INO,
+			       AT_STATX_SYNC_AS_STAT, NULL);
 	if (!ret) {
 		info->lo_device = huge_encode_dev(stat.dev);
 		info->lo_inode = stat.ino;
diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
index 9d82850d3f44..3b0feb1379ff 100644
--- a/drivers/block/zloop.c
+++ b/drivers/block/zloop.c
@@ -316,7 +316,13 @@ static int zloop_update_seq_zone(struct zloop_device *zlo, unsigned int zone_no)
 
 	lockdep_assert_held(&zone->lock);
 
-	ret = vfs_getattr(&zone->file->f_path, &stat, STATX_SIZE, 0);
+	/*
+	 * The zone file belongs to the task that set up the zone, not to
+	 * the one using the block device, so check the metadata read
+	 * against the current domain.
+	 */
+	ret = vfs_getattr_file(&zone->file->f_path, &stat, STATX_SIZE, 0,
+			       NULL);
 	if (ret < 0) {
 		pr_err("%pg: Failed to get zone %u file stat (err=%d)\n",
 		       zlo->disk->part0, zone_no, ret);
@@ -1074,7 +1080,8 @@ static int zloop_get_block_size(struct zloop_device *zlo,
 	 * file can't be used for direct-io at all, so fall back to the block
 	 * device limits in that case.
 	 */
-	if (!vfs_getattr(&zone->file->f_path, &st, STATX_DIOALIGN, 0) &&
+	if (!vfs_getattr_file(&zone->file->f_path, &st, STATX_DIOALIGN, 0,
+			      zone->file) &&
 	    (st.result_mask & STATX_DIOALIGN) && st.dio_mem_align) {
 		zlo->block_size = st.dio_offset_align;
 		zlo->dio_mem_align = min(st.dio_mem_align - 1, PAGE_SIZE - 1);
@@ -1153,7 +1160,8 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
 		zone->cond = BLK_ZONE_COND_NOT_WP;
 		zone->wp = U64_MAX;
 
-		ret = vfs_getattr(&zone->file->f_path, &stat, STATX_SIZE, 0);
+		ret = vfs_getattr_file(&zone->file->f_path, &stat,
+				       STATX_SIZE, 0, zone->file);
 		if (ret < 0) {
 			pr_err("Failed to get zone %u file stat\n", zone_no);
 			goto out_fput;
diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c
index a28a6eaaa145..079fe44ccd9b 100644
--- a/fs/bpf_fs_kfuncs.c
+++ b/fs/bpf_fs_kfuncs.c
@@ -538,7 +538,7 @@ BTF_SET_END(bpf_inode_init_xattr_hooks)
  * would update the victim without i_rwsem, and the non-locking one would
  * deadlock on the parent.  Reject both kfuncs for these hooks.
  *
- * inode_getattr() is also reached both with and without i_rwsem: path-based
+ * path_getattr() is also reached both with and without i_rwsem: path-based
  * callers such as stat(2) hold no lock, while nfsd fills the pre-operation
  * attributes from nfsd_setattr() with the inode already write-locked.
  */
@@ -546,7 +546,7 @@ BTF_ID_LIST_SINGLE(bpf_set_dentry_xattr_ids, func, bpf_set_dentry_xattr)
 BTF_ID_LIST_SINGLE(bpf_remove_dentry_xattr_ids, func, bpf_remove_dentry_xattr)
 
 BTF_SET_START(d_inode_ambiguous_hooks)
-BTF_ID(func, bpf_lsm_inode_getattr)
+BTF_ID(func, bpf_lsm_path_getattr)
 #ifdef CONFIG_SECURITY_PATH
 BTF_ID(func, bpf_lsm_path_link)
 BTF_ID(func, bpf_lsm_path_rename)
diff --git a/fs/stat.c b/fs/stat.c
index b032821efb79..e68dc17f23c4 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -172,11 +172,12 @@ EXPORT_SYMBOL_GPL(generic_fill_statx_atomic_writes);
  * @request_mask: STATX_xxx flags indicating what the caller wants
  * @query_flags: Query mode (AT_STATX_SYNC_TYPE)
  *
- * Get attributes without calling security_inode_getattr.
+ * Get attributes without calling security_path_getattr.
  *
- * Currently the only caller other than vfs_getattr is internal to the
- * filehandle lookup code, which uses only the inode number and returns no
- * attributes to any user.  Any other code probably wants vfs_getattr.
+ * Callers must call security_path_getattr() beforehand, unless they only
+ * use the attributes internally: the filehandle lookup code, for
+ * instance, uses only the inode number and returns no attributes to any
+ * user.  Code that merely holds a path probably wants vfs_getattr().
  */
 int vfs_getattr_nosec(const struct path *path, struct kstat *stat,
 		      u32 request_mask, unsigned int query_flags)
@@ -261,32 +262,62 @@ EXPORT_SYMBOL(vfs_getattr_nosec);
  */
 int vfs_getattr(const struct path *path, struct kstat *stat,
 		u32 request_mask, unsigned int query_flags)
+{
+	return vfs_getattr_file(path, stat, request_mask, query_flags, NULL);
+}
+EXPORT_SYMBOL(vfs_getattr);
+
+/**
+ * vfs_getattr_file - Get the enhanced basic attributes of an open file
+ * @path: The file of interest
+ * @stat: Where to return the statistics
+ * @request_mask: STATX_xxx flags indicating what the caller wants
+ * @query_flags: Query mode (AT_STATX_SYNC_TYPE)
+ * @file: The file through which the attributes are requested, if any
+ *
+ * Like vfs_getattr(), for callers that hold the struct file the operation
+ * is requested through: security_path_getattr() receives that file, so
+ * that LSMs can authorize the operation with the rights available at
+ * open(2) time.  When @file is set it must refer to the same object as
+ * @path.  Callers that do not hold a file should use vfs_getattr()
+ * instead.
+ *
+ * 0 will be returned on success, and a -ve error code if unsuccessful.
+ */
+int vfs_getattr_file(const struct path *path, struct kstat *stat,
+		     u32 request_mask, unsigned int query_flags,
+		     struct file *file)
 {
 	int retval;
 
-	retval = security_inode_getattr(path);
+	retval = security_path_getattr(path, file);
 	if (unlikely(retval))
 		return retval;
 	return vfs_getattr_nosec(path, stat, request_mask, query_flags);
 }
-EXPORT_SYMBOL(vfs_getattr);
+EXPORT_SYMBOL(vfs_getattr_file);
 
 /**
  * vfs_fstat - Get the basic attributes by file descriptor
  * @fd: The file descriptor referring to the file of interest
  * @stat: The result structure to fill in.
  *
- * This function is a wrapper around vfs_getattr().  The main difference is
- * that it uses a file descriptor to determine the file location.
+ * This function is a wrapper around vfs_getattr_file().  The main
+ * difference is that it uses a file descriptor to determine the file
+ * location, and passes that file to security_path_getattr(), so that
+ * LSMs can later authorize the operation with the rights available at
+ * open(2) time.
  *
  * 0 will be returned on success, and a -ve error code if unsuccessful.
  */
 int vfs_fstat(int fd, struct kstat *stat)
 {
 	CLASS(fd_raw, f)(fd);
+
 	if (fd_empty(f))
 		return -EBADF;
-	return vfs_getattr(&fd_file(f)->f_path, stat, STATX_BASIC_STATS, 0);
+	return vfs_getattr_file(&fd_file(f)->f_path, stat, STATX_BASIC_STATS,
+				0, fd_file(f));
 }
 
 static int statx_lookup_flags(int flags)
@@ -302,9 +333,11 @@ static int statx_lookup_flags(int flags)
 }
 
 static int vfs_statx_path(const struct path *path, int flags, struct kstat *stat,
-			  u32 request_mask)
+			  u32 request_mask, struct file *file)
 {
-	int error = vfs_getattr(path, stat, request_mask, flags);
+	int error;
+
+	error = vfs_getattr_file(path, stat, request_mask, flags, file);
 	if (error)
 		return error;
 
@@ -328,7 +361,8 @@ static int vfs_statx_fd(int fd, int flags, struct kstat *stat,
 	CLASS(fd_raw, f)(fd);
 	if (fd_empty(f))
 		return -EBADF;
-	return vfs_statx_path(&fd_file(f)->f_path, flags, stat, request_mask);
+	return vfs_statx_path(&fd_file(f)->f_path, flags, stat, request_mask,
+			      fd_file(f));
 }
 
 /**
@@ -339,10 +373,10 @@ static int vfs_statx_fd(int fd, int flags, struct kstat *stat,
  * @stat: The result structure to fill in.
  * @request_mask: STATX_xxx flags indicating what the caller wants
  *
- * This function is a wrapper around vfs_getattr().  The main difference is
- * that it uses a filename and base directory to determine the file location.
- * Additionally, the use of AT_SYMLINK_NOFOLLOW in flags will prevent a symlink
- * at the given name from being referenced.
+ * This function is a wrapper around vfs_statx_path().  The main difference
+ * with vfs_getattr() is that it uses a filename and base directory to
+ * determine the file location.  Additionally, the use of AT_SYMLINK_NOFOLLOW
+ * in flags will prevent a symlink at the given name from being referenced.
  *
  * 0 will be returned on success, and a -ve error code if unsuccessful.
  */
@@ -361,7 +395,7 @@ static int vfs_statx(int dfd, struct filename *filename, int flags,
 	error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
 	if (error)
 		return error;
-	error = vfs_statx_path(&path, flags, stat, request_mask);
+	error = vfs_statx_path(&path, flags, stat, request_mask, NULL);
 	path_put(&path);
 	if (retry_estale(error, lookup_flags)) {
 		lookup_flags |= LOOKUP_REVAL;
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index f81b6e52ac40..c418e38a78c2 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -1249,7 +1249,7 @@ xfs_ioc_dioinfo(
 	struct dioattr		da;
 	int			error;
 
-	error = vfs_getattr(&file->f_path, &st, STATX_DIOALIGN, 0);
+	error = vfs_getattr_file(&file->f_path, &st, STATX_DIOALIGN, 0, file);
 	if (error)
 		return error;
 
diff --git a/include/linux/fs.h b/include/linux/fs.h
index d501d3d9ef0d..0e65e53cad84 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3241,6 +3241,9 @@ void generic_fill_statx_atomic_writes(struct kstat *stat,
 				      unsigned int unit_max_opt);
 extern int vfs_getattr_nosec(const struct path *, struct kstat *, u32, unsigned int);
 extern int vfs_getattr(const struct path *, struct kstat *, u32, unsigned int);
+int vfs_getattr_file(const struct path *path, struct kstat *stat,
+		     u32 request_mask, unsigned int query_flags,
+		     struct file *file);
 void __inode_add_bytes(struct inode *inode, loff_t bytes);
 void inode_add_bytes(struct inode *inode, loff_t bytes);
 void __inode_sub_bytes(struct inode *inode, loff_t bytes);
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index 180d2427e5f9..504db4be1cf9 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -164,7 +164,8 @@ LSM_HOOK(int, 0, path_setattr, const struct mnt_idmap *idmap,
 	 struct iattr *attr, struct file *file)
 LSM_HOOK(void, LSM_RET_VOID, inode_post_setattr, const struct mnt_idmap *idmap,
 	 struct dentry *dentry, int ia_valid)
-LSM_HOOK(int, 0, inode_getattr, const struct path *path)
+LSM_HOOK(int, 0, path_getattr, const struct path *path,
+	 struct file *file)
 LSM_HOOK(int, 0, inode_xattr_skipcap, const char *name)
 LSM_HOOK(int, 0, inode_setxattr, const struct mnt_idmap *idmap,
 	 const struct path *path, const char *name, const void *value,
diff --git a/include/linux/security.h b/include/linux/security.h
index e929ef320888..a2f2c97473dd 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -435,7 +435,7 @@ int security_path_setattr(const struct mnt_idmap *idmap,
 			  struct iattr *attr, struct file *file);
 void security_inode_post_setattr(const struct mnt_idmap *idmap, struct dentry *dentry,
 				 int ia_valid);
-int security_inode_getattr(const struct path *path);
+int security_path_getattr(const struct path *path, struct file *file);
 int security_inode_setxattr(const struct mnt_idmap *idmap,
 			    const struct path *path, const char *name,
 			    const void *value, size_t size, int flags,
@@ -1017,7 +1017,8 @@ security_inode_post_setattr(const struct mnt_idmap *idmap, struct dentry *dentry
 			    int ia_valid)
 { }
 
-static inline int security_inode_getattr(const struct path *path)
+static inline int security_path_getattr(const struct path *path,
+					struct file *file)
 {
 	return 0;
 }
diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c
index c8d25b7ba2ea..6ac14e4020a4 100644
--- a/kernel/bpf/bpf_lsm.c
+++ b/kernel/bpf/bpf_lsm.c
@@ -342,7 +342,7 @@ BTF_ID(func, bpf_lsm_file_receive)
 
 BTF_ID(func, bpf_lsm_inode_create)
 BTF_ID(func, bpf_lsm_inode_free_security)
-BTF_ID(func, bpf_lsm_inode_getattr)
+BTF_ID(func, bpf_lsm_path_getattr)
 BTF_ID(func, bpf_lsm_inode_getxattr)
 BTF_ID(func, bpf_lsm_inode_mknod)
 BTF_ID(func, bpf_lsm_inode_need_killpriv)
diff --git a/kernel/bpf/bpf_lsm_proto.c b/kernel/bpf/bpf_lsm_proto.c
index 5d4e9ccd0078..510e18542e49 100644
--- a/kernel/bpf/bpf_lsm_proto.c
+++ b/kernel/bpf/bpf_lsm_proto.c
@@ -49,6 +49,17 @@ noinline int bpf_lsm_path_setattr(const struct mnt_idmap *idmap,
 	return 0;
 }
 
+/*
+ * Strong definition of the path_getattr() BPF LSM hook.  The file argument is
+ * only set by callers that hold the struct file the operation is requested
+ * through, and is NULL for path-based callers, so mark it as PTR_MAYBE_NULL.
+ */
+noinline int bpf_lsm_path_getattr(const struct path *path,
+				  struct file *file__nullable)
+{
+	return 0;
+}
+
 /*
  * Strong definitions of the inode xattr BPF LSM hooks.  The file argument is
  * only set for file descriptor-based operations and is NULL for path-based
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 310740045498..7006e1830269 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -962,7 +962,7 @@ BPF_CALL_3(bpf_d_path, const struct path *, path, char *, buf, u32, sz)
 BTF_SET_START(btf_allowlist_d_path)
 #ifdef CONFIG_SECURITY
 BTF_ID(func, security_file_permission)
-BTF_ID(func, security_inode_getattr)
+BTF_ID(func, security_path_getattr)
 BTF_ID(func, security_file_open)
 #endif
 #ifdef CONFIG_SECURITY_PATH
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index eaebc3c60c5a..2329d73f1d6b 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -457,7 +457,8 @@ static int apparmor_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
 	return common_perm_cond(OP_CHOWN, path, AA_MAY_CHOWN);
 }
 
-static int apparmor_inode_getattr(const struct path *path)
+static int apparmor_path_getattr(const struct path *path,
+				 struct file *file)
 {
 	return common_perm_cond(OP_GETATTR, path, AA_MAY_GETATTR);
 }
@@ -1803,7 +1804,7 @@ static struct security_hook_list apparmor_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(path_chmod, apparmor_path_chmod),
 	LSM_HOOK_INIT(path_chown, apparmor_path_chown),
 	LSM_HOOK_INIT(path_truncate, apparmor_path_truncate),
-	LSM_HOOK_INIT(inode_getattr, apparmor_inode_getattr),
+	LSM_HOOK_INIT(path_getattr, apparmor_path_getattr),
 
 	LSM_HOOK_INIT(file_open, apparmor_file_open),
 	LSM_HOOK_INIT(file_receive, apparmor_file_receive),
diff --git a/security/security.c b/security/security.c
index e27add36b0a6..c7cc9c51becd 100644
--- a/security/security.c
+++ b/security/security.c
@@ -1908,18 +1908,19 @@ void security_inode_post_setattr(const struct mnt_idmap *idmap, struct dentry *d
 }
 
 /**
- * security_inode_getattr() - Check if getting file attributes is allowed
- * @path: file
+ * security_path_getattr() - Check if getting file attributes is allowed
+ * @path: file (the VFS makes no guarantees with regard to @path->mnt)
+ * @file: file through which the attributes are retrieved, if any
  *
  * Check permission before obtaining file attributes.
  *
  * Return: Returns 0 if permission is granted.
  */
-int security_inode_getattr(const struct path *path)
+int security_path_getattr(const struct path *path, struct file *file)
 {
 	if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
 		return 0;
-	return call_int_hook(inode_getattr, path);
+	return call_int_hook(path_getattr, path, file);
 }
 
 /**
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 0d55906f62e5..0323b38fa777 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3348,7 +3348,8 @@ static int selinux_path_setattr(const struct mnt_idmap *idmap,
 	return dentry_has_perm(cred, dentry, av);
 }
 
-static int selinux_inode_getattr(const struct path *path)
+static int selinux_path_getattr(const struct path *path,
+				struct file *file)
 {
 	struct task_security_struct *tsec;
 
@@ -7740,7 +7741,7 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(inode_follow_link, selinux_inode_follow_link),
 	LSM_HOOK_INIT(inode_permission, selinux_inode_permission),
 	LSM_HOOK_INIT(path_setattr, selinux_path_setattr),
-	LSM_HOOK_INIT(inode_getattr, selinux_inode_getattr),
+	LSM_HOOK_INIT(path_getattr, selinux_path_getattr),
 	LSM_HOOK_INIT(inode_xattr_skipcap, selinux_inode_xattr_skipcap),
 	LSM_HOOK_INIT(inode_setxattr, selinux_inode_setxattr),
 	LSM_HOOK_INIT(inode_post_setxattr, selinux_inode_post_setxattr),
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index c66cdb8a45d7..ec1e29f26700 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1296,12 +1296,14 @@ static int smack_path_setattr(const struct mnt_idmap *idmap,
 }
 
 /**
- * smack_inode_getattr - Smack check for getting attributes
+ * smack_path_getattr - Smack check for getting attributes
  * @path: path to extract the info from
+ * @file: file through which the attributes are retrieved, if any
  *
  * Returns 0 if access is permitted, an error code otherwise
  */
-static int smack_inode_getattr(const struct path *path)
+static int smack_path_getattr(const struct path *path,
+			      struct file *file)
 {
 	struct smk_audit_info ad;
 	struct inode *inode = d_backing_inode(path->dentry);
@@ -5205,7 +5207,7 @@ static struct security_hook_list smack_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(inode_rename, smack_inode_rename),
 	LSM_HOOK_INIT(inode_permission, smack_inode_permission),
 	LSM_HOOK_INIT(path_setattr, smack_path_setattr),
-	LSM_HOOK_INIT(inode_getattr, smack_inode_getattr),
+	LSM_HOOK_INIT(path_getattr, smack_path_getattr),
 	LSM_HOOK_INIT(inode_xattr_skipcap, smack_inode_xattr_skipcap),
 	LSM_HOOK_INIT(inode_setxattr, smack_inode_setxattr),
 	LSM_HOOK_INIT(inode_post_setxattr, smack_inode_post_setxattr),
diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
index c66e02ed8ee3..cf0090df7eab 100644
--- a/security/tomoyo/tomoyo.c
+++ b/security/tomoyo/tomoyo.c
@@ -112,13 +112,15 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
 }
 
 /**
- * tomoyo_inode_getattr - Target for security_inode_getattr().
+ * tomoyo_path_getattr - Target for security_path_getattr().
  *
  * @path: Pointer to "struct path".
+ * @file: Pointer to "struct file", or NULL.
  *
  * Returns 0 on success, negative value otherwise.
  */
-static int tomoyo_inode_getattr(const struct path *path)
+static int tomoyo_path_getattr(const struct path *path,
+			       struct file *file)
 {
 	return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, path, NULL);
 }
@@ -570,7 +572,7 @@ static struct security_hook_list tomoyo_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(path_mknod, tomoyo_path_mknod),
 	LSM_HOOK_INIT(path_link, tomoyo_path_link),
 	LSM_HOOK_INIT(path_rename, tomoyo_path_rename),
-	LSM_HOOK_INIT(inode_getattr, tomoyo_inode_getattr),
+	LSM_HOOK_INIT(path_getattr, tomoyo_path_getattr),
 	LSM_HOOK_INIT(file_ioctl, tomoyo_file_ioctl),
 	LSM_HOOK_INIT(file_ioctl_compat, tomoyo_file_ioctl),
 	LSM_HOOK_INIT(path_chmod, tomoyo_path_chmod),
diff --git a/tools/testing/selftests/bpf/prog_tests/d_path.c b/tools/testing/selftests/bpf/prog_tests/d_path.c
index ec73291ef060..3b5a20939ea9 100644
--- a/tools/testing/selftests/bpf/prog_tests/d_path.c
+++ b/tools/testing/selftests/bpf/prog_tests/d_path.c
@@ -98,7 +98,7 @@ static int trigger_fstat_events(pid_t pid)
 	if (!ASSERT_GE(ret, 0, "set_pathname for dir"))
 		goto out_close;
 
-	/* triggers vfs_getattr */
+	/* triggers vfs_fstat() */
 	fstat(pipefd[0], &fileStat);
 	fstat(pipefd[1], &fileStat);
 	fstat(sockfd, &fileStat);
diff --git a/tools/testing/selftests/bpf/progs/test_d_path.c b/tools/testing/selftests/bpf/progs/test_d_path.c
index edb5494a47f7..908ade86f262 100644
--- a/tools/testing/selftests/bpf/progs/test_d_path.c
+++ b/tools/testing/selftests/bpf/progs/test_d_path.c
@@ -19,9 +19,8 @@ int called_stat = 0;
 int called_close = 0;
 int path_match_fallocate = 0;
 
-SEC("fentry/security_inode_getattr")
-int BPF_PROG(prog_stat, struct path *path, struct kstat *stat,
-	     __u32 request_mask, unsigned int query_flags)
+SEC("fentry/security_path_getattr")
+int BPF_PROG(prog_stat, struct path *path, struct file *file)
 {
 	pid_t pid = bpf_get_current_pid_tgid() >> 32;
 	__u32 cnt = cnt_stat;
diff --git a/tools/testing/selftests/bpf/progs/test_d_path_check_rdonly_mem.c b/tools/testing/selftests/bpf/progs/test_d_path_check_rdonly_mem.c
index 27c27cff6a3a..668ce78cff31 100644
--- a/tools/testing/selftests/bpf/progs/test_d_path_check_rdonly_mem.c
+++ b/tools/testing/selftests/bpf/progs/test_d_path_check_rdonly_mem.c
@@ -7,9 +7,8 @@
 
 extern const int bpf_prog_active __ksym;
 
-SEC("fentry/security_inode_getattr")
-int BPF_PROG(d_path_check_rdonly_mem, struct path *path, struct kstat *stat,
-	     __u32 request_mask, unsigned int query_flags)
+SEC("fentry/security_path_getattr")
+int BPF_PROG(d_path_check_rdonly_mem, struct path *path, struct file *file)
 {
 	void *active;
 	__u32 cpu;
diff --git a/tools/testing/selftests/bpf/progs/test_d_path_check_types.c b/tools/testing/selftests/bpf/progs/test_d_path_check_types.c
index 7e02b7361307..18b411f2abad 100644
--- a/tools/testing/selftests/bpf/progs/test_d_path_check_types.c
+++ b/tools/testing/selftests/bpf/progs/test_d_path_check_types.c
@@ -11,9 +11,8 @@ struct {
 	__uint(max_entries, 1 << 12);
 } ringbuf SEC(".maps");
 
-SEC("fentry/security_inode_getattr")
-int BPF_PROG(d_path_check_rdonly_mem, struct path *path, struct kstat *stat,
-	     __u32 request_mask, unsigned int query_flags)
+SEC("fentry/security_path_getattr")
+int BPF_PROG(d_path_check_rdonly_mem, struct path *path, struct file *file)
 {
 	void *active;
 	u32 cpu;
diff --git a/tools/testing/selftests/bpf/progs/verifier_vfs_accept.c b/tools/testing/selftests/bpf/progs/verifier_vfs_accept.c
index 25f37a3dd7cf..81142d217655 100644
--- a/tools/testing/selftests/bpf/progs/verifier_vfs_accept.c
+++ b/tools/testing/selftests/bpf/progs/verifier_vfs_accept.c
@@ -71,7 +71,7 @@ int BPF_PROG(get_task_exe_file_and_put_kfunc_from_argument,
 	return 0;
 }
 
-SEC("lsm.s/inode_getattr")
+SEC("lsm.s/path_getattr")
 __success
 int BPF_PROG(path_d_path_from_path_argument, struct path *path)
 {
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 10/17] LSM: rename the inode xattr hooks to path_xattr hooks
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
                   ` (8 preceding siblings ...)
  2026-11-17 15:05 ` [PATCH -next -v4 09/17] LSM: rename inode_getattr to path_getattr and pass struct file Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 14:55   ` sashiko-bot
  2026-11-17 15:05 ` [PATCH -next -v4 11/17] LSM: rename the inode posix acl hooks to path_*_acl hooks Cai Xinchen
                   ` (6 subsequent siblings)
  16 siblings, 1 reply; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

Rename the inode_{set,get,list,remove}xattr hooks to
path_{set,get,list,remove}xattr, as they take a struct path, and rename
security_inode_*xattr() and the SELinux, Smack, EVM and IMA
implementations accordingly.  The inode_post_* notification hooks still
take a dentry and keep their names.

BPF programs attach to hooks and to the security_*() wrappers by name, so
update the BPF selftests, the strong definitions in
kernel/bpf/bpf_lsm_proto.c and the BTF ID allowlists.  Smack audit
records are initialized with __func__ and now show the new names.

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 Documentation/bpf/fs_kfuncs.rst               |  2 +-
 fs/bpf_fs_kfuncs.c                            |  4 +-
 fs/overlayfs/inode.c                          |  2 +-
 fs/xattr.c                                    | 10 ++---
 include/linux/lsm_hook_defs.h                 |  8 ++--
 include/linux/security.h                      | 38 +++++++++----------
 kernel/bpf/bpf_lsm.c                          |  6 +--
 kernel/bpf/bpf_lsm_proto.c                    | 26 ++++++-------
 security/integrity/evm/evm_main.c             | 28 +++++++-------
 security/integrity/ima/ima_appraise.c         | 20 +++++-----
 security/security.c                           | 37 +++++++++---------
 security/selinux/hooks.c                      | 31 +++++++--------
 security/smack/smack_lsm.c                    | 30 +++++++--------
 .../selftests/bpf/prog_tests/fs_kfuncs.c      | 10 ++---
 .../selftests/bpf/progs/test_get_xattr.c      |  4 +-
 .../bpf/progs/test_set_remove_xattr.c         |  8 ++--
 .../bpf/progs/verifier_lsm_init_xattr.c       |  2 +-
 .../selftests/bpf/progs/verifier_vfs_reject.c |  2 +-
 18 files changed, 135 insertions(+), 133 deletions(-)

diff --git a/Documentation/bpf/fs_kfuncs.rst b/Documentation/bpf/fs_kfuncs.rst
index 8762c3233a3d..9586dbbbf177 100644
--- a/Documentation/bpf/fs_kfuncs.rst
+++ b/Documentation/bpf/fs_kfuncs.rst
@@ -18,4 +18,4 @@ To avoid recursions, these kfuncs follow the following rules:
 1. These kfuncs are only permitted from BPF LSM function.
 2. These kfuncs should not call into other LSM hooks, i.e. security_*(). For
    example, ``bpf_get_file_xattr()`` does not use ``vfs_getxattr()``, because
-   the latter calls LSM hook ``security_inode_getxattr``.
+   the latter calls LSM hook ``security_path_getxattr``.
diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c
index 079fe44ccd9b..f10a9840bf98 100644
--- a/fs/bpf_fs_kfuncs.c
+++ b/fs/bpf_fs_kfuncs.c
@@ -600,10 +600,10 @@ BTF_SET_START(d_inode_locked_hooks)
 BTF_ID(func, bpf_lsm_inode_post_removexattr)
 BTF_ID(func, bpf_lsm_inode_post_setattr)
 BTF_ID(func, bpf_lsm_inode_post_setxattr)
-BTF_ID(func, bpf_lsm_inode_removexattr)
+BTF_ID(func, bpf_lsm_path_removexattr)
 BTF_ID(func, bpf_lsm_inode_rmdir)
 BTF_ID(func, bpf_lsm_path_setattr)
-BTF_ID(func, bpf_lsm_inode_setxattr)
+BTF_ID(func, bpf_lsm_path_setxattr)
 BTF_ID(func, bpf_lsm_inode_unlink)
 /*
  * Path hooks whose path argument is already locked by the caller.  They can
diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index 2f480ab05c88..e9cc798a989f 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -392,7 +392,7 @@ static void ovl_idmap_posix_acl(const struct inode *realinode,
  * > and following it on overlayfs.
  * >
  * > Applying the same logic to acl: we do need to call the
- * > security_inode_getxattr() on the underlying fs, even if just want to
+ * > security_path_getxattr() on the underlying fs, even if just want to
  * > check permissions on overlay. This is currently not done, which is an
  * > inconsistency.
  * >
diff --git a/fs/xattr.c b/fs/xattr.c
index a07d03a0502f..30a349e0b4d6 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -309,8 +309,8 @@ __vfs_setxattr_locked(const struct mnt_idmap *idmap, const struct path *path,
 	if (error)
 		return error;
 
-	error = security_inode_setxattr(idmap, path, name, value, size,
-					flags, file);
+	error = security_path_setxattr(idmap, path, name, value, size,
+				       flags, file);
 	if (error)
 		goto out;
 
@@ -464,7 +464,7 @@ vfs_getxattr(const struct mnt_idmap *idmap, const struct path *path,
 	if (error)
 		return error;
 
-	error = security_inode_getxattr(path, name, file);
+	error = security_path_getxattr(path, name, file);
 	if (error)
 		return error;
 
@@ -517,7 +517,7 @@ vfs_listxattr(const struct path *path, char *list, size_t size,
 	struct inode *inode = d_inode(dentry);
 	ssize_t error;
 
-	error = security_inode_listxattr(path, file);
+	error = security_path_listxattr(path, file);
 	if (error)
 		return error;
 
@@ -580,7 +580,7 @@ __vfs_removexattr_locked(const struct mnt_idmap *idmap,
 	if (error)
 		return error;
 
-	error = security_inode_removexattr(idmap, path, name, file);
+	error = security_path_removexattr(idmap, path, name, file);
 	if (error)
 		goto out;
 
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index 504db4be1cf9..3c43ec49bee8 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -167,16 +167,16 @@ LSM_HOOK(void, LSM_RET_VOID, inode_post_setattr, const struct mnt_idmap *idmap,
 LSM_HOOK(int, 0, path_getattr, const struct path *path,
 	 struct file *file)
 LSM_HOOK(int, 0, inode_xattr_skipcap, const char *name)
-LSM_HOOK(int, 0, inode_setxattr, const struct mnt_idmap *idmap,
+LSM_HOOK(int, 0, path_setxattr, const struct mnt_idmap *idmap,
 	 const struct path *path, const char *name, const void *value,
 	 size_t size, int flags, struct file *file)
 LSM_HOOK(void, LSM_RET_VOID, inode_post_setxattr, struct dentry *dentry,
 	 const char *name, const void *value, size_t size, int flags)
-LSM_HOOK(int, 0, inode_getxattr, const struct path *path, const char *name,
+LSM_HOOK(int, 0, path_getxattr, const struct path *path, const char *name,
 	 struct file *file)
-LSM_HOOK(int, 0, inode_listxattr, const struct path *path,
+LSM_HOOK(int, 0, path_listxattr, const struct path *path,
 	 struct file *file)
-LSM_HOOK(int, 0, inode_removexattr, const struct mnt_idmap *idmap,
+LSM_HOOK(int, 0, path_removexattr, const struct mnt_idmap *idmap,
 	 const struct path *path, const char *name, struct file *file)
 LSM_HOOK(void, LSM_RET_VOID, inode_post_removexattr, struct dentry *dentry,
 	 const char *name)
diff --git a/include/linux/security.h b/include/linux/security.h
index a2f2c97473dd..2784420d6c3d 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -436,10 +436,10 @@ int security_path_setattr(const struct mnt_idmap *idmap,
 void security_inode_post_setattr(const struct mnt_idmap *idmap, struct dentry *dentry,
 				 int ia_valid);
 int security_path_getattr(const struct path *path, struct file *file);
-int security_inode_setxattr(const struct mnt_idmap *idmap,
-			    const struct path *path, const char *name,
-			    const void *value, size_t size, int flags,
-			    struct file *file);
+int security_path_setxattr(const struct mnt_idmap *idmap,
+			   const struct path *path, const char *name,
+			   const void *value, size_t size, int flags,
+			   struct file *file);
 int security_inode_set_acl(const struct mnt_idmap *idmap,
 			   const struct path *path, const char *acl_name,
 			   struct posix_acl *kacl, struct file *file);
@@ -456,13 +456,13 @@ void security_inode_post_remove_acl(const struct mnt_idmap *idmap,
 				    const char *acl_name);
 void security_inode_post_setxattr(struct dentry *dentry, const char *name,
 				  const void *value, size_t size, int flags);
-int security_inode_getxattr(const struct path *path,
-			    const char *name, struct file *file);
-int security_inode_listxattr(const struct path *path,
+int security_path_getxattr(const struct path *path,
+			   const char *name, struct file *file);
+int security_path_listxattr(const struct path *path,
+			    struct file *file);
+int security_path_removexattr(const struct mnt_idmap *idmap,
+			      const struct path *path, const char *name,
 			      struct file *file);
-int security_inode_removexattr(const struct mnt_idmap *idmap,
-			       const struct path *path, const char *name,
-			       struct file *file);
 void security_inode_post_removexattr(struct dentry *dentry, const char *name);
 int security_inode_file_setattr(const struct path *path,
 				struct file_kattr *fa, struct file *file);
@@ -1023,7 +1023,7 @@ static inline int security_path_getattr(const struct path *path,
 	return 0;
 }
 
-static inline int security_inode_setxattr(const struct mnt_idmap *idmap,
+static inline int security_path_setxattr(const struct mnt_idmap *idmap,
 		const struct path *path, const char *name,
 		const void *value, size_t size, int flags,
 		struct file *file)
@@ -1070,22 +1070,22 @@ static inline void security_inode_post_setxattr(struct dentry *dentry,
 		const char *name, const void *value, size_t size, int flags)
 { }
 
-static inline int security_inode_getxattr(const struct path *path,
-			const char *name, struct file *file)
+static inline int security_path_getxattr(const struct path *path,
+					 const char *name, struct file *file)
 {
 	return 0;
 }
 
-static inline int security_inode_listxattr(const struct path *path,
-					   struct file *file)
+static inline int security_path_listxattr(const struct path *path,
+					  struct file *file)
 {
 	return 0;
 }
 
-static inline int security_inode_removexattr(const struct mnt_idmap *idmap,
-					     const struct path *path,
-					     const char *name,
-					     struct file *file)
+static inline int security_path_removexattr(const struct mnt_idmap *idmap,
+					    const struct path *path,
+					    const char *name,
+					    struct file *file)
 {
 	return cap_inode_removexattr(idmap, path, name, file);
 }
diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c
index 6ac14e4020a4..6b110691a9d1 100644
--- a/kernel/bpf/bpf_lsm.c
+++ b/kernel/bpf/bpf_lsm.c
@@ -343,17 +343,17 @@ BTF_ID(func, bpf_lsm_file_receive)
 BTF_ID(func, bpf_lsm_inode_create)
 BTF_ID(func, bpf_lsm_inode_free_security)
 BTF_ID(func, bpf_lsm_path_getattr)
-BTF_ID(func, bpf_lsm_inode_getxattr)
+BTF_ID(func, bpf_lsm_path_getxattr)
 BTF_ID(func, bpf_lsm_inode_mknod)
 BTF_ID(func, bpf_lsm_inode_need_killpriv)
 BTF_ID(func, bpf_lsm_inode_post_setxattr)
 BTF_ID(func, bpf_lsm_inode_post_removexattr)
 BTF_ID(func, bpf_lsm_inode_readlink)
-BTF_ID(func, bpf_lsm_inode_removexattr)
+BTF_ID(func, bpf_lsm_path_removexattr)
 BTF_ID(func, bpf_lsm_inode_rename)
 BTF_ID(func, bpf_lsm_inode_rmdir)
 BTF_ID(func, bpf_lsm_path_setattr)
-BTF_ID(func, bpf_lsm_inode_setxattr)
+BTF_ID(func, bpf_lsm_path_setxattr)
 BTF_ID(func, bpf_lsm_inode_symlink)
 BTF_ID(func, bpf_lsm_inode_unlink)
 BTF_ID(func, bpf_lsm_kernel_module_request)
diff --git a/kernel/bpf/bpf_lsm_proto.c b/kernel/bpf/bpf_lsm_proto.c
index 510e18542e49..c2d51e05a1db 100644
--- a/kernel/bpf/bpf_lsm_proto.c
+++ b/kernel/bpf/bpf_lsm_proto.c
@@ -61,34 +61,34 @@ noinline int bpf_lsm_path_getattr(const struct path *path,
 }
 
 /*
- * Strong definitions of the inode xattr BPF LSM hooks.  The file argument is
+ * Strong definitions of the path xattr BPF LSM hooks.  The file argument is
  * only set for file descriptor-based operations and is NULL for path-based
  * and in-kernel callers, so mark it as PTR_MAYBE_NULL.
  */
-noinline int bpf_lsm_inode_setxattr(const struct mnt_idmap *idmap,
-				    const struct path *path, const char *name,
-				    const void *value, size_t size, int flags,
-				    struct file *file__nullable)
+noinline int bpf_lsm_path_setxattr(const struct mnt_idmap *idmap,
+				   const struct path *path, const char *name,
+				   const void *value, size_t size, int flags,
+				   struct file *file__nullable)
 {
 	return 0;
 }
 
-noinline int bpf_lsm_inode_getxattr(const struct path *path, const char *name,
-				    struct file *file__nullable)
+noinline int bpf_lsm_path_getxattr(const struct path *path, const char *name,
+				   struct file *file__nullable)
 {
 	return 0;
 }
 
-noinline int bpf_lsm_inode_listxattr(const struct path *path,
-				     struct file *file__nullable)
+noinline int bpf_lsm_path_listxattr(const struct path *path,
+				    struct file *file__nullable)
 {
 	return 0;
 }
 
-noinline int bpf_lsm_inode_removexattr(const struct mnt_idmap *idmap,
-				       const struct path *path,
-				       const char *name,
-				       struct file *file__nullable)
+noinline int bpf_lsm_path_removexattr(const struct mnt_idmap *idmap,
+				      const struct path *path,
+				      const char *name,
+				      struct file *file__nullable)
 {
 	return 0;
 }
diff --git a/security/integrity/evm/evm_main.c b/security/integrity/evm/evm_main.c
index 8a7a150e180c..64119591c900 100644
--- a/security/integrity/evm/evm_main.c
+++ b/security/integrity/evm/evm_main.c
@@ -7,8 +7,8 @@
  * Kylene Hall <kjhall@us.ibm.com>
  *
  * File: evm_main.c
- *	implements evm_inode_setxattr, evm_inode_post_setxattr,
- *	evm_inode_removexattr, evm_verifyxattr, and evm_inode_set_acl.
+ *	implements evm_path_setxattr, evm_inode_post_setxattr,
+ *	evm_path_removexattr, evm_verifyxattr, and evm_inode_set_acl.
  */
 
 #define pr_fmt(fmt) "EVM: "fmt
@@ -613,7 +613,7 @@ static int evm_protect_xattr(const struct mnt_idmap *idmap,
 }
 
 /**
- * evm_inode_setxattr - protect the EVM extended attribute
+ * evm_path_setxattr - protect the EVM extended attribute
  * @idmap: idmap of the mount
  * @path: pointer to the affected object
  * @xattr_name: pointer to the affected extended attribute name
@@ -628,11 +628,11 @@ static int evm_protect_xattr(const struct mnt_idmap *idmap,
  * userspace from writing HMAC value.  Writing 'security.evm' requires
  * requires CAP_SYS_ADMIN privileges.
  */
-static int evm_inode_setxattr(const struct mnt_idmap *idmap,
-			      const struct path *path,
-			      const char *xattr_name, const void *xattr_value,
-			      size_t xattr_value_len, int flags,
-			      struct file *file)
+static int evm_path_setxattr(const struct mnt_idmap *idmap,
+			     const struct path *path,
+			     const char *xattr_name, const void *xattr_value,
+			     size_t xattr_value_len, int flags,
+			     struct file *file)
 {
 	const struct evm_ima_xattr_data *xattr_data = xattr_value;
 	struct dentry *dentry = path->dentry;
@@ -655,7 +655,7 @@ static int evm_inode_setxattr(const struct mnt_idmap *idmap,
 }
 
 /**
- * evm_inode_removexattr - protect the EVM extended attribute
+ * evm_path_removexattr - protect the EVM extended attribute
  * @idmap: idmap of the mount
  * @path: pointer to the affected object
  * @xattr_name: pointer to the affected extended attribute name
@@ -664,9 +664,9 @@ static int evm_inode_setxattr(const struct mnt_idmap *idmap,
  * Removing 'security.evm' requires CAP_SYS_ADMIN privileges and that
  * the current value is valid.
  */
-static int evm_inode_removexattr(const struct mnt_idmap *idmap,
-				 const struct path *path,
-				 const char *xattr_name, struct file *file)
+static int evm_path_removexattr(const struct mnt_idmap *idmap,
+				const struct path *path,
+				const char *xattr_name, struct file *file)
 {
 	struct dentry *dentry = path->dentry;
 
@@ -1235,13 +1235,13 @@ static struct security_hook_list evm_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(path_setattr, evm_path_setattr),
 	LSM_HOOK_INIT(inode_post_setattr, evm_inode_post_setattr),
 	LSM_HOOK_INIT(inode_copy_up_xattr, evm_inode_copy_up_xattr),
-	LSM_HOOK_INIT(inode_setxattr, evm_inode_setxattr),
+	LSM_HOOK_INIT(path_setxattr, evm_path_setxattr),
 	LSM_HOOK_INIT(inode_post_setxattr, evm_inode_post_setxattr),
 	LSM_HOOK_INIT(inode_set_acl, evm_inode_set_acl),
 	LSM_HOOK_INIT(inode_post_set_acl, evm_inode_post_set_acl),
 	LSM_HOOK_INIT(inode_remove_acl, evm_inode_remove_acl),
 	LSM_HOOK_INIT(inode_post_remove_acl, evm_inode_post_remove_acl),
-	LSM_HOOK_INIT(inode_removexattr, evm_inode_removexattr),
+	LSM_HOOK_INIT(path_removexattr, evm_path_removexattr),
 	LSM_HOOK_INIT(inode_post_removexattr, evm_inode_post_removexattr),
 	LSM_HOOK_INIT(inode_init_security, evm_inode_init_security),
 	LSM_HOOK_INIT(inode_alloc_security, evm_inode_alloc_security),
diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c
index a231f1f419f7..991982c97726 100644
--- a/security/integrity/ima/ima_appraise.c
+++ b/security/integrity/ima/ima_appraise.c
@@ -759,11 +759,11 @@ static int validate_hash_algo(struct dentry *dentry,
 	return -EACCES;
 }
 
-static int ima_inode_setxattr(const struct mnt_idmap *idmap,
-			      const struct path *path,
-			      const char *xattr_name, const void *xattr_value,
-			      size_t xattr_value_len, int flags,
-			      struct file *file)
+static int ima_path_setxattr(const struct mnt_idmap *idmap,
+			     const struct path *path,
+			     const char *xattr_name, const void *xattr_value,
+			     size_t xattr_value_len, int flags,
+			     struct file *file)
 {
 	const struct evm_ima_xattr_data *xvalue = xattr_value;
 	struct dentry *dentry = path->dentry;
@@ -806,9 +806,9 @@ static int ima_inode_set_acl(const struct mnt_idmap *idmap,
 	return 0;
 }
 
-static int ima_inode_removexattr(const struct mnt_idmap *idmap,
-				 const struct path *path,
-				 const char *xattr_name, struct file *file)
+static int ima_path_removexattr(const struct mnt_idmap *idmap,
+				const struct path *path,
+				const char *xattr_name, struct file *file)
 {
 	int result, digsig = -1;
 
@@ -832,9 +832,9 @@ static int ima_inode_remove_acl(const struct mnt_idmap *idmap,
 
 static struct security_hook_list ima_appraise_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(inode_post_setattr, ima_inode_post_setattr),
-	LSM_HOOK_INIT(inode_setxattr, ima_inode_setxattr),
+	LSM_HOOK_INIT(path_setxattr, ima_path_setxattr),
 	LSM_HOOK_INIT(inode_set_acl, ima_inode_set_acl),
-	LSM_HOOK_INIT(inode_removexattr, ima_inode_removexattr),
+	LSM_HOOK_INIT(path_removexattr, ima_path_removexattr),
 	LSM_HOOK_INIT(inode_remove_acl, ima_inode_remove_acl),
 };
 
diff --git a/security/security.c b/security/security.c
index c7cc9c51becd..470cff4ac24d 100644
--- a/security/security.c
+++ b/security/security.c
@@ -1924,7 +1924,7 @@ int security_path_getattr(const struct path *path, struct file *file)
 }
 
 /**
- * security_inode_setxattr() - Check if setting file xattrs is allowed
+ * security_path_setxattr() - Check if setting file xattrs is allowed
  * @idmap: idmap of the mount
  * @path: file (the VFS makes no guarantees with regard to @path->mnt)
  * @name: xattr name
@@ -1950,10 +1950,10 @@ int security_path_getattr(const struct path *path, struct file *file)
  *
  * Return: Returns 0 if permission is granted.
  */
-int security_inode_setxattr(const struct mnt_idmap *idmap,
-			    const struct path *path, const char *name,
-			    const void *value, size_t size, int flags,
-			    struct file *file)
+int security_path_setxattr(const struct mnt_idmap *idmap,
+			   const struct path *path, const char *name,
+			   const void *value, size_t size, int flags,
+			   struct file *file)
 {
 	int rc;
 
@@ -1967,7 +1967,7 @@ int security_inode_setxattr(const struct mnt_idmap *idmap,
 			return rc;
 	}
 
-	return call_int_hook(inode_setxattr, idmap, path, name, value,
+	return call_int_hook(path_setxattr, idmap, path, name, value,
 			     size, flags, file);
 }
 
@@ -2095,7 +2095,7 @@ void security_inode_post_setxattr(struct dentry *dentry, const char *name,
 }
 
 /**
- * security_inode_getxattr() - Check if xattr access is allowed
+ * security_path_getxattr() - Check if xattr access is allowed
  * @path: file (the VFS makes no guarantees with regard to @path->mnt)
  * @name: xattr name
  * @file: file through which the xattr access is requested, if any
@@ -2105,16 +2105,16 @@ void security_inode_post_setxattr(struct dentry *dentry, const char *name,
  *
  * Return: Returns 0 if permission is granted.
  */
-int security_inode_getxattr(const struct path *path,
-			    const char *name, struct file *file)
+int security_path_getxattr(const struct path *path,
+			   const char *name, struct file *file)
 {
 	if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
 		return 0;
-	return call_int_hook(inode_getxattr, path, name, file);
+	return call_int_hook(path_getxattr, path, name, file);
 }
 
 /**
- * security_inode_listxattr() - Check if listing xattrs is allowed
+ * security_path_listxattr() - Check if listing xattrs is allowed
  * @path: file (the VFS makes no guarantees with regard to @path->mnt)
  * @file: file through which the xattr names are listed, if any
  *
@@ -2123,15 +2123,16 @@ int security_inode_getxattr(const struct path *path,
  *
  * Return: Returns 0 if permission is granted.
  */
-int security_inode_listxattr(const struct path *path, struct file *file)
+int security_path_listxattr(const struct path *path,
+			    struct file *file)
 {
 	if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
 		return 0;
-	return call_int_hook(inode_listxattr, path, file);
+	return call_int_hook(path_listxattr, path, file);
 }
 
 /**
- * security_inode_removexattr() - Check if removing an xattr is allowed
+ * security_path_removexattr() - Check if removing an xattr is allowed
  * @idmap: idmap of the mount
  * @path: file (the VFS makes no guarantees with regard to @path->mnt)
  * @name: xattr name
@@ -2154,9 +2155,9 @@ int security_inode_listxattr(const struct path *path, struct file *file)
  *
  * Return: Returns 0 if permission is granted.
  */
-int security_inode_removexattr(const struct mnt_idmap *idmap,
-			       const struct path *path, const char *name,
-			       struct file *file)
+int security_path_removexattr(const struct mnt_idmap *idmap,
+			      const struct path *path, const char *name,
+			      struct file *file)
 {
 	int rc;
 
@@ -2170,7 +2171,7 @@ int security_inode_removexattr(const struct mnt_idmap *idmap,
 			return rc;
 	}
 
-	return call_int_hook(inode_removexattr, idmap, path, name, file);
+	return call_int_hook(path_removexattr, idmap, path, name, file);
 }
 
 /**
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 0323b38fa777..a49c97498619 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3390,10 +3390,10 @@ static int selinux_inode_xattr_skipcap(const char *name)
 	return !strcmp(name, XATTR_NAME_SELINUX);
 }
 
-static int selinux_inode_setxattr(const struct mnt_idmap *idmap,
-				  const struct path *path,
-				  const char *name, const void *value,
-				  size_t size, int flags, struct file *file)
+static int selinux_path_setxattr(const struct mnt_idmap *idmap,
+				 const struct path *path,
+				 const char *name, const void *value,
+				 size_t size, int flags, struct file *file)
 {
 	struct dentry *dentry = path->dentry;
 	struct inode *inode = d_backing_inode(dentry);
@@ -3540,24 +3540,25 @@ static void selinux_inode_post_setxattr(struct dentry *dentry, const char *name,
 	spin_unlock(&isec->lock);
 }
 
-static int selinux_inode_getxattr(const struct path *path,
-				  const char *name, struct file *file)
+static int selinux_path_getxattr(const struct path *path, const char *name,
+				 struct file *file)
 {
 	const struct cred *cred = current_cred();
 
 	return dentry_has_perm(cred, path->dentry, FILE__GETATTR);
 }
 
-static int selinux_inode_listxattr(const struct path *path, struct file *file)
+static int selinux_path_listxattr(const struct path *path,
+				  struct file *file)
 {
 	const struct cred *cred = current_cred();
 
 	return dentry_has_perm(cred, path->dentry, FILE__GETATTR);
 }
 
-static int selinux_inode_removexattr(const struct mnt_idmap *idmap,
-				     const struct path *path,
-				     const char *name, struct file *file)
+static int selinux_path_removexattr(const struct mnt_idmap *idmap,
+				    const struct path *path,
+				    const char *name, struct file *file)
 {
 	/* if not a selinux xattr, only check the ordinary setattr perm */
 	if (strcmp(name, XATTR_NAME_SELINUX))
@@ -3637,7 +3638,7 @@ static int selinux_path_notify(const struct path *path, u64 mask,
 /*
  * Copy the inode security context value to the user.
  *
- * Permission check is handled by selinux_inode_getxattr hook.
+ * Permission check is handled by selinux_path_getxattr hook.
  */
 static int selinux_inode_getsecurity(const struct mnt_idmap *idmap,
 				     struct inode *inode, const char *name,
@@ -7743,11 +7744,11 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(path_setattr, selinux_path_setattr),
 	LSM_HOOK_INIT(path_getattr, selinux_path_getattr),
 	LSM_HOOK_INIT(inode_xattr_skipcap, selinux_inode_xattr_skipcap),
-	LSM_HOOK_INIT(inode_setxattr, selinux_inode_setxattr),
+	LSM_HOOK_INIT(path_setxattr, selinux_path_setxattr),
 	LSM_HOOK_INIT(inode_post_setxattr, selinux_inode_post_setxattr),
-	LSM_HOOK_INIT(inode_getxattr, selinux_inode_getxattr),
-	LSM_HOOK_INIT(inode_listxattr, selinux_inode_listxattr),
-	LSM_HOOK_INIT(inode_removexattr, selinux_inode_removexattr),
+	LSM_HOOK_INIT(path_getxattr, selinux_path_getxattr),
+	LSM_HOOK_INIT(path_listxattr, selinux_path_listxattr),
+	LSM_HOOK_INIT(path_removexattr, selinux_path_removexattr),
 	LSM_HOOK_INIT(inode_file_getattr, selinux_inode_file_getattr),
 	LSM_HOOK_INIT(inode_file_setattr, selinux_inode_file_setattr),
 	LSM_HOOK_INIT(inode_set_acl, selinux_inode_set_acl),
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index ec1e29f26700..2e4250cc31a2 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1344,7 +1344,7 @@ static int smack_inode_xattr_skipcap(const char *name)
 }
 
 /**
- * smack_inode_setxattr - Smack check for setting xattrs
+ * smack_path_setxattr - Smack check for setting xattrs
  * @idmap: idmap of the mount
  * @path: the object
  * @name: name of the attribute
@@ -1357,10 +1357,10 @@ static int smack_inode_xattr_skipcap(const char *name)
  *
  * Returns 0 if access is permitted, an error code otherwise
  */
-static int smack_inode_setxattr(const struct mnt_idmap *idmap,
-				const struct path *path,
-				const char *name, const void *value,
-				size_t size, int flags, struct file *file)
+static int smack_path_setxattr(const struct mnt_idmap *idmap,
+			       const struct path *path,
+			       const char *name, const void *value,
+			       size_t size, int flags, struct file *file)
 {
 	struct smk_audit_info ad;
 	struct dentry *dentry = path->dentry;
@@ -1464,15 +1464,15 @@ static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
 }
 
 /**
- * smack_inode_getxattr - Smack check on getxattr
+ * smack_path_getxattr - Smack check on getxattr
  * @path: the object
  * @name: unused
  * @file: file through which the xattr access is requested, if any
  *
  * Returns 0 if access is permitted, an error code otherwise
  */
-static int smack_inode_getxattr(const struct path *path,
-			const char *name, struct file *file)
+static int smack_path_getxattr(const struct path *path, const char *name,
+			       struct file *file)
 {
 	struct smk_audit_info ad;
 	struct dentry *dentry = path->dentry;
@@ -1487,7 +1487,7 @@ static int smack_inode_getxattr(const struct path *path,
 }
 
 /**
- * smack_inode_removexattr - Smack check on removexattr
+ * smack_path_removexattr - Smack check on removexattr
  * @idmap: idmap of the mount
  * @path: the object
  * @name: name of the attribute
@@ -1497,9 +1497,9 @@ static int smack_inode_getxattr(const struct path *path,
  *
  * Returns 0 if access is permitted, an error code otherwise
  */
-static int smack_inode_removexattr(const struct mnt_idmap *idmap,
-				   const struct path *path,
-				   const char *name, struct file *file)
+static int smack_path_removexattr(const struct mnt_idmap *idmap,
+				  const struct path *path,
+				  const char *name, struct file *file)
 {
 	struct inode_smack *isp;
 	struct smk_audit_info ad;
@@ -5209,10 +5209,10 @@ static struct security_hook_list smack_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(path_setattr, smack_path_setattr),
 	LSM_HOOK_INIT(path_getattr, smack_path_getattr),
 	LSM_HOOK_INIT(inode_xattr_skipcap, smack_inode_xattr_skipcap),
-	LSM_HOOK_INIT(inode_setxattr, smack_inode_setxattr),
+	LSM_HOOK_INIT(path_setxattr, smack_path_setxattr),
 	LSM_HOOK_INIT(inode_post_setxattr, smack_inode_post_setxattr),
-	LSM_HOOK_INIT(inode_getxattr, smack_inode_getxattr),
-	LSM_HOOK_INIT(inode_removexattr, smack_inode_removexattr),
+	LSM_HOOK_INIT(path_getxattr, smack_path_getxattr),
+	LSM_HOOK_INIT(path_removexattr, smack_path_removexattr),
 	LSM_HOOK_INIT(inode_set_acl, smack_inode_set_acl),
 	LSM_HOOK_INIT(inode_get_acl, smack_inode_get_acl),
 	LSM_HOOK_INIT(inode_remove_acl, smack_inode_remove_acl),
diff --git a/tools/testing/selftests/bpf/prog_tests/fs_kfuncs.c b/tools/testing/selftests/bpf/prog_tests/fs_kfuncs.c
index 43a26ec69a8e..5145b1f03cac 100644
--- a/tools/testing/selftests/bpf/prog_tests/fs_kfuncs.c
+++ b/tools/testing/selftests/bpf/prog_tests/fs_kfuncs.c
@@ -53,7 +53,7 @@ static void test_get_xattr(const char *name, const char *value, bool allow_acces
 	if (!ASSERT_GE(fd, 0, "open_file"))
 		goto out;
 
-	/* Trigger security_inode_getxattr */
+	/* Trigger security_path_getxattr */
 	err = getxattr(testfile, name, v, sizeof(v));
 
 	if (allow_access) {
@@ -148,13 +148,13 @@ static void test_set_remove_xattr(void)
 
 	/* First, test not _locked version of the kfuncs with getxattr. */
 
-	/* Read security.bpf.foo and trigger test_inode_getxattr. This
+	/* Read security.bpf.foo and trigger test_path_getxattr. This
 	 * bpf program will set security.bpf.bar to "world".
 	 */
 	read_and_validate_foo(skel);
 	validate_bar_match(skel);
 
-	/* Read security.bpf.foo and trigger test_inode_getxattr again.
+	/* Read security.bpf.foo and trigger test_path_getxattr again.
 	 * This will remove xattr security.bpf.bar.
 	 */
 	read_and_validate_foo(skel);
@@ -167,13 +167,13 @@ static void test_set_remove_xattr(void)
 
 	/* Second, test _locked version of the kfuncs, with setxattr */
 
-	/* Set security.bpf.foo and trigger test_inode_setxattr. This
+	/* Set security.bpf.foo and trigger test_path_setxattr. This
 	 * bpf program will set security.bpf.bar to "world".
 	 */
 	set_foo(skel);
 	validate_bar_match(skel);
 
-	/* Set security.bpf.foo and trigger test_inode_setxattr again.
+	/* Set security.bpf.foo and trigger test_path_setxattr again.
 	 * This will remove xattr security.bpf.bar.
 	 */
 	set_foo(skel);
diff --git a/tools/testing/selftests/bpf/progs/test_get_xattr.c b/tools/testing/selftests/bpf/progs/test_get_xattr.c
index 97361ff10e9f..c6bde355b58f 100644
--- a/tools/testing/selftests/bpf/progs/test_get_xattr.c
+++ b/tools/testing/selftests/bpf/progs/test_get_xattr.c
@@ -55,8 +55,8 @@ int BPF_PROG(test_file_open, struct file *f)
 	return 0;
 }
 
-SEC("lsm.s/inode_getxattr")
-int BPF_PROG(test_inode_getxattr, const struct path *path, char *name,
+SEC("lsm.s/path_getxattr")
+int BPF_PROG(test_path_getxattr, const struct path *path, char *name,
 	     struct file *file)
 {
 	struct bpf_dynptr value_ptr;
diff --git a/tools/testing/selftests/bpf/progs/test_set_remove_xattr.c b/tools/testing/selftests/bpf/progs/test_set_remove_xattr.c
index 06656ac9a777..d096b00cf3bf 100644
--- a/tools/testing/selftests/bpf/progs/test_set_remove_xattr.c
+++ b/tools/testing/selftests/bpf/progs/test_set_remove_xattr.c
@@ -32,8 +32,8 @@ static inline bool name_match_foo(const char *name)
 }
 
 /* Test bpf_set_dentry_xattr and bpf_remove_dentry_xattr */
-SEC("lsm.s/inode_getxattr")
-int BPF_PROG(test_inode_getxattr, const struct path *path, char *name,
+SEC("lsm.s/path_getxattr")
+int BPF_PROG(test_path_getxattr, const struct path *path, char *name,
 	     struct file *file)
 {
 	struct bpf_dynptr value_ptr;
@@ -87,8 +87,8 @@ bool locked_remove_security_selinux_fail;
  * not-_locked version in the BPF program. The verifier will fix them up
  * properly.
  */
-SEC("lsm.s/inode_setxattr")
-int BPF_PROG(test_inode_setxattr, const struct mnt_idmap *idmap,
+SEC("lsm.s/path_setxattr")
+int BPF_PROG(test_path_setxattr, const struct mnt_idmap *idmap,
 	     const struct path *path,
 	     const char *name, const void *value, size_t size, int flags,
 	     struct file *file)
diff --git a/tools/testing/selftests/bpf/progs/verifier_lsm_init_xattr.c b/tools/testing/selftests/bpf/progs/verifier_lsm_init_xattr.c
index 9b7a15c1862f..bc728fdd0b0f 100644
--- a/tools/testing/selftests/bpf/progs/verifier_lsm_init_xattr.c
+++ b/tools/testing/selftests/bpf/progs/verifier_lsm_init_xattr.c
@@ -232,7 +232,7 @@ int BPF_PROG(reject_lsm_cgroup, struct inode *inode, struct inode *dir,
 	return 0;
 }
 
-SEC("lsm/inode_setxattr")
+SEC("lsm/path_setxattr")
 __failure __msg("calling kernel function bpf_inode_init_xattr is not allowed")
 int BPF_PROG(reject_wrong_hook, const struct mnt_idmap *idmap,
 	     const struct path *path,
diff --git a/tools/testing/selftests/bpf/progs/verifier_vfs_reject.c b/tools/testing/selftests/bpf/progs/verifier_vfs_reject.c
index ed2bd2faebf3..f41750c3fc70 100644
--- a/tools/testing/selftests/bpf/progs/verifier_vfs_reject.c
+++ b/tools/testing/selftests/bpf/progs/verifier_vfs_reject.c
@@ -46,7 +46,7 @@ int BPF_PROG(get_task_exe_file_kfunc_null)
 	return 0;
 }
 
-SEC("lsm.s/inode_getxattr")
+SEC("lsm.s/path_getxattr")
 __failure __msg("R1 type=fp expected=ptr_, trusted_ptr_, rcu_ptr_")
 int BPF_PROG(get_task_exe_file_kfunc_fp)
 {
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 11/17] LSM: rename the inode posix acl hooks to path_*_acl hooks
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
                   ` (9 preceding siblings ...)
  2026-11-17 15:05 ` [PATCH -next -v4 10/17] LSM: rename the inode xattr hooks to path_xattr hooks Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 14:55   ` sashiko-bot
  2026-11-17 15:05 ` [PATCH -next -v4 12/17] LSM: rename the inode fileattr hooks to path_file_* hooks Cai Xinchen
                   ` (5 subsequent siblings)
  16 siblings, 1 reply; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

Rename the inode_{set,get,remove}_acl hooks to path_{set,get,remove}_acl,
as they take a struct path, and rename security_inode_*_acl() and the
SELinux, Smack, EVM and IMA implementations accordingly.  The
inode_post_set_acl and inode_post_remove_acl notification hooks still
take a dentry and keep their names.

Update the BPF selftests, the strong definitions in
kernel/bpf/bpf_lsm_proto.c and the Smack audit function names.

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 fs/posix_acl.c                        |  6 ++--
 include/linux/lsm_hook_defs.h         |  6 ++--
 include/linux/security.h              | 44 ++++++++++++------------
 kernel/bpf/bpf_lsm_proto.c            | 48 +++++++++++++--------------
 security/integrity/evm/evm_main.c     | 26 +++++++--------
 security/integrity/ima/ima_appraise.c | 20 +++++------
 security/security.c                   | 32 +++++++++---------
 security/selinux/hooks.c              | 26 +++++++--------
 security/smack/smack_lsm.c            | 32 +++++++++---------
 9 files changed, 120 insertions(+), 120 deletions(-)

diff --git a/fs/posix_acl.c b/fs/posix_acl.c
index 4de0ad023df8..39a1153eecae 100644
--- a/fs/posix_acl.c
+++ b/fs/posix_acl.c
@@ -1133,7 +1133,7 @@ int vfs_set_acl(const struct mnt_idmap *idmap, const struct path *path,
 	if (error)
 		goto out_inode_unlock;
 
-	error = security_inode_set_acl(idmap, path, acl_name, kacl, file);
+	error = security_path_set_acl(idmap, path, acl_name, kacl, file);
 	if (error)
 		goto out_inode_unlock;
 
@@ -1195,7 +1195,7 @@ struct posix_acl *vfs_get_acl(const struct mnt_idmap *idmap,
 	 * The VFS has no restrictions on reading POSIX ACLs so calling
 	 * something like xattr_permission() isn't needed. Only LSMs get a say.
 	 */
-	error = security_inode_get_acl(idmap, path, acl_name, file);
+	error = security_path_get_acl(idmap, path, acl_name, file);
 	if (error)
 		return ERR_PTR(error);
 
@@ -1252,7 +1252,7 @@ int vfs_remove_acl(const struct mnt_idmap *idmap, const struct path *path,
 	if (error)
 		goto out_inode_unlock;
 
-	error = security_inode_remove_acl(idmap, path, acl_name, file);
+	error = security_path_remove_acl(idmap, path, acl_name, file);
 	if (error)
 		goto out_inode_unlock;
 
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index 3c43ec49bee8..0db95ec9d1d1 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -184,15 +184,15 @@ LSM_HOOK(int, 0, inode_file_setattr, const struct path *path,
 	 struct file_kattr *fa, struct file *file)
 LSM_HOOK(int, 0, inode_file_getattr, const struct path *path,
 	 struct file_kattr *fa, struct file *file)
-LSM_HOOK(int, 0, inode_set_acl, const struct mnt_idmap *idmap,
+LSM_HOOK(int, 0, path_set_acl, const struct mnt_idmap *idmap,
 	 const struct path *path, const char *acl_name,
 	 struct posix_acl *kacl, struct file *file)
 LSM_HOOK(void, LSM_RET_VOID, inode_post_set_acl, struct dentry *dentry,
 	 const char *acl_name, struct posix_acl *kacl)
-LSM_HOOK(int, 0, inode_get_acl, const struct mnt_idmap *idmap,
+LSM_HOOK(int, 0, path_get_acl, const struct mnt_idmap *idmap,
 	 const struct path *path, const char *acl_name,
 	 struct file *file)
-LSM_HOOK(int, 0, inode_remove_acl, const struct mnt_idmap *idmap,
+LSM_HOOK(int, 0, path_remove_acl, const struct mnt_idmap *idmap,
 	 const struct path *path, const char *acl_name,
 	 struct file *file)
 LSM_HOOK(void, LSM_RET_VOID, inode_post_remove_acl, const struct mnt_idmap *idmap,
diff --git a/include/linux/security.h b/include/linux/security.h
index 2784420d6c3d..3dbdfe77d9c3 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -440,17 +440,17 @@ int security_path_setxattr(const struct mnt_idmap *idmap,
 			   const struct path *path, const char *name,
 			   const void *value, size_t size, int flags,
 			   struct file *file);
-int security_inode_set_acl(const struct mnt_idmap *idmap,
-			   const struct path *path, const char *acl_name,
-			   struct posix_acl *kacl, struct file *file);
+int security_path_set_acl(const struct mnt_idmap *idmap,
+			  const struct path *path, const char *acl_name,
+			  struct posix_acl *kacl, struct file *file);
 void security_inode_post_set_acl(struct dentry *dentry, const char *acl_name,
 				 struct posix_acl *kacl);
-int security_inode_get_acl(const struct mnt_idmap *idmap,
-			   const struct path *path, const char *acl_name,
-			   struct file *file);
-int security_inode_remove_acl(const struct mnt_idmap *idmap,
-			      const struct path *path, const char *acl_name,
-			      struct file *file);
+int security_path_get_acl(const struct mnt_idmap *idmap,
+			  const struct path *path, const char *acl_name,
+			  struct file *file);
+int security_path_remove_acl(const struct mnt_idmap *idmap,
+			     const struct path *path, const char *acl_name,
+			     struct file *file);
 void security_inode_post_remove_acl(const struct mnt_idmap *idmap,
 				    struct dentry *dentry,
 				    const char *acl_name);
@@ -1031,11 +1031,11 @@ static inline int security_path_setxattr(const struct mnt_idmap *idmap,
 	return cap_inode_setxattr(path, name, value, size, flags, file);
 }
 
-static inline int security_inode_set_acl(const struct mnt_idmap *idmap,
-					 const struct path *path,
-					 const char *acl_name,
-					 struct posix_acl *kacl,
-					 struct file *file)
+static inline int security_path_set_acl(const struct mnt_idmap *idmap,
+					const struct path *path,
+					const char *acl_name,
+					struct posix_acl *kacl,
+					struct file *file)
 {
 	return 0;
 }
@@ -1045,18 +1045,18 @@ static inline void security_inode_post_set_acl(struct dentry *dentry,
 					       struct posix_acl *kacl)
 { }
 
-static inline int security_inode_get_acl(const struct mnt_idmap *idmap,
-					 const struct path *path,
-					 const char *acl_name,
-					 struct file *file)
+static inline int security_path_get_acl(const struct mnt_idmap *idmap,
+					const struct path *path,
+					const char *acl_name,
+					struct file *file)
 {
 	return 0;
 }
 
-static inline int security_inode_remove_acl(const struct mnt_idmap *idmap,
-					    const struct path *path,
-					    const char *acl_name,
-					    struct file *file)
+static inline int security_path_remove_acl(const struct mnt_idmap *idmap,
+					   const struct path *path,
+					   const char *acl_name,
+					   struct file *file)
 {
 	return 0;
 }
diff --git a/kernel/bpf/bpf_lsm_proto.c b/kernel/bpf/bpf_lsm_proto.c
index c2d51e05a1db..1bc90fd53388 100644
--- a/kernel/bpf/bpf_lsm_proto.c
+++ b/kernel/bpf/bpf_lsm_proto.c
@@ -94,49 +94,49 @@ noinline int bpf_lsm_path_removexattr(const struct mnt_idmap *idmap,
 }
 
 /*
- * Strong definitions of the inode POSIX ACL BPF LSM hooks.  The file argument
+ * Strong definitions of the inode fileattr BPF LSM hooks.  The file argument
  * is only set for file descriptor-based operations and is NULL for path-based
  * and in-kernel callers, so mark it as PTR_MAYBE_NULL.
  */
-noinline int bpf_lsm_inode_set_acl(const struct mnt_idmap *idmap,
-				   const struct path *path,
-				   const char *acl_name, struct posix_acl *kacl,
-				   struct file *file__nullable)
-{
-	return 0;
-}
-
-noinline int bpf_lsm_inode_get_acl(const struct mnt_idmap *idmap,
-				   const struct path *path,
-				   const char *acl_name,
-				   struct file *file__nullable)
+noinline int bpf_lsm_inode_file_setattr(const struct path *path,
+					struct file_kattr *fa,
+					struct file *file__nullable)
 {
 	return 0;
 }
 
-noinline int bpf_lsm_inode_remove_acl(const struct mnt_idmap *idmap,
-				      const struct path *path,
-				      const char *acl_name,
-				      struct file *file__nullable)
+noinline int bpf_lsm_inode_file_getattr(const struct path *path,
+					struct file_kattr *fa,
+					struct file *file__nullable)
 {
 	return 0;
 }
 
 /*
- * Strong definitions of the inode fileattr BPF LSM hooks.  The file argument
+ * Strong definitions of the path POSIX ACL BPF LSM hooks.  The file argument
  * is only set for file descriptor-based operations and is NULL for path-based
  * and in-kernel callers, so mark it as PTR_MAYBE_NULL.
  */
-noinline int bpf_lsm_inode_file_setattr(const struct path *path,
-					struct file_kattr *fa,
-					struct file *file__nullable)
+noinline int bpf_lsm_path_set_acl(const struct mnt_idmap *idmap,
+				  const struct path *path,
+				  const char *acl_name, struct posix_acl *kacl,
+				  struct file *file__nullable)
 {
 	return 0;
 }
 
-noinline int bpf_lsm_inode_file_getattr(const struct path *path,
-					struct file_kattr *fa,
-					struct file *file__nullable)
+noinline int bpf_lsm_path_get_acl(const struct mnt_idmap *idmap,
+				  const struct path *path,
+				  const char *acl_name,
+				  struct file *file__nullable)
+{
+	return 0;
+}
+
+noinline int bpf_lsm_path_remove_acl(const struct mnt_idmap *idmap,
+				     const struct path *path,
+				     const char *acl_name,
+				     struct file *file__nullable)
 {
 	return 0;
 }
diff --git a/security/integrity/evm/evm_main.c b/security/integrity/evm/evm_main.c
index 64119591c900..2cdf765d51dd 100644
--- a/security/integrity/evm/evm_main.c
+++ b/security/integrity/evm/evm_main.c
@@ -8,7 +8,7 @@
  *
  * File: evm_main.c
  *	implements evm_path_setxattr, evm_inode_post_setxattr,
- *	evm_path_removexattr, evm_verifyxattr, and evm_inode_set_acl.
+ *	evm_path_removexattr, evm_verifyxattr, and evm_path_set_acl.
  */
 
 #define pr_fmt(fmt) "EVM: "fmt
@@ -709,7 +709,7 @@ static inline int evm_inode_set_acl_change(const struct mnt_idmap *idmap,
 #endif
 
 /**
- * evm_inode_set_acl - protect the EVM extended attribute from posix acls
+ * evm_path_set_acl - protect the EVM extended attribute from posix acls
  * @idmap: idmap of the mount
  * @path: pointer to the affected object
  * @acl_name: name of the posix acl
@@ -722,10 +722,10 @@ static inline int evm_inode_set_acl_change(const struct mnt_idmap *idmap,
  *
  * Return: zero on success, -EPERM on failure.
  */
-static int evm_inode_set_acl(const struct mnt_idmap *idmap,
-			     const struct path *path,
-			     const char *acl_name, struct posix_acl *kacl,
-			     struct file *file)
+static int evm_path_set_acl(const struct mnt_idmap *idmap,
+			    const struct path *path,
+			    const char *acl_name, struct posix_acl *kacl,
+			    struct file *file)
 {
 	enum integrity_status evm_status;
 	struct dentry *dentry = path->dentry;
@@ -766,7 +766,7 @@ static int evm_inode_set_acl(const struct mnt_idmap *idmap,
 }
 
 /**
- * evm_inode_remove_acl - Protect the EVM extended attribute from posix acls
+ * evm_path_remove_acl - Protect the EVM extended attribute from posix acls
  * @idmap: idmap of the mount
  * @path: pointer to the affected object
  * @acl_name: name of the posix acl
@@ -778,11 +778,11 @@ static int evm_inode_set_acl(const struct mnt_idmap *idmap,
  *
  * Return: zero on success, -EPERM on failure.
  */
-static int evm_inode_remove_acl(const struct mnt_idmap *idmap,
-				const struct path *path,
-				const char *acl_name, struct file *file)
+static int evm_path_remove_acl(const struct mnt_idmap *idmap,
+			       const struct path *path,
+			       const char *acl_name, struct file *file)
 {
-	return evm_inode_set_acl(idmap, path, acl_name, NULL, file);
+	return evm_path_set_acl(idmap, path, acl_name, NULL, file);
 }
 
 static void evm_reset_status(struct inode *inode)
@@ -1237,9 +1237,9 @@ static struct security_hook_list evm_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(inode_copy_up_xattr, evm_inode_copy_up_xattr),
 	LSM_HOOK_INIT(path_setxattr, evm_path_setxattr),
 	LSM_HOOK_INIT(inode_post_setxattr, evm_inode_post_setxattr),
-	LSM_HOOK_INIT(inode_set_acl, evm_inode_set_acl),
+	LSM_HOOK_INIT(path_set_acl, evm_path_set_acl),
 	LSM_HOOK_INIT(inode_post_set_acl, evm_inode_post_set_acl),
-	LSM_HOOK_INIT(inode_remove_acl, evm_inode_remove_acl),
+	LSM_HOOK_INIT(path_remove_acl, evm_path_remove_acl),
 	LSM_HOOK_INIT(inode_post_remove_acl, evm_inode_post_remove_acl),
 	LSM_HOOK_INIT(path_removexattr, evm_path_removexattr),
 	LSM_HOOK_INIT(inode_post_removexattr, evm_inode_post_removexattr),
diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c
index 991982c97726..bad0a597cc29 100644
--- a/security/integrity/ima/ima_appraise.c
+++ b/security/integrity/ima/ima_appraise.c
@@ -795,10 +795,10 @@ static int ima_path_setxattr(const struct mnt_idmap *idmap,
 	return result;
 }
 
-static int ima_inode_set_acl(const struct mnt_idmap *idmap,
-			     const struct path *path,
-			     const char *acl_name, struct posix_acl *kacl,
-			     struct file *file)
+static int ima_path_set_acl(const struct mnt_idmap *idmap,
+			    const struct path *path,
+			    const char *acl_name, struct posix_acl *kacl,
+			    struct file *file)
 {
 	if (evm_revalidate_status(acl_name))
 		ima_reset_appraise_flags(d_backing_inode(path->dentry), -1);
@@ -823,19 +823,19 @@ static int ima_path_removexattr(const struct mnt_idmap *idmap,
 	return result;
 }
 
-static int ima_inode_remove_acl(const struct mnt_idmap *idmap,
-				 const struct path *path,
-				 const char *acl_name, struct file *file)
+static int ima_path_remove_acl(const struct mnt_idmap *idmap,
+			       const struct path *path,
+			       const char *acl_name, struct file *file)
 {
-	return ima_inode_set_acl(idmap, path, acl_name, NULL, file);
+	return ima_path_set_acl(idmap, path, acl_name, NULL, file);
 }
 
 static struct security_hook_list ima_appraise_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(inode_post_setattr, ima_inode_post_setattr),
 	LSM_HOOK_INIT(path_setxattr, ima_path_setxattr),
-	LSM_HOOK_INIT(inode_set_acl, ima_inode_set_acl),
+	LSM_HOOK_INIT(path_set_acl, ima_path_set_acl),
 	LSM_HOOK_INIT(path_removexattr, ima_path_removexattr),
-	LSM_HOOK_INIT(inode_remove_acl, ima_inode_remove_acl),
+	LSM_HOOK_INIT(path_remove_acl, ima_path_remove_acl),
 };
 
 void __init init_ima_appraise_lsm(const struct lsm_id *lsmid)
diff --git a/security/security.c b/security/security.c
index 470cff4ac24d..95d3e890e841 100644
--- a/security/security.c
+++ b/security/security.c
@@ -1972,7 +1972,7 @@ int security_path_setxattr(const struct mnt_idmap *idmap,
 }
 
 /**
- * security_inode_set_acl() - Check if setting posix acls is allowed
+ * security_path_set_acl() - Check if setting posix acls is allowed
  * @idmap: idmap of the mount
  * @path: the object the posix acls are set on (the VFS makes no guarantees
  *        with regard to @path->mnt)
@@ -1986,14 +1986,14 @@ int security_path_setxattr(const struct mnt_idmap *idmap,
  *
  * Return: Returns 0 if permission is granted.
  */
-int security_inode_set_acl(const struct mnt_idmap *idmap,
-			   const struct path *path, const char *acl_name,
-			   struct posix_acl *kacl, struct file *file)
+int security_path_set_acl(const struct mnt_idmap *idmap,
+			  const struct path *path, const char *acl_name,
+			  struct posix_acl *kacl, struct file *file)
 {
 	if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
 		return 0;
-	return call_int_hook(inode_set_acl, idmap, path, acl_name, kacl,
-			       file);
+	return call_int_hook(path_set_acl, idmap, path, acl_name, kacl,
+			     file);
 }
 
 /**
@@ -2014,7 +2014,7 @@ void security_inode_post_set_acl(struct dentry *dentry, const char *acl_name,
 }
 
 /**
- * security_inode_get_acl() - Check if reading posix acls is allowed
+ * security_path_get_acl() - Check if reading posix acls is allowed
  * @idmap: idmap of the mount
  * @path: the object the posix acls are retrieved from (the VFS makes no
  *        guarantees with regard to @path->mnt)
@@ -2027,17 +2027,17 @@ void security_inode_post_set_acl(struct dentry *dentry, const char *acl_name,
  *
  * Return: Returns 0 if permission is granted.
  */
-int security_inode_get_acl(const struct mnt_idmap *idmap,
-			   const struct path *path, const char *acl_name,
-			   struct file *file)
+int security_path_get_acl(const struct mnt_idmap *idmap,
+			  const struct path *path, const char *acl_name,
+			  struct file *file)
 {
 	if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
 		return 0;
-	return call_int_hook(inode_get_acl, idmap, path, acl_name, file);
+	return call_int_hook(path_get_acl, idmap, path, acl_name, file);
 }
 
 /**
- * security_inode_remove_acl() - Check if removing a posix acl is allowed
+ * security_path_remove_acl() - Check if removing a posix acl is allowed
  * @idmap: idmap of the mount
  * @path: the object the posix acl is removed from (the VFS makes no
  *        guarantees with regard to @path->mnt)
@@ -2050,13 +2050,13 @@ int security_inode_get_acl(const struct mnt_idmap *idmap,
  *
  * Return: Returns 0 if permission is granted.
  */
-int security_inode_remove_acl(const struct mnt_idmap *idmap,
-			      const struct path *path, const char *acl_name,
-			      struct file *file)
+int security_path_remove_acl(const struct mnt_idmap *idmap,
+			     const struct path *path, const char *acl_name,
+			     struct file *file)
 {
 	if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
 		return 0;
-	return call_int_hook(inode_remove_acl, idmap, path, acl_name, file);
+	return call_int_hook(path_remove_acl, idmap, path, acl_name, file);
 }
 
 /**
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index a49c97498619..e0f384bb7ca6 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3478,24 +3478,24 @@ static int selinux_path_setxattr(const struct mnt_idmap *idmap,
 			    &ad);
 }
 
-static int selinux_inode_set_acl(const struct mnt_idmap *idmap,
-				 const struct path *path,
-				 const char *acl_name, struct posix_acl *kacl,
-				 struct file *file)
+static int selinux_path_set_acl(const struct mnt_idmap *idmap,
+				const struct path *path,
+				const char *acl_name, struct posix_acl *kacl,
+				struct file *file)
 {
 	return dentry_has_perm(current_cred(), path->dentry, FILE__SETATTR);
 }
 
-static int selinux_inode_get_acl(const struct mnt_idmap *idmap,
-				 const struct path *path,
-				 const char *acl_name, struct file *file)
+static int selinux_path_get_acl(const struct mnt_idmap *idmap,
+				const struct path *path,
+				const char *acl_name, struct file *file)
 {
 	return dentry_has_perm(current_cred(), path->dentry, FILE__GETATTR);
 }
 
-static int selinux_inode_remove_acl(const struct mnt_idmap *idmap,
-				    const struct path *path,
-				    const char *acl_name, struct file *file)
+static int selinux_path_remove_acl(const struct mnt_idmap *idmap,
+				   const struct path *path,
+				   const char *acl_name, struct file *file)
 {
 	return dentry_has_perm(current_cred(), path->dentry, FILE__SETATTR);
 }
@@ -7751,9 +7751,9 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(path_removexattr, selinux_path_removexattr),
 	LSM_HOOK_INIT(inode_file_getattr, selinux_inode_file_getattr),
 	LSM_HOOK_INIT(inode_file_setattr, selinux_inode_file_setattr),
-	LSM_HOOK_INIT(inode_set_acl, selinux_inode_set_acl),
-	LSM_HOOK_INIT(inode_get_acl, selinux_inode_get_acl),
-	LSM_HOOK_INIT(inode_remove_acl, selinux_inode_remove_acl),
+	LSM_HOOK_INIT(path_set_acl, selinux_path_set_acl),
+	LSM_HOOK_INIT(path_get_acl, selinux_path_get_acl),
+	LSM_HOOK_INIT(path_remove_acl, selinux_path_remove_acl),
 	LSM_HOOK_INIT(inode_getsecurity, selinux_inode_getsecurity),
 	LSM_HOOK_INIT(inode_setsecurity, selinux_inode_setsecurity),
 	LSM_HOOK_INIT(inode_listsecurity, selinux_inode_listsecurity),
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 2e4250cc31a2..f301757ab2b7 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1552,7 +1552,7 @@ static int smack_path_removexattr(const struct mnt_idmap *idmap,
 }
 
 /**
- * smack_inode_set_acl - Smack check for setting posix acls
+ * smack_path_set_acl - Smack check for setting posix acls
  * @idmap: idmap of the mnt this request came from
  * @path: the object
  * @acl_name: name of the posix acl
@@ -1561,10 +1561,10 @@ static int smack_path_removexattr(const struct mnt_idmap *idmap,
  *
  * Returns 0 if access is permitted, an error code otherwise
  */
-static int smack_inode_set_acl(const struct mnt_idmap *idmap,
-			       const struct path *path,
-			       const char *acl_name, struct posix_acl *kacl,
-			       struct file *file)
+static int smack_path_set_acl(const struct mnt_idmap *idmap,
+			      const struct path *path,
+			      const char *acl_name, struct posix_acl *kacl,
+			      struct file *file)
 {
 	struct smk_audit_info ad;
 	int rc;
@@ -1579,7 +1579,7 @@ static int smack_inode_set_acl(const struct mnt_idmap *idmap,
 }
 
 /**
- * smack_inode_get_acl - Smack check for getting posix acls
+ * smack_path_get_acl - Smack check for getting posix acls
  * @idmap: idmap of the mnt this request came from
  * @path: the object
  * @acl_name: name of the posix acl
@@ -1587,9 +1587,9 @@ static int smack_inode_set_acl(const struct mnt_idmap *idmap,
  *
  * Returns 0 if access is permitted, an error code otherwise
  */
-static int smack_inode_get_acl(const struct mnt_idmap *idmap,
-			       const struct path *path,
-			       const char *acl_name, struct file *file)
+static int smack_path_get_acl(const struct mnt_idmap *idmap,
+			      const struct path *path,
+			      const char *acl_name, struct file *file)
 {
 	struct smk_audit_info ad;
 	int rc;
@@ -1604,7 +1604,7 @@ static int smack_inode_get_acl(const struct mnt_idmap *idmap,
 }
 
 /**
- * smack_inode_remove_acl - Smack check for getting posix acls
+ * smack_path_remove_acl - Smack check for removing posix acls
  * @idmap: idmap of the mnt this request came from
  * @path: the object
  * @acl_name: name of the posix acl
@@ -1612,9 +1612,9 @@ static int smack_inode_get_acl(const struct mnt_idmap *idmap,
  *
  * Returns 0 if access is permitted, an error code otherwise
  */
-static int smack_inode_remove_acl(const struct mnt_idmap *idmap,
-				  const struct path *path,
-				  const char *acl_name, struct file *file)
+static int smack_path_remove_acl(const struct mnt_idmap *idmap,
+				 const struct path *path,
+				 const char *acl_name, struct file *file)
 {
 	struct smk_audit_info ad;
 	int rc;
@@ -5213,9 +5213,9 @@ static struct security_hook_list smack_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(inode_post_setxattr, smack_inode_post_setxattr),
 	LSM_HOOK_INIT(path_getxattr, smack_path_getxattr),
 	LSM_HOOK_INIT(path_removexattr, smack_path_removexattr),
-	LSM_HOOK_INIT(inode_set_acl, smack_inode_set_acl),
-	LSM_HOOK_INIT(inode_get_acl, smack_inode_get_acl),
-	LSM_HOOK_INIT(inode_remove_acl, smack_inode_remove_acl),
+	LSM_HOOK_INIT(path_set_acl, smack_path_set_acl),
+	LSM_HOOK_INIT(path_get_acl, smack_path_get_acl),
+	LSM_HOOK_INIT(path_remove_acl, smack_path_remove_acl),
 	LSM_HOOK_INIT(inode_getsecurity, smack_inode_getsecurity),
 	LSM_HOOK_INIT(inode_setsecurity, smack_inode_setsecurity),
 	LSM_HOOK_INIT(inode_listsecurity, smack_inode_listsecurity),
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 12/17] LSM: rename the inode fileattr hooks to path_file_* hooks
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
                   ` (10 preceding siblings ...)
  2026-11-17 15:05 ` [PATCH -next -v4 11/17] LSM: rename the inode posix acl hooks to path_*_acl hooks Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 15:02   ` sashiko-bot
  2026-11-17 15:05 ` [PATCH -next -v4 13/17] LSM: rename inode_setsecctx to path_setsecctx Cai Xinchen
                   ` (4 subsequent siblings)
  16 siblings, 1 reply; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

Rename the inode_file_getattr and inode_file_setattr hooks to
path_file_getattr and path_file_setattr, as they take a struct path, and
rename security_inode_file_*() and the SELinux implementations
accordingly.

Update the BPF selftests and the strong definitions in
kernel/bpf/bpf_lsm_proto.c.

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 fs/file_attr.c                |  4 ++--
 include/linux/lsm_hook_defs.h |  4 ++--
 include/linux/security.h      | 20 ++++++++++----------
 kernel/bpf/bpf_lsm_proto.c    | 16 ++++++++--------
 security/security.c           | 16 ++++++++--------
 security/selinux/hooks.c      | 16 ++++++++--------
 6 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/fs/file_attr.c b/fs/file_attr.c
index 846847e64ad3..3b8eb92feade 100644
--- a/fs/file_attr.c
+++ b/fs/file_attr.c
@@ -129,7 +129,7 @@ int vfs_fileattr_get(const struct path *path, struct file_kattr *fa,
 	if (!inode->i_op->fileattr_get)
 		return -ENOIOCTLCMD;
 
-	error = security_inode_file_getattr(path, fa, file);
+	error = security_path_file_getattr(path, fa, file);
 	if (error)
 		return error;
 
@@ -325,7 +325,7 @@ static int do_vfs_fileattr_set(const struct path *const path,
 		err = fileattr_set_prepare(inode, &old_ma, fa);
 		if (err)
 			goto out;
-		err = security_inode_file_setattr(path, fa, file);
+		err = security_path_file_setattr(path, fa, file);
 		if (err)
 			goto out;
 		err = inode->i_op->fileattr_set(idmap, dentry, fa);
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index 0db95ec9d1d1..2680972b2c50 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -180,9 +180,9 @@ LSM_HOOK(int, 0, path_removexattr, const struct mnt_idmap *idmap,
 	 const struct path *path, const char *name, struct file *file)
 LSM_HOOK(void, LSM_RET_VOID, inode_post_removexattr, struct dentry *dentry,
 	 const char *name)
-LSM_HOOK(int, 0, inode_file_setattr, const struct path *path,
+LSM_HOOK(int, 0, path_file_setattr, const struct path *path,
 	 struct file_kattr *fa, struct file *file)
-LSM_HOOK(int, 0, inode_file_getattr, const struct path *path,
+LSM_HOOK(int, 0, path_file_getattr, const struct path *path,
 	 struct file_kattr *fa, struct file *file)
 LSM_HOOK(int, 0, path_set_acl, const struct mnt_idmap *idmap,
 	 const struct path *path, const char *acl_name,
diff --git a/include/linux/security.h b/include/linux/security.h
index 3dbdfe77d9c3..e625564ada1f 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -464,10 +464,10 @@ int security_path_removexattr(const struct mnt_idmap *idmap,
 			      const struct path *path, const char *name,
 			      struct file *file);
 void security_inode_post_removexattr(struct dentry *dentry, const char *name);
-int security_inode_file_setattr(const struct path *path,
-				struct file_kattr *fa, struct file *file);
-int security_inode_file_getattr(const struct path *path,
-				struct file_kattr *fa, struct file *file);
+int security_path_file_setattr(const struct path *path,
+			       struct file_kattr *fa, struct file *file);
+int security_path_file_getattr(const struct path *path,
+			       struct file_kattr *fa, struct file *file);
 int security_inode_need_killpriv(struct dentry *dentry);
 int security_inode_killpriv(const struct mnt_idmap *idmap, struct dentry *dentry);
 int security_inode_getsecurity(const struct mnt_idmap *idmap,
@@ -1094,16 +1094,16 @@ static inline void security_inode_post_removexattr(struct dentry *dentry,
 						   const char *name)
 { }
 
-static inline int security_inode_file_setattr(const struct path *path,
-					      struct file_kattr *fa,
-					      struct file *file)
+static inline int security_path_file_setattr(const struct path *path,
+					     struct file_kattr *fa,
+					     struct file *file)
 {
 	return 0;
 }
 
-static inline int security_inode_file_getattr(const struct path *path,
-					      struct file_kattr *fa,
-					      struct file *file)
+static inline int security_path_file_getattr(const struct path *path,
+					     struct file_kattr *fa,
+					     struct file *file)
 {
 	return 0;
 }
diff --git a/kernel/bpf/bpf_lsm_proto.c b/kernel/bpf/bpf_lsm_proto.c
index 1bc90fd53388..d359ca8ab3cd 100644
--- a/kernel/bpf/bpf_lsm_proto.c
+++ b/kernel/bpf/bpf_lsm_proto.c
@@ -94,20 +94,20 @@ noinline int bpf_lsm_path_removexattr(const struct mnt_idmap *idmap,
 }
 
 /*
- * Strong definitions of the inode fileattr BPF LSM hooks.  The file argument
- * is only set for file descriptor-based operations and is NULL for path-based
+ * Strong definitions of the path fileattr BPF LSM hooks.  The file argument is
+ * only set for file descriptor-based operations and is NULL for path-based
  * and in-kernel callers, so mark it as PTR_MAYBE_NULL.
  */
-noinline int bpf_lsm_inode_file_setattr(const struct path *path,
-					struct file_kattr *fa,
-					struct file *file__nullable)
+noinline int bpf_lsm_path_file_setattr(const struct path *path,
+				       struct file_kattr *fa,
+				       struct file *file__nullable)
 {
 	return 0;
 }
 
-noinline int bpf_lsm_inode_file_getattr(const struct path *path,
-					struct file_kattr *fa,
-					struct file *file__nullable)
+noinline int bpf_lsm_path_file_getattr(const struct path *path,
+				       struct file_kattr *fa,
+				       struct file *file__nullable)
 {
 	return 0;
 }
diff --git a/security/security.c b/security/security.c
index 95d3e890e841..314c7736f0dd 100644
--- a/security/security.c
+++ b/security/security.c
@@ -2189,7 +2189,7 @@ void security_inode_post_removexattr(struct dentry *dentry, const char *name)
 }
 
 /**
- * security_inode_file_setattr() - check if setting fsxattr is allowed
+ * security_path_file_setattr() - check if setting fsxattr is allowed
  * @path: file to set filesystem extended attributes on (the VFS makes no
  *        guarantees with regard to @path->mnt)
  * @fa: extended attributes to set on the inode
@@ -2200,14 +2200,14 @@ void security_inode_post_removexattr(struct dentry *dentry, const char *name)
  *
  * Return: Returns 0 if permission is granted.
  */
-int security_inode_file_setattr(const struct path *path,
-				struct file_kattr *fa, struct file *file)
+int security_path_file_setattr(const struct path *path,
+			       struct file_kattr *fa, struct file *file)
 {
-	return call_int_hook(inode_file_setattr, path, fa, file);
+	return call_int_hook(path_file_setattr, path, fa, file);
 }
 
 /**
- * security_inode_file_getattr() - check if retrieving fsxattr is allowed
+ * security_path_file_getattr() - check if retrieving fsxattr is allowed
  * @path: file to retrieve filesystem extended attributes from (the VFS makes no
  *        guarantees with regard to @path->mnt)
  * @fa: extended attributes to get
@@ -2218,10 +2218,10 @@ int security_inode_file_setattr(const struct path *path,
  *
  * Return: Returns 0 if permission is granted.
  */
-int security_inode_file_getattr(const struct path *path,
-				struct file_kattr *fa, struct file *file)
+int security_path_file_getattr(const struct path *path,
+			       struct file_kattr *fa, struct file *file)
 {
-	return call_int_hook(inode_file_getattr, path, fa, file);
+	return call_int_hook(path_file_getattr, path, fa, file);
 }
 
 /**
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index e0f384bb7ca6..02fa9bbf7ea3 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3573,16 +3573,16 @@ static int selinux_path_removexattr(const struct mnt_idmap *idmap,
 	return -EACCES;
 }
 
-static int selinux_inode_file_setattr(const struct path *path,
-				      struct file_kattr *fa,
-				      struct file *file)
+static int selinux_path_file_setattr(const struct path *path,
+				     struct file_kattr *fa,
+				     struct file *file)
 {
 	return dentry_has_perm(current_cred(), path->dentry, FILE__SETATTR);
 }
 
-static int selinux_inode_file_getattr(const struct path *path,
-				      struct file_kattr *fa,
-				      struct file *file)
+static int selinux_path_file_getattr(const struct path *path,
+				     struct file_kattr *fa,
+				     struct file *file)
 {
 	return dentry_has_perm(current_cred(), path->dentry, FILE__GETATTR);
 }
@@ -7749,8 +7749,8 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(path_getxattr, selinux_path_getxattr),
 	LSM_HOOK_INIT(path_listxattr, selinux_path_listxattr),
 	LSM_HOOK_INIT(path_removexattr, selinux_path_removexattr),
-	LSM_HOOK_INIT(inode_file_getattr, selinux_inode_file_getattr),
-	LSM_HOOK_INIT(inode_file_setattr, selinux_inode_file_setattr),
+	LSM_HOOK_INIT(path_file_getattr, selinux_path_file_getattr),
+	LSM_HOOK_INIT(path_file_setattr, selinux_path_file_setattr),
 	LSM_HOOK_INIT(path_set_acl, selinux_path_set_acl),
 	LSM_HOOK_INIT(path_get_acl, selinux_path_get_acl),
 	LSM_HOOK_INIT(path_remove_acl, selinux_path_remove_acl),
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 13/17] LSM: rename inode_setsecctx to path_setsecctx
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
                   ` (11 preceding siblings ...)
  2026-11-17 15:05 ` [PATCH -next -v4 12/17] LSM: rename the inode fileattr hooks to path_file_* hooks Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 14:59   ` sashiko-bot
  2026-11-17 15:05 ` [PATCH -next -v4 14/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
                   ` (3 subsequent siblings)
  16 siblings, 1 reply; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

The inode_setsecctx hook receives a struct path, so rename it to
path_setsecctx and rename security_inode_setsecctx() and the SELinux and
Smack implementations accordingly.  The exported symbol is renamed as
well, so out-of-tree modules calling security_inode_setsecctx() have to
be updated.  Nothing under tools/ attaches to this hook.

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 fs/nfsd/vfs.c                 | 2 +-
 include/linux/lsm_hook_defs.h | 2 +-
 include/linux/security.h      | 6 +++---
 security/security.c           | 8 ++++----
 security/selinux/hooks.c      | 6 +++---
 security/smack/smack_lsm.c    | 4 ++--
 6 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 9eae731ecb26..aa75d2a60d60 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -628,7 +628,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,
 			break;
 	}
 	if (attr->na_seclabel && attr->na_seclabel->len)
-		attr->na_labelerr = security_inode_setsecctx(&path,
+		attr->na_labelerr = security_path_setsecctx(&path,
 			attr->na_seclabel->data, attr->na_seclabel->len);
 	if (IS_ENABLED(CONFIG_FS_POSIX_ACL) && attr->na_dpacl) {
 		if (!S_ISDIR(inode->i_mode))
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index 2680972b2c50..eefe68db5b45 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -340,7 +340,7 @@ LSM_HOOK(int, 0, secctx_to_secid, const char *secdata, u32 seclen, u32 *secid)
 LSM_HOOK(void, LSM_RET_VOID, release_secctx, struct lsm_context *cp)
 LSM_HOOK(void, LSM_RET_VOID, inode_invalidate_secctx, struct inode *inode)
 LSM_HOOK(int, 0, inode_notifysecctx, struct inode *inode, void *ctx, u32 ctxlen)
-LSM_HOOK(int, 0, inode_setsecctx, const struct path *path, void *ctx,
+LSM_HOOK(int, 0, path_setsecctx, const struct path *path, void *ctx,
 	 u32 ctxlen)
 LSM_HOOK(int, -EOPNOTSUPP, inode_getsecctx, struct inode *inode,
 	 struct lsm_context *cp)
diff --git a/include/linux/security.h b/include/linux/security.h
index e625564ada1f..ddd9e1561084 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -597,7 +597,7 @@ int security_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid);
 void security_release_secctx(struct lsm_context *cp);
 void security_inode_invalidate_secctx(struct inode *inode);
 int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen);
-int security_inode_setsecctx(const struct path *path, void *ctx, u32 ctxlen);
+int security_path_setsecctx(const struct path *path, void *ctx, u32 ctxlen);
 int security_inode_getsecctx(struct inode *inode, struct lsm_context *cp);
 int security_locked_down(enum lockdown_reason what);
 int lsm_fill_user_ctx(struct lsm_ctx __user *uctx, u32 *uctx_len,
@@ -1650,8 +1650,8 @@ static inline int security_inode_notifysecctx(struct inode *inode, void *ctx, u3
 {
 	return -EOPNOTSUPP;
 }
-static inline int security_inode_setsecctx(const struct path *path, void *ctx,
-					   u32 ctxlen)
+static inline int security_path_setsecctx(const struct path *path, void *ctx,
+					  u32 ctxlen)
 {
 	return -EOPNOTSUPP;
 }
diff --git a/security/security.c b/security/security.c
index 314c7736f0dd..d892a26f382f 100644
--- a/security/security.c
+++ b/security/security.c
@@ -4140,7 +4140,7 @@ int security_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
 EXPORT_SYMBOL(security_inode_notifysecctx);
 
 /**
- * security_inode_setsecctx() - Change the security label of an inode
+ * security_path_setsecctx() - Change the security label of an inode
  * @path: inode (the VFS makes no guarantees with regard to @path->mnt)
  * @ctx: secctx
  * @ctxlen: length of secctx
@@ -4155,11 +4155,11 @@ EXPORT_SYMBOL(security_inode_notifysecctx);
  *
  * Return: Returns 0 on success, error on failure.
  */
-int security_inode_setsecctx(const struct path *path, void *ctx, u32 ctxlen)
+int security_path_setsecctx(const struct path *path, void *ctx, u32 ctxlen)
 {
-	return call_int_hook(inode_setsecctx, path, ctx, ctxlen);
+	return call_int_hook(path_setsecctx, path, ctx, ctxlen);
 }
-EXPORT_SYMBOL(security_inode_setsecctx);
+EXPORT_SYMBOL(security_path_setsecctx);
 
 /**
  * security_inode_getsecctx() - Get the security label of an inode
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 02fa9bbf7ea3..b7d90a78c686 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -7162,8 +7162,8 @@ static int selinux_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen
 /*
  *	called with inode->i_mutex locked
  */
-static int selinux_inode_setsecctx(const struct path *path, void *ctx,
-				   u32 ctxlen)
+static int selinux_path_setsecctx(const struct path *path, void *ctx,
+				  u32 ctxlen)
 {
 	return __vfs_setxattr_locked(&nop_mnt_idmap, path, XATTR_NAME_SELINUX,
 				     ctx, ctxlen, 0, NULL, NULL);
@@ -7837,7 +7837,7 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(release_secctx, selinux_release_secctx),
 	LSM_HOOK_INIT(inode_invalidate_secctx, selinux_inode_invalidate_secctx),
 	LSM_HOOK_INIT(inode_notifysecctx, selinux_inode_notifysecctx),
-	LSM_HOOK_INIT(inode_setsecctx, selinux_inode_setsecctx),
+	LSM_HOOK_INIT(path_setsecctx, selinux_path_setsecctx),
 
 	LSM_HOOK_INIT(unix_stream_connect, selinux_socket_unix_stream_connect),
 	LSM_HOOK_INIT(unix_may_send, selinux_socket_unix_may_send),
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index f301757ab2b7..d4364e9eb1f1 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -5006,7 +5006,7 @@ static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
 				       ctxlen, 0);
 }
 
-static int smack_inode_setsecctx(const struct path *path, void *ctx, u32 ctxlen)
+static int smack_path_setsecctx(const struct path *path, void *ctx, u32 ctxlen)
 {
 	return __vfs_setxattr_locked(&nop_mnt_idmap, path, XATTR_NAME_SMACK,
 				     ctx, ctxlen, 0, NULL, NULL);
@@ -5331,7 +5331,7 @@ static struct security_hook_list smack_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(lsmprop_to_secctx, smack_lsmprop_to_secctx),
 	LSM_HOOK_INIT(secctx_to_secid, smack_secctx_to_secid),
 	LSM_HOOK_INIT(inode_notifysecctx, smack_inode_notifysecctx),
-	LSM_HOOK_INIT(inode_setsecctx, smack_inode_setsecctx),
+	LSM_HOOK_INIT(path_setsecctx, smack_path_setsecctx),
 	LSM_HOOK_INIT(inode_getsecctx, smack_inode_getsecctx),
 	LSM_HOOK_INIT(inode_copy_up, smack_inode_copy_up),
 	LSM_HOOK_INIT(inode_copy_up_xattr, smack_inode_copy_up_xattr),
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 14/17] landlock: Add READ_METADATA and WRITE_METADATA access rights
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
                   ` (12 preceding siblings ...)
  2026-11-17 15:05 ` [PATCH -next -v4 13/17] LSM: rename inode_setsecctx to path_setsecctx Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 15:49   ` sashiko-bot
  2026-11-17 15:05 ` [PATCH -next -v4 15/17] selftests/landlock: Add tests for metadata " Cai Xinchen
                   ` (2 subsequent siblings)
  16 siblings, 1 reply; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

Add LANDLOCK_ACCESS_FS_READ_METADATA and
LANDLOCK_ACCESS_FS_WRITE_METADATA, which group metadata operations by
security relevance instead of by syscall [1].  They cover the metadata
system calls, the FS_IOC_* flag ioctls and the file_getattr(2) and
file_setattr(2) interfaces, and are implemented by hooking path_getattr,
path_file_getattr, path_setattr, path_file_setattr, path_setxattr,
path_getxattr, path_listxattr, path_removexattr, path_set_acl,
path_get_acl and path_remove_acl.

Like for LANDLOCK_ACCESS_FS_TRUNCATE, the rights available at open(2)
time decide for operations on an already opened file, whereas path-based
accesses and O_PATH descriptors are checked against the current domain.
Both rights are added to _LANDLOCK_ACCESS_FS_OPTIONAL and their names to
_LANDLOCK_ACCESS_FS_NAMES, and deny_masks_t is widened to u16.

hook_path_setattr only restricts explicit changes.  The setuid/setgid bit
and capability clearing that the kernel performs implicitly arrives with
ATTR_FORCE set and is ignored, while the same clearing requested by
chown(2) is checked; a chown(2) that changes nothing is not restricted.
Kernel-internal accesses made under the current credentials are checked
because they cannot be told apart from a user request, but kernel threads
and override_creds() users are not.

Bump the ABI version to 13, and keep the in-tree selftests valid by
updating the shared masks, the expected ABI version and the expected
trace suffix.

[1]
https://lore.kernel.org/all/abc960a1-e66e-792e-6869-cfd201c29dbe@digikod.net/

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 fs/stat.c                                     |  14 ++
 include/linux/landlock.h                      |   4 +-
 include/uapi/linux/landlock.h                 |  47 +++-
 security/landlock/access.h                    |  13 +-
 security/landlock/fs.c                        | 235 ++++++++++++++++--
 security/landlock/limits.h                    |   2 +-
 security/landlock/syscalls.c                  |   2 +-
 tools/testing/selftests/landlock/base_test.c  |   2 +-
 tools/testing/selftests/landlock/fs_test.c    |   4 +-
 .../selftests/landlock/trace_fs_test.c        |   3 +-
 10 files changed, 285 insertions(+), 41 deletions(-)

diff --git a/fs/stat.c b/fs/stat.c
index e68dc17f23c4..a1a5bd83b507 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -19,6 +19,7 @@
 #include <linux/pagemap.h>
 #include <linux/compat.h>
 #include <linux/iversion.h>
+#include <linux/audit.h>
 
 #include <linux/uaccess.h>
 #include <asm/unistd.h>
@@ -361,6 +362,7 @@ static int vfs_statx_fd(int fd, int flags, struct kstat *stat,
 	CLASS(fd_raw, f)(fd);
 	if (fd_empty(f))
 		return -EBADF;
+	audit_file(fd_file(f));
 	return vfs_statx_path(&fd_file(f)->f_path, flags, stat, request_mask,
 			      fd_file(f));
 }
@@ -391,6 +393,18 @@ static int vfs_statx(int dfd, struct filename *filename, int flags,
 		      AT_STATX_SYNC_TYPE))
 		return -EINVAL;
 
+	/*
+	 * An empty pathname with AT_EMPTY_PATH refers to the file descriptor
+	 * itself.  Resolve it as such so that the struct file is passed down
+	 * to the LSM hooks, like sys_statx() does for a NULL pathname and
+	 * unlike a plain path lookup from the file descriptor.  This branch
+	 * replaces a path lookup, so vfs_statx_fd() keeps auditing the file
+	 * descriptor as that lookup would have.
+	 */
+	if ((flags & AT_EMPTY_PATH) && dfd >= 0 && !IS_ERR_OR_NULL(filename) &&
+	    !filename->name[0])
+		return vfs_statx_fd(dfd, flags, stat, request_mask);
+
 retry:
 	error = filename_lookup(dfd, filename, lookup_flags, &path, NULL);
 	if (error)
diff --git a/include/linux/landlock.h b/include/linux/landlock.h
index 0ee4880988ba..ee1234fbc9f0 100644
--- a/include/linux/landlock.h
+++ b/include/linux/landlock.h
@@ -41,7 +41,9 @@
 	_LANDLOCK_NAME_ENTRY(LANDLOCK_ACCESS_FS_REFER, "refer"), \
 	_LANDLOCK_NAME_ENTRY(LANDLOCK_ACCESS_FS_TRUNCATE, "truncate"), \
 	_LANDLOCK_NAME_ENTRY(LANDLOCK_ACCESS_FS_IOCTL_DEV, "ioctl_dev"), \
-	_LANDLOCK_NAME_ENTRY(LANDLOCK_ACCESS_FS_RESOLVE_UNIX, "resolve_unix")
+	_LANDLOCK_NAME_ENTRY(LANDLOCK_ACCESS_FS_RESOLVE_UNIX, "resolve_unix"), \
+	_LANDLOCK_NAME_ENTRY(LANDLOCK_ACCESS_FS_READ_METADATA, "read_metadata"), \
+	_LANDLOCK_NAME_ENTRY(LANDLOCK_ACCESS_FS_WRITE_METADATA, "write_metadata")
 
 #define _LANDLOCK_ACCESS_NET_NAMES \
 	_LANDLOCK_NAME_ENTRY(LANDLOCK_ACCESS_NET_BIND_TCP, "bind_tcp"), \
diff --git a/include/uapi/linux/landlock.h b/include/uapi/linux/landlock.h
index 7e38b9d1bf12..59838325c2af 100644
--- a/include/uapi/linux/landlock.h
+++ b/include/uapi/linux/landlock.h
@@ -430,10 +430,49 @@ struct landlock_capability_attr {
  *   The rationale for this design is described in
  *   :ref:`Documentation/security/landlock.rst <scoped-flags-interaction>`.
  *
+ * The following access rights apply to both files and directories:
+ *
+ * - %LANDLOCK_ACCESS_FS_READ_METADATA: Read file or directory metadata (e.g.
+ *   inode attributes, extended attributes, and POSIX ACLs) through
+ *   :manpage:`stat(2)`, :manpage:`fstat(2)`, :manpage:`lstat(2)`,
+ *   :manpage:`newfstatat(2)`, :manpage:`statx(2)`, :manpage:`getxattr(2)`,
+ *   and :manpage:`listxattr(2)`.
+ *
+ *   This access right is available since the thirteenth version of the
+ *   Landlock ABI.
+ * - %LANDLOCK_ACCESS_FS_WRITE_METADATA: Change file or directory metadata
+ *   (e.g. inode attributes, extended attributes, and POSIX ACLs) through
+ *   :manpage:`chmod(2)`, :manpage:`chown(2)`, :manpage:`utimensat(2)`,
+ *   :manpage:`setxattr(2)`, and :manpage:`removexattr(2)`, as well as related
+ *   system calls.  Metadata changes that the kernel performs implicitly on
+ *   behalf of another operation (e.g. timestamp updates with
+ *   :manpage:`write(2)`, or set-user-ID and set-group-ID bit clearing with
+ *   :manpage:`write(2)` or :manpage:`truncate(2)`) are not restricted by
+ *   this access right.
+ *
+ *   This access right is available since the thirteenth version of the
+ *   Landlock ABI.
+ *
  * Whether an opened file can be truncated with :manpage:`ftruncate(2)` or used
  * with `ioctl(2)` is determined during :manpage:`open(2)`, in the same way as
  * read and write permissions are checked during :manpage:`open(2)` using
- * %LANDLOCK_ACCESS_FS_READ_FILE and %LANDLOCK_ACCESS_FS_WRITE_FILE.
+ * %LANDLOCK_ACCESS_FS_READ_FILE and %LANDLOCK_ACCESS_FS_WRITE_FILE.  The same
+ * applies to metadata operations performed on an already opened file through
+ * its file descriptor (e.g. :manpage:`fstat(2)`, :manpage:`fchmod(2)`,
+ * :manpage:`fchown(2)`, :manpage:`futimens(2)`, :manpage:`fgetxattr(2)`,
+ * :manpage:`fsetxattr(2)`, the ``FS_IOC_GETFLAGS`` and ``FS_IOC_SETFLAGS``
+ * ioctls, and :manpage:`file_getattr(2)` and :manpage:`file_setattr(2)` with
+ * ``AT_EMPTY_PATH``): these are authorized with
+ * %LANDLOCK_ACCESS_FS_READ_METADATA and %LANDLOCK_ACCESS_FS_WRITE_METADATA at
+ * :manpage:`open(2)` time.  O_PATH file descriptors are an exception: they do
+ * not record any access right at :manpage:`open(2)` time, so metadata
+ * operations performed through them are checked against the Landlock domain
+ * of the calling thread instead.  Only the metadata system calls that accept
+ * O_PATH file descriptors behave that way, e.g. fstat(2), and statx(2),
+ * fchmodat(2), fchownat(2) or utimensat(2) with an empty path; the other
+ * file descriptor based metadata system calls and the
+ * FS_IOC_GETFLAGS and FS_IOC_SETFLAGS ioctls reject O_PATH file descriptors
+ * with EBADF.
  *
  * A directory can receive access rights related to files or directories.  The
  * following access right is applied to the directory itself, and the
@@ -494,9 +533,7 @@ struct landlock_capability_attr {
  *
  *   It is currently not possible to restrict some file-related actions
  *   accessible through these syscall families: :manpage:`chdir(2)`,
- *   :manpage:`stat(2)`, :manpage:`flock(2)`, :manpage:`chmod(2)`,
- *   :manpage:`chown(2)`, :manpage:`setxattr(2)`, :manpage:`utime(2)`,
- *   :manpage:`fcntl(2)`, :manpage:`access(2)`.
+ *   :manpage:`flock(2)`, :manpage:`fcntl(2)`, :manpage:`access(2)`.
  *   Future Landlock evolutions will enable to restrict them.
  */
 /* clang-format off */
@@ -517,6 +554,8 @@ struct landlock_capability_attr {
 #define LANDLOCK_ACCESS_FS_TRUNCATE			(1ULL << 14)
 #define LANDLOCK_ACCESS_FS_IOCTL_DEV			(1ULL << 15)
 #define LANDLOCK_ACCESS_FS_RESOLVE_UNIX			(1ULL << 16)
+#define LANDLOCK_ACCESS_FS_READ_METADATA		(1ULL << 17)
+#define LANDLOCK_ACCESS_FS_WRITE_METADATA		(1ULL << 18)
 /* clang-format on */
 
 /**
diff --git a/security/landlock/access.h b/security/landlock/access.h
index 72afd236f883..10e7b6d35545 100644
--- a/security/landlock/access.h
+++ b/security/landlock/access.h
@@ -30,7 +30,9 @@
 /* clang-format off */
 #define _LANDLOCK_ACCESS_FS_OPTIONAL ( \
 	LANDLOCK_ACCESS_FS_TRUNCATE | \
-	LANDLOCK_ACCESS_FS_IOCTL_DEV)
+	LANDLOCK_ACCESS_FS_IOCTL_DEV | \
+	LANDLOCK_ACCESS_FS_READ_METADATA | \
+	LANDLOCK_ACCESS_FS_WRITE_METADATA)
 /* clang-format on */
 
 typedef u32 access_mask_t;
@@ -155,11 +157,12 @@ struct layer_masks {
  * required by update_request().
  *
  * Each nibble represents the layer index of the newest layer which denied a
- * certain access right.  For file system access rights, the upper four bits are
- * the index of the layer which denies LANDLOCK_ACCESS_FS_IOCTL_DEV and the
- * lower nibble represents LANDLOCK_ACCESS_FS_TRUNCATE.
+ * certain access right.  For file system access rights, the nibbles from the
+ * least to the most significant one represent the layers which deny
+ * LANDLOCK_ACCESS_FS_TRUNCATE, LANDLOCK_ACCESS_FS_IOCTL_DEV,
+ * LANDLOCK_ACCESS_FS_READ_METADATA and LANDLOCK_ACCESS_FS_WRITE_METADATA.
  */
-typedef u8 deny_masks_t;
+typedef u16 deny_masks_t;
 
 /*
  * Makes sure all optional access rights can be tied to a layer index (cf.
diff --git a/security/landlock/fs.c b/security/landlock/fs.c
index 2ab67bcad198..7d0e539b4cda 100644
--- a/security/landlock/fs.c
+++ b/security/landlock/fs.c
@@ -318,6 +318,8 @@ static struct landlock_object *get_inode_object(struct inode *const inode)
 	LANDLOCK_ACCESS_FS_EXECUTE | \
 	LANDLOCK_ACCESS_FS_WRITE_FILE | \
 	LANDLOCK_ACCESS_FS_READ_FILE | \
+	LANDLOCK_ACCESS_FS_READ_METADATA | \
+	LANDLOCK_ACCESS_FS_WRITE_METADATA | \
 	LANDLOCK_ACCESS_FS_TRUNCATE | \
 	LANDLOCK_ACCESS_FS_IOCTL_DEV | \
 	LANDLOCK_ACCESS_FS_RESOLVE_UNIX)
@@ -1676,6 +1678,195 @@ static int hook_path_truncate(const struct path *const path)
 	return current_check_access_path(path, LANDLOCK_ACCESS_FS_TRUNCATE);
 }
 
+static int check_access_file(const struct file *const file,
+			     const access_mask_t access)
+{
+	/*
+	 * O_PATH file descriptors do not go through the open permission
+	 * checks (cf. do_dentry_open()) and therefore do not carry the
+	 * access rights stashed at open time: they are checked against the
+	 * current domain, like path-based accesses.
+	 */
+	if (unlikely(file->f_mode & FMODE_PATH))
+		return current_check_access_path(&file->f_path, access);
+
+	/*
+	 * Allows accesses if the requested access right was available at the
+	 * time of opening the file, to get a consistent access check as for
+	 * read, write and execute operations.
+	 *
+	 * Note: For checks done based on the file's Landlock allowed access,
+	 * we enforce them independently of whether the current thread is in
+	 * a Landlock domain, so that open files passed between independent
+	 * processes retain their behaviour.
+	 */
+	if (landlock_file(file)->allowed_access & access)
+		return 0;
+
+	landlock_log_denial(landlock_cred(file->f_cred), &(struct landlock_request) {
+		.type = LANDLOCK_REQUEST_FS_ACCESS,
+		.audit = {
+			.type = LSM_AUDIT_DATA_FILE,
+			.u.file = file,
+		},
+		.all_existing_optional_access = _LANDLOCK_ACCESS_FS_OPTIONAL,
+		.access = access,
+#ifdef CONFIG_SECURITY_LANDLOCK_LOG
+		.deny_masks = landlock_file(file)->deny_masks,
+		.quiet_optional_accesses = landlock_file(file)->quiet_optional_accesses,
+#endif /* CONFIG_SECURITY_LANDLOCK_LOG */
+	});
+	return -EACCES;
+}
+
+static int check_access_path_or_file(const struct path *const path,
+				     const struct file *const file,
+				     const access_mask_t access)
+{
+	if (file)
+		return check_access_file(file, access);
+
+	return current_check_access_path(path, access);
+}
+
+static int hook_path_getattr(const struct path *const path,
+			     struct file *const file)
+{
+	return check_access_path_or_file(path, file,
+					 LANDLOCK_ACCESS_FS_READ_METADATA);
+}
+
+static int hook_path_file_getattr(const struct path *const path,
+				  struct file_kattr *const fa,
+				  struct file *const file)
+{
+	return check_access_path_or_file(path, file,
+					 LANDLOCK_ACCESS_FS_READ_METADATA);
+}
+
+static int hook_path_setattr(const struct mnt_idmap *const idmap,
+			     const struct path *const path,
+			     struct dentry *const dentry,
+			     struct iattr *const attr,
+			     struct file *const file)
+{
+	unsigned int ia_valid = attr->ia_valid;
+
+	/*
+	 * Only explicit metadata changes are checked: implicit
+	 * timestamp updates never go through notify_change(), and size
+	 * changes (ATTR_SIZE) are governed by the truncate hooks
+	 * instead.
+	 *
+	 * The setuid/setgid bit and file capability clearing that the
+	 * kernel performs after write(2) or truncate(2) is an implicit
+	 * change as well: it comes through __remove_privs() and
+	 * do_truncate() with ATTR_FORCE set, and do_notify_change() then
+	 * adds a synthesized ATTR_MODE (with these bits removed) before
+	 * calling this hook.  As do_notify_change() makes it a bug for
+	 * callers to pass ATTR_MODE together with a kill flag, an
+	 * ATTR_MODE seen along with ATTR_FORCE is always
+	 * kernel-synthesized and must not be checked.  An explicit
+	 * chown(2) does not set ATTR_FORCE, so the same clearing
+	 * requested through chown(2), including chown(2) with
+	 * (-1, -1) on a privileged file, is still checked through the
+	 * synthesized ATTR_MODE or the remaining ATTR_KILL_PRIV.  A
+	 * chown(2) that changes nothing (e.g. with (-1, -1) on a file
+	 * without privilege bits or file capabilities) sets neither a
+	 * changed attribute nor a kill flag, and is not checked.
+	 */
+	if (ia_valid & ATTR_FORCE)
+		ia_valid &= ~(ATTR_KILL_SUID | ATTR_KILL_SGID |
+			      ATTR_KILL_PRIV | ATTR_MODE);
+
+	if (!(ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
+			  ATTR_TIMES_SET | ATTR_TOUCH | ATTR_KILL_PRIV)))
+		return 0;
+
+	return check_access_path_or_file(path, file,
+					 LANDLOCK_ACCESS_FS_WRITE_METADATA);
+}
+
+static int hook_path_file_setattr(const struct path *const path,
+				  struct file_kattr *const fa,
+				  struct file *const file)
+{
+	/*
+	 * The chattr(2) style flags (e.g. FS_IMMUTABLE_FL) and fsxattr
+	 * fields are metadata: writing them requires WRITE_METADATA.  The
+	 * user-facing path is checked here.  Stacking filesystems that
+	 * forward the operation with their own credentials (e.g. overlayfs)
+	 * are not restricted again, unlike the ones that use the caller's
+	 * credentials (e.g. eCryptfs), which are checked on the lower path
+	 * as well.
+	 */
+	return check_access_path_or_file(path, file,
+					 LANDLOCK_ACCESS_FS_WRITE_METADATA);
+}
+
+static int hook_path_setxattr(const struct mnt_idmap *const idmap,
+			       const struct path *const path,
+			       const char *const name,
+			       const void *const value, const size_t size,
+			       const int flags,
+			       struct file *const file)
+{
+	return check_access_path_or_file(path, file,
+					 LANDLOCK_ACCESS_FS_WRITE_METADATA);
+}
+
+static int hook_path_getxattr(const struct path *const path,
+			      const char *const name,
+			      struct file *const file)
+{
+	return check_access_path_or_file(path, file,
+					 LANDLOCK_ACCESS_FS_READ_METADATA);
+}
+
+static int hook_path_listxattr(const struct path *const path,
+			       struct file *const file)
+{
+	return check_access_path_or_file(path, file,
+					 LANDLOCK_ACCESS_FS_READ_METADATA);
+}
+
+static int hook_path_removexattr(const struct mnt_idmap *const idmap,
+				  const struct path *const path,
+				  const char *const name,
+				  struct file *const file)
+{
+	return check_access_path_or_file(path, file,
+					 LANDLOCK_ACCESS_FS_WRITE_METADATA);
+}
+
+static int hook_path_set_acl(const struct mnt_idmap *const idmap,
+			      const struct path *const path,
+			      const char *const acl_name,
+			      struct posix_acl *const kacl,
+			      struct file *const file)
+{
+	return check_access_path_or_file(path, file,
+					 LANDLOCK_ACCESS_FS_WRITE_METADATA);
+}
+
+static int hook_path_get_acl(const struct mnt_idmap *const idmap,
+			      const struct path *const path,
+			      const char *const acl_name,
+			      struct file *const file)
+{
+	return check_access_path_or_file(path, file,
+					 LANDLOCK_ACCESS_FS_READ_METADATA);
+}
+
+static int hook_path_remove_acl(const struct mnt_idmap *const idmap,
+				const struct path *const path,
+				const char *const acl_name,
+				struct file *const file)
+{
+	return check_access_path_or_file(path, file,
+					 LANDLOCK_ACCESS_FS_WRITE_METADATA);
+}
+
 /**
  * unmask_scoped_access - Remove access right bits in @masks in all layers
  *                        where @client and @server have the same domain
@@ -1876,7 +2067,9 @@ static int hook_file_open(struct file *const file)
 	 * We look up more access than what we immediately need for open(), so
 	 * that we can later authorize operations on opened files.
 	 */
-	optional_access = LANDLOCK_ACCESS_FS_TRUNCATE;
+	optional_access = LANDLOCK_ACCESS_FS_TRUNCATE |
+			  LANDLOCK_ACCESS_FS_READ_METADATA |
+			  LANDLOCK_ACCESS_FS_WRITE_METADATA;
 	if (is_device(file))
 		optional_access |= LANDLOCK_ACCESS_FS_IOCTL_DEV;
 
@@ -1928,32 +2121,11 @@ static int hook_file_open(struct file *const file)
 static int hook_file_truncate(struct file *const file)
 {
 	/*
-	 * Allows truncation if the truncate right was available at the time of
-	 * opening the file, to get a consistent access check as for read, write
-	 * and execute operations.
-	 *
-	 * Note: For checks done based on the file's Landlock allowed access, we
-	 * enforce them independently of whether the current thread is in a
-	 * Landlock domain, so that open files passed between independent
-	 * processes retain their behaviour.
+	 * Allows truncation if the truncate right was available at the time
+	 * of opening the file, to get a consistent access check as for read,
+	 * write and execute operations.
 	 */
-	if (landlock_file(file)->allowed_access & LANDLOCK_ACCESS_FS_TRUNCATE)
-		return 0;
-
-	landlock_log_denial(landlock_cred(file->f_cred), &(struct landlock_request) {
-		.type = LANDLOCK_REQUEST_FS_ACCESS,
-		.audit = {
-			.type = LSM_AUDIT_DATA_FILE,
-			.u.file = file,
-		},
-		.all_existing_optional_access = _LANDLOCK_ACCESS_FS_OPTIONAL,
-		.access = LANDLOCK_ACCESS_FS_TRUNCATE,
-#ifdef CONFIG_SECURITY_LANDLOCK_LOG
-		.deny_masks = landlock_file(file)->deny_masks,
-		.quiet_optional_accesses = landlock_file(file)->quiet_optional_accesses,
-#endif /* CONFIG_SECURITY_LANDLOCK_LOG */
-	});
-	return -EACCES;
+	return check_access_file(file, LANDLOCK_ACCESS_FS_TRUNCATE);
 }
 
 static int hook_file_ioctl_common(const struct file *const file,
@@ -2100,6 +2272,17 @@ static struct security_hook_list landlock_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(path_unlink, hook_path_unlink),
 	LSM_HOOK_INIT(path_rmdir, hook_path_rmdir),
 	LSM_HOOK_INIT(path_truncate, hook_path_truncate),
+	LSM_HOOK_INIT(path_getattr, hook_path_getattr),
+	LSM_HOOK_INIT(path_file_getattr, hook_path_file_getattr),
+	LSM_HOOK_INIT(path_setattr, hook_path_setattr),
+	LSM_HOOK_INIT(path_file_setattr, hook_path_file_setattr),
+	LSM_HOOK_INIT(path_setxattr, hook_path_setxattr),
+	LSM_HOOK_INIT(path_getxattr, hook_path_getxattr),
+	LSM_HOOK_INIT(path_listxattr, hook_path_listxattr),
+	LSM_HOOK_INIT(path_removexattr, hook_path_removexattr),
+	LSM_HOOK_INIT(path_set_acl, hook_path_set_acl),
+	LSM_HOOK_INIT(path_get_acl, hook_path_get_acl),
+	LSM_HOOK_INIT(path_remove_acl, hook_path_remove_acl),
 	LSM_HOOK_INIT(unix_find, hook_unix_find),
 
 	LSM_HOOK_INIT(file_alloc_security, hook_file_alloc_security),
diff --git a/security/landlock/limits.h b/security/landlock/limits.h
index ddd300e10689..ed606ee3102f 100644
--- a/security/landlock/limits.h
+++ b/security/landlock/limits.h
@@ -21,7 +21,7 @@
 #define LANDLOCK_MAX_NUM_LAYERS		16
 #define LANDLOCK_MAX_NUM_RULES		U32_MAX
 
-#define LANDLOCK_LAST_ACCESS_FS		LANDLOCK_ACCESS_FS_RESOLVE_UNIX
+#define LANDLOCK_LAST_ACCESS_FS		LANDLOCK_ACCESS_FS_WRITE_METADATA
 #define LANDLOCK_MASK_ACCESS_FS		((LANDLOCK_LAST_ACCESS_FS << 1) - 1)
 #define LANDLOCK_NUM_ACCESS_FS		__const_hweight64(LANDLOCK_MASK_ACCESS_FS)
 
diff --git a/security/landlock/syscalls.c b/security/landlock/syscalls.c
index fb5af318b69b..11d3a2abcec1 100644
--- a/security/landlock/syscalls.c
+++ b/security/landlock/syscalls.c
@@ -191,7 +191,7 @@ static const struct file_operations ruleset_fops = {
  * If the change involves a fix that requires userspace awareness, also update
  * the errata documentation in Documentation/userspace-api/landlock.rst .
  */
-const int landlock_abi_version = 12;
+const int landlock_abi_version = 13;
 
 /**
  * sys_landlock_create_ruleset - Create a new ruleset
diff --git a/tools/testing/selftests/landlock/base_test.c b/tools/testing/selftests/landlock/base_test.c
index 89c0d96607de..14078ad203d8 100644
--- a/tools/testing/selftests/landlock/base_test.c
+++ b/tools/testing/selftests/landlock/base_test.c
@@ -76,7 +76,7 @@ TEST(abi_version)
 	const struct landlock_ruleset_attr ruleset_attr = {
 		.handled_access_fs = LANDLOCK_ACCESS_FS_READ_FILE,
 	};
-	ASSERT_EQ(12, landlock_create_ruleset(NULL, 0,
+	ASSERT_EQ(13, landlock_create_ruleset(NULL, 0,
 					      LANDLOCK_CREATE_RULESET_VERSION));
 
 	ASSERT_EQ(-1, landlock_create_ruleset(&ruleset_attr, 0,
diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
index 48c1f896dc9a..2593db7ef25c 100644
--- a/tools/testing/selftests/landlock/fs_test.c
+++ b/tools/testing/selftests/landlock/fs_test.c
@@ -571,11 +571,13 @@ TEST_F_FORK(layout1, inval)
 	LANDLOCK_ACCESS_FS_EXECUTE | \
 	LANDLOCK_ACCESS_FS_WRITE_FILE | \
 	LANDLOCK_ACCESS_FS_READ_FILE | \
+	LANDLOCK_ACCESS_FS_READ_METADATA | \
+	LANDLOCK_ACCESS_FS_WRITE_METADATA | \
 	LANDLOCK_ACCESS_FS_TRUNCATE | \
 	LANDLOCK_ACCESS_FS_IOCTL_DEV | \
 	LANDLOCK_ACCESS_FS_RESOLVE_UNIX)
 
-#define ACCESS_LAST LANDLOCK_ACCESS_FS_RESOLVE_UNIX
+#define ACCESS_LAST LANDLOCK_ACCESS_FS_WRITE_METADATA
 
 #define ACCESS_ALL ( \
 	ACCESS_FILE | \
diff --git a/tools/testing/selftests/landlock/trace_fs_test.c b/tools/testing/selftests/landlock/trace_fs_test.c
index 64014ade3a0e..97506d249c4f 100644
--- a/tools/testing/selftests/landlock/trace_fs_test.c
+++ b/tools/testing/selftests/landlock/trace_fs_test.c
@@ -252,7 +252,8 @@ TEST_F(trace_fs, add_rule_path_beneath)
 TEST_F(trace_fs, add_rule_path_beneath_escaped_path_overflow)
 {
 	static const char access_prefix[] = "execute|write_file|read_file|";
-	static const char access_suffix[] = "|ioctl_dev|resolve_unix";
+	static const char access_suffix[] =
+		"|ioctl_dev|resolve_unix|read_metadata|write_metadata";
 	struct landlock_ruleset_attr ruleset_attr = {
 		.handled_access_fs = LANDLOCK_ACCESS_FS_READ_FILE,
 	};
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 15/17] selftests/landlock: Add tests for metadata access rights
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
                   ` (13 preceding siblings ...)
  2026-11-17 15:05 ` [PATCH -next -v4 14/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 15:12   ` sashiko-bot
  2026-11-17 15:05 ` [PATCH -next -v4 16/17] samples/landlock: Add metadata rights to sandboxer Cai Xinchen
  2026-11-17 15:05 ` [PATCH -next -v4 17/17] Documentation: Update landlock doc for metadata rights Cai Xinchen
  16 siblings, 1 reply; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

Add layout1 and layout2_overlay tests for the two new rights:
unhandled_metadata, write_metadata, read_metadata, fileattr,
fileattr_write_only, metadata_open_time and metadata_transfer.  They
cover the metadata system calls, the fileattr interfaces, the open-time
semantic and the transfer of file descriptors between processes.

The file descriptor-based checks reopen their files after the ruleset is
enforced, so that the rights come from the rules rather than from
descriptors opened before the sandbox, and the chown(2) no-op tests use
the effective group ID so that they also pass as non-root.

The fallback syscall numbers for file_getattr(2) and file_setattr(2) are
overridden on alpha and MIPS, which do not use the generic numbers.

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 tools/testing/selftests/landlock/fs_test.c | 928 ++++++++++++++++++++-
 1 file changed, 922 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
index 2593db7ef25c..5dd2eeafd22a 100644
--- a/tools/testing/selftests/landlock/fs_test.c
+++ b/tools/testing/selftests/landlock/fs_test.c
@@ -26,8 +26,10 @@
 #include <sys/sendfile.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
+#include <sys/syscall.h>
 #include <sys/sysmacros.h>
 #include <sys/un.h>
+#include <sys/xattr.h>
 #include <sys/vfs.h>
 #include <unistd.h>
 
@@ -4116,12 +4118,14 @@ TEST_F_FORK(ftruncate, open_and_ftruncate_in_different_processes)
 }
 
 /* Invokes the FS_IOC_GETFLAGS IOCTL and returns its errno or 0. */
-static int test_fs_ioc_getflags_ioctl(int fd)
+static int test_fs_ioc_getflags_ioctl(int fd, unsigned int *const flags)
 {
-	uint32_t flags;
+	unsigned int flags_;
 
-	if (ioctl(fd, FS_IOC_GETFLAGS, &flags) < 0)
+	if (ioctl(fd, FS_IOC_GETFLAGS, &flags_) < 0)
 		return errno;
+	if (flags)
+		*flags = flags_;
 	return 0;
 }
 
@@ -4144,7 +4148,7 @@ TEST(memfd_ftruncate_and_ioctl)
 		 * created in ways other than open(2).
 		 */
 		EXPECT_EQ(0, test_ftruncate(fd));
-		EXPECT_EQ(0, test_fs_ioc_getflags_ioctl(fd));
+		EXPECT_EQ(0, test_fs_ioc_getflags_ioctl(fd, NULL));
 
 		ASSERT_EQ(0, close(fd));
 
@@ -4175,7 +4179,7 @@ TEST_F_FORK(layout1, o_path_ftruncate_and_ioctl)
 	ASSERT_LE(0, fd);
 
 	EXPECT_EQ(EBADF, test_ftruncate(fd));
-	EXPECT_EQ(EBADF, test_fs_ioc_getflags_ioctl(fd));
+	EXPECT_EQ(EBADF, test_fs_ioc_getflags_ioctl(fd, NULL));
 
 	ASSERT_EQ(0, close(fd));
 
@@ -4191,7 +4195,7 @@ TEST_F_FORK(layout1, o_path_ftruncate_and_ioctl)
 	ASSERT_LE(0, fd);
 
 	EXPECT_EQ(EBADF, test_ftruncate(fd));
-	EXPECT_EQ(EBADF, test_fs_ioc_getflags_ioctl(fd));
+	EXPECT_EQ(EBADF, test_fs_ioc_getflags_ioctl(fd, NULL));
 
 	ASSERT_EQ(0, close(fd));
 }
@@ -10973,4 +10977,916 @@ TEST_F(trace_layout1, check_rule_fs_empty_grant)
 	free(buf);
 }
 
+/* Invokes chmod(2) and returns its errno or 0. */
+static int test_chmod(const char *const path, mode_t mode)
+{
+	if (chmod(path, mode) < 0)
+		return errno;
+	return 0;
+}
+
+/* Invokes fchmod(2) and returns its errno or 0. */
+static int test_fchmod(int fd, mode_t mode)
+{
+	if (fchmod(fd, mode) < 0)
+		return errno;
+	return 0;
+}
+
+/* Invokes chown(2) and returns its errno or 0. */
+static int test_chown(const char *const path, uid_t uid, gid_t gid)
+{
+	if (chown(path, uid, gid) < 0)
+		return errno;
+	return 0;
+}
+
+/* Invokes fchown(2) and returns its errno or 0. */
+static int test_fchown(int fd, uid_t uid, gid_t gid)
+{
+	if (fchown(fd, uid, gid) < 0)
+		return errno;
+	return 0;
+}
+
+/* Invokes lchown(2) and returns its errno or 0. */
+static int test_lchown(const char *const path, uid_t uid, gid_t gid)
+{
+	if (lchown(path, uid, gid) < 0)
+		return errno;
+	return 0;
+}
+
+/* Timestamps used by the utimensat(2) and futimens(2) test helpers. */
+static const struct timespec test_times[] = {
+	{
+		.tv_sec = 0,
+		.tv_nsec = UTIME_OMIT,
+	},
+	{
+		.tv_sec = 1,
+		.tv_nsec = 0,
+	},
+};
+
+/* Invokes utimensat(2) with explicit times and returns its errno or 0. */
+static int test_utimensat(const char *const path)
+{
+	if (utimensat(AT_FDCWD, path, test_times, 0) < 0)
+		return errno;
+	return 0;
+}
+
+/* Invokes utimensat(2) with UTIME_NOW and returns its errno or 0. */
+static int test_utimensat_now(const char *const path)
+{
+	if (utimensat(AT_FDCWD, path, NULL, 0) < 0)
+		return errno;
+	return 0;
+}
+
+/* Invokes futimens(2) and returns its errno or 0. */
+static int test_futimens(int fd)
+{
+	if (futimens(fd, test_times) < 0)
+		return errno;
+	return 0;
+}
+
+/* Invokes setxattr(2) and returns its errno or 0. */
+static int test_setxattr(const char *const path, const char *const name,
+			 const void *const value, const size_t size)
+{
+	if (setxattr(path, name, value, size, 0) < 0)
+		return errno;
+	return 0;
+}
+
+/* Invokes getxattr(2) and returns its errno or 0. */
+static int test_getxattr(const char *const path, const char *const name,
+			 void *const value, const size_t size)
+{
+	if (getxattr(path, name, value, size) < 0)
+		return errno;
+	return 0;
+}
+
+/* Invokes listxattr(2) and returns its errno or 0. */
+static int test_listxattr(const char *const path, void *const list,
+			  const size_t size)
+{
+	if (listxattr(path, list, size) < 0)
+		return errno;
+	return 0;
+}
+
+/* Invokes removexattr(2) and returns its errno or 0. */
+static int test_removexattr(const char *const path, const char *const name)
+{
+	if (removexattr(path, name) < 0)
+		return errno;
+	return 0;
+}
+
+/* Invokes fsetxattr(2) and returns its errno or 0. */
+static int test_fsetxattr(int fd, const char *const name,
+			  const void *const value, const size_t size)
+{
+	if (fsetxattr(fd, name, value, size, 0) < 0)
+		return errno;
+	return 0;
+}
+
+/* Invokes fgetxattr(2) and returns its errno or 0. */
+static int test_fgetxattr(int fd, const char *const name, void *const value,
+			  const size_t size)
+{
+	if (fgetxattr(fd, name, value, size) < 0)
+		return errno;
+	return 0;
+}
+
+/* Invokes stat(2) and returns its errno or 0. */
+static int test_stat(const char *const path, struct stat *statbuf)
+{
+	if (stat(path, statbuf) < 0)
+		return errno;
+	return 0;
+}
+
+/* Invokes fstat(2) and returns its errno or 0. */
+static int test_fstat(int fd, struct stat *statbuf)
+{
+	if (fstat(fd, statbuf) < 0)
+		return errno;
+	return 0;
+}
+
+TEST_F(layout1, unhandled_metadata)
+{
+	int file_fd;
+	int ruleset_fd;
+	const char *const file1 = file1_s1d1;
+	const char *const file2 = file2_s1d1;
+	const char *const dir1 = dir_s1d1;
+	struct stat statbuf;
+	const struct rule rules[] = {
+		{
+			.path = file1,
+			.access = LANDLOCK_ACCESS_FS_WRITE_FILE,
+		},
+		{
+			.path = file2,
+			.access = LANDLOCK_ACCESS_FS_READ_FILE |
+				  LANDLOCK_ACCESS_FS_WRITE_FILE,
+		},
+		{
+			.path = dir1,
+			.access = ACCESS_RW,
+		},
+		{},
+	};
+
+	/*
+	 * READ_METADATA and WRITE_METADATA are not handled, so metadata
+	 * access should be allowed.
+	 */
+	ruleset_fd = create_ruleset(_metadata, ACCESS_RW, rules);
+	ASSERT_LE(0, ruleset_fd);
+
+	enforce_ruleset(_metadata, ruleset_fd);
+	ASSERT_EQ(0, close(ruleset_fd));
+
+	/*
+	 * Open the file once the domain is enforced, so that the file-based
+	 * operations below go through hook_file_open() and do not inherit the
+	 * unrestricted allowed_access of a file opened without a domain.
+	 */
+	file_fd = open(file1, O_WRONLY | O_CLOEXEC);
+	ASSERT_LE(0, file_fd);
+
+	EXPECT_EQ(0, test_chmod(file1, 0644));
+	EXPECT_EQ(0, test_fchmod(file_fd, 0644));
+	EXPECT_EQ(0, test_chmod(file2, 0400));
+	EXPECT_EQ(0, test_chmod(dir1, 0700));
+
+	EXPECT_EQ(0, test_chown(file1, -1, getegid()));
+	EXPECT_EQ(0, test_fchown(file_fd, -1, getegid()));
+	EXPECT_EQ(0, test_lchown(file1, -1, getegid()));
+
+	EXPECT_EQ(0, test_utimensat(file1));
+	EXPECT_EQ(0, test_utimensat_now(file1));
+
+	EXPECT_EQ(0, test_setxattr(file1, "user.test", "a", 1));
+	EXPECT_EQ(0, test_getxattr(file1, "user.test", NULL, 0));
+	EXPECT_EQ(0, test_listxattr(file1, NULL, 0));
+	EXPECT_EQ(0, test_removexattr(file1, "user.test"));
+
+	EXPECT_EQ(0, test_stat(file1, &statbuf));
+	EXPECT_EQ(0, test_fstat(file_fd, &statbuf));
+	EXPECT_EQ(0, test_stat(dir1, &statbuf));
+
+	ASSERT_EQ(0, close(file_fd));
+}
+
+TEST_F(layout1, write_metadata)
+{
+	int file_fd, file2_fd, trunc_fd, chown_fd;
+	int ruleset_fd;
+	const char *const file1 = file1_s1d1;
+	const char *const file2 = file2_s1d1;
+	const char *const trunc_file = file1_s1d2;
+	const char *const chown_file = file2_s1d2;
+	const char *const dir1 = dir_s1d1;
+	struct stat statbuf;
+	const struct rule rules[] = {
+		{
+			.path = file1,
+			.access = LANDLOCK_ACCESS_FS_WRITE_FILE |
+				  LANDLOCK_ACCESS_FS_READ_METADATA |
+				  LANDLOCK_ACCESS_FS_WRITE_METADATA,
+		},
+		{
+			.path = file2,
+			.access = LANDLOCK_ACCESS_FS_READ_FILE |
+				  LANDLOCK_ACCESS_FS_WRITE_FILE |
+				  LANDLOCK_ACCESS_FS_READ_METADATA,
+		},
+		{
+			.path = chown_file,
+			.access = LANDLOCK_ACCESS_FS_READ_FILE |
+				  LANDLOCK_ACCESS_FS_WRITE_FILE |
+				  LANDLOCK_ACCESS_FS_READ_METADATA,
+		},
+		{
+			.path = trunc_file,
+			.access = LANDLOCK_ACCESS_FS_READ_FILE |
+				  LANDLOCK_ACCESS_FS_WRITE_FILE |
+				  LANDLOCK_ACCESS_FS_READ_METADATA |
+				  LANDLOCK_ACCESS_FS_TRUNCATE,
+		},
+		{
+			.path = dir1,
+			.access = ACCESS_RW,
+		},
+		{},
+	};
+
+	ruleset_fd = create_ruleset(_metadata, ACCESS_RW |
+				    LANDLOCK_ACCESS_FS_READ_METADATA |
+				    LANDLOCK_ACCESS_FS_WRITE_METADATA |
+				    LANDLOCK_ACCESS_FS_TRUNCATE, rules);
+	ASSERT_LE(0, ruleset_fd);
+	file_fd = open(file1, O_WRONLY | O_CLOEXEC);
+	ASSERT_LE(0, file_fd);
+	file2_fd = open(file2, O_RDWR | O_CLOEXEC);
+	ASSERT_LE(0, file2_fd);
+	trunc_fd = open(trunc_file, O_RDWR | O_CLOEXEC);
+	ASSERT_LE(0, trunc_fd);
+	chown_fd = open(chown_file, O_RDWR | O_CLOEXEC);
+	ASSERT_LE(0, chown_fd);
+
+	/*
+	 * Arm the setuid bit for the setuid-clearing tests below:
+	 * writing or truncating a setuid file clears that bit
+	 * implicitly, which must not require WRITE_METADATA, whereas
+	 * an explicit chown(2) with (-1, -1) requests the same
+	 * clearing and must require it.  The clearing happens when
+	 * the caller has no CAP_FSETID, which is the case here
+	 * because tests run without capabilities (see disable_caps()
+	 * in prepare_layout()).
+	 */
+	ASSERT_EQ(0, fchmod(file_fd, 04666));
+	ASSERT_EQ(0, fchmod(file2_fd, 04666));
+	ASSERT_EQ(0, fchmod(trunc_fd, 04666));
+	ASSERT_EQ(0, fchmod(chown_fd, 04666));
+	/*
+	 * Closes the file descriptors opened before sandboxing: they carry
+	 * every access right because they were allocated before the
+	 * sandbox was enforced, so the assertions below would not check
+	 * the rules if they kept using them.
+	 */
+	ASSERT_EQ(0, close(file_fd));
+	ASSERT_EQ(0, close(file2_fd));
+	ASSERT_EQ(0, close(trunc_fd));
+	ASSERT_EQ(0, close(chown_fd));
+
+	enforce_ruleset(_metadata, ruleset_fd);
+	ASSERT_EQ(0, close(ruleset_fd));
+
+	/*
+	 * Reopens the files while the ruleset is enforced, so that the
+	 * rights stashed at open time come from the rules: file1 gets
+	 * WRITE_METADATA, file2 and chown_file only get READ_METADATA, and
+	 * trunc_file gets TRUNCATE but no WRITE_METADATA.
+	 */
+	file_fd = open(file1, O_WRONLY | O_CLOEXEC);
+	ASSERT_LE(0, file_fd);
+	file2_fd = open(file2, O_RDWR | O_CLOEXEC);
+	ASSERT_LE(0, file2_fd);
+	trunc_fd = open(trunc_file, O_RDWR | O_CLOEXEC);
+	ASSERT_LE(0, trunc_fd);
+	chown_fd = open(chown_file, O_RDWR | O_CLOEXEC);
+	ASSERT_LE(0, chown_fd);
+
+	/*
+	 * An explicit chown(2) with (-1, -1) on a setuid file is an
+	 * explicit request to clear the setuid bit: it requires
+	 * WRITE_METADATA, which file1 has, and clears the bit.
+	 */
+	EXPECT_EQ(0, test_fchown(file_fd, -1, -1));
+	ASSERT_EQ(0, fstat(file_fd, &statbuf));
+	EXPECT_EQ(0, statbuf.st_mode & S_ISUID);
+
+	/* file1 has WRITE_METADATA: allowed */
+	EXPECT_EQ(0, test_chmod(file1, 0644));
+	EXPECT_EQ(0, test_fchmod(file_fd, 0644));
+	EXPECT_EQ(0, test_chown(file1, -1, getegid()));
+	EXPECT_EQ(0, test_fchown(file_fd, -1, getegid()));
+	EXPECT_EQ(0, test_lchown(file1, -1, getegid()));
+	EXPECT_EQ(0, test_utimensat(file1));
+	EXPECT_EQ(0, test_utimensat_now(file1));
+	EXPECT_EQ(0, test_setxattr(file1, "user.test", "a", 1));
+	EXPECT_EQ(0, test_removexattr(file1, "user.test"));
+
+	/*
+	 * Writing is not an explicit metadata change: implicit timestamp
+	 * updates and the implicit setuid-bit clearing are allowed
+	 * without WRITE_METADATA.
+	 */
+	EXPECT_EQ(1, write(file2_fd, "a", 1));
+	ASSERT_EQ(0, fstat(file2_fd, &statbuf));
+	EXPECT_EQ(0, statbuf.st_mode & S_ISUID);
+
+	/* file2 does not have WRITE_METADATA: denied */
+	EXPECT_EQ(EACCES, test_chmod(file2, 0400));
+	EXPECT_EQ(EACCES, test_chown(file2, -1, getegid()));
+	EXPECT_EQ(EACCES, test_lchown(file2, -1, getegid()));
+	EXPECT_EQ(EACCES, test_utimensat(file2));
+	EXPECT_EQ(EACCES, test_utimensat_now(file2));
+	EXPECT_EQ(EACCES, test_setxattr(file2, "user.test", "a", 1));
+	EXPECT_EQ(EACCES, test_removexattr(file2, "user.test"));
+
+	/*
+	 * Without the WRITE_METADATA right (i.e. without the right stashed
+	 * at open time), the same explicit chown(2) with (-1, -1) is
+	 * denied and leaves the setuid bit in place.
+	 */
+	EXPECT_EQ(EACCES, test_fchown(chown_fd, -1, -1));
+	ASSERT_EQ(0, fstat(chown_fd, &statbuf));
+	EXPECT_EQ(S_ISUID, statbuf.st_mode & S_ISUID);
+
+	/* dir1 does not have WRITE_METADATA: denied */
+	EXPECT_EQ(EACCES, test_chmod(dir1, 0700));
+	EXPECT_EQ(EACCES, test_chown(dir1, -1, getegid()));
+
+	/*
+	 * Truncating a setuid file implicitly clears the setuid bit as
+	 * well: this must not require WRITE_METADATA, which trunc_file
+	 * does not have, but it does require TRUNCATE.
+	 */
+	EXPECT_EQ(0, ftruncate(trunc_fd, 0));
+	ASSERT_EQ(0, fstat(trunc_fd, &statbuf));
+	EXPECT_EQ(0, statbuf.st_mode & S_ISUID);
+
+	ASSERT_EQ(0, close(file_fd));
+	ASSERT_EQ(0, close(file2_fd));
+	ASSERT_EQ(0, close(trunc_fd));
+	ASSERT_EQ(0, close(chown_fd));
+}
+
+TEST_F(layout1, read_metadata)
+{
+	int file_fd, file2_fd, sandbox_fd;
+	int ruleset_fd;
+	const char *const file1 = file1_s1d1;
+	const char *const file2 = file2_s1d1;
+	const char *const dir1 = dir_s1d1;
+	struct stat statbuf;
+	const struct rule rules[] = {
+		{
+			.path = file1,
+			.access = LANDLOCK_ACCESS_FS_READ_FILE |
+				  LANDLOCK_ACCESS_FS_READ_METADATA,
+		},
+		{
+			.path = file2,
+			.access = LANDLOCK_ACCESS_FS_READ_FILE |
+				  LANDLOCK_ACCESS_FS_WRITE_FILE,
+		},
+		{
+			.path = dir1,
+			.access = ACCESS_RW,
+		},
+		{},
+	};
+
+	ruleset_fd = create_ruleset(_metadata, ACCESS_RW |
+				    LANDLOCK_ACCESS_FS_READ_METADATA, rules);
+	ASSERT_LE(0, ruleset_fd);
+
+	ASSERT_EQ(0, setxattr(file1, "user.test", "a", 1, 0));
+	ASSERT_EQ(0, setxattr(file2, "user.test", "a", 1, 0));
+
+	/*
+	 * A file descriptor opened before the ruleset is enforced carries
+	 * all access rights.
+	 */
+	sandbox_fd = open(file1, O_RDONLY | O_CLOEXEC);
+	ASSERT_LE(0, sandbox_fd);
+
+	enforce_ruleset(_metadata, ruleset_fd);
+	ASSERT_EQ(0, close(ruleset_fd));
+
+	/* file1 has READ_METADATA: allowed */
+	EXPECT_EQ(0, test_stat(file1, &statbuf));
+	file_fd = open(file1, O_RDONLY | O_CLOEXEC);
+	ASSERT_LE(0, file_fd);
+	EXPECT_EQ(0, test_fstat(file_fd, &statbuf));
+	EXPECT_EQ(0, test_getxattr(file1, "user.test", NULL, 0));
+	EXPECT_EQ(0, test_listxattr(file1, NULL, 0));
+
+	/*
+	 * Reading metadata through the file descriptor opened before
+	 * sandboxing is still allowed.
+	 */
+	EXPECT_EQ(0, test_fstat(sandbox_fd, &statbuf));
+	ASSERT_EQ(0, close(sandbox_fd));
+
+	/*
+	 * file2 does not have READ_METADATA: denied, both through the path
+	 * and through a file descriptor opened while the ruleset is
+	 * enforced.
+	 */
+	EXPECT_EQ(EACCES, test_stat(file2, &statbuf));
+	file2_fd = open(file2, O_RDONLY | O_CLOEXEC);
+	ASSERT_LE(0, file2_fd);
+	EXPECT_EQ(EACCES, test_fstat(file2_fd, &statbuf));
+	EXPECT_EQ(EACCES, test_fgetxattr(file2_fd, "user.test", NULL, 0));
+	ASSERT_EQ(0, close(file2_fd));
+	EXPECT_EQ(EACCES, test_getxattr(file2, "user.test", NULL, 0));
+	EXPECT_EQ(EACCES, test_listxattr(file2, NULL, 0));
+	/* dir1 does not have READ_METADATA: denied */
+	EXPECT_EQ(EACCES, test_stat(dir1, &statbuf));
+
+	ASSERT_EQ(0, close(file_fd));
+}
+
+/* Invokes ioctl(FS_IOC_SETFLAGS) and returns its errno or 0. */
+static int test_setflags(int fd, const unsigned int flags)
+{
+	unsigned int flags_ = flags;
+
+	if (ioctl(fd, FS_IOC_SETFLAGS, &flags_) < 0)
+		return errno;
+	return 0;
+}
+
+#ifndef __NR_file_getattr
+#if defined(__alpha__)
+#define __NR_file_getattr 578
+#elif defined(__mips__)
+#define __NR_file_getattr (__NR_Linux + 468)
+#else
+#define __NR_file_getattr 468
+#endif
+#endif
+#ifndef __NR_file_setattr
+#if defined(__alpha__)
+#define __NR_file_setattr 579
+#elif defined(__mips__)
+#define __NR_file_setattr (__NR_Linux + 469)
+#else
+#define __NR_file_setattr 469
+#endif
+#endif
+
+/* Invokes file_getattr(2) and returns its errno or 0. */
+static int test_file_getattr(int dfd, const char *const path,
+			     struct file_attr *const fattr,
+			     const unsigned int at_flags)
+{
+	if (syscall(__NR_file_getattr, dfd, path, fattr, sizeof(*fattr),
+		    at_flags) < 0)
+		return errno;
+	return 0;
+}
+
+/* Invokes file_setattr(2) and returns its errno or 0. */
+static int test_file_setattr(int dfd, const char *const path,
+			     struct file_attr *const fattr,
+			     const unsigned int at_flags)
+{
+	if (syscall(__NR_file_setattr, dfd, path, fattr, sizeof(*fattr),
+		    at_flags) < 0)
+		return errno;
+	return 0;
+}
+
+TEST_F(layout1, fileattr)
+{
+	const struct rule rules[] = {
+		{
+			.path = file1_s1d1,
+			.access = LANDLOCK_ACCESS_FS_READ_METADATA |
+				  LANDLOCK_ACCESS_FS_WRITE_METADATA,
+		},
+		{},
+	};
+	struct file_attr fattr;
+	unsigned int flags;
+	int fd, fd2, ruleset_fd;
+
+	ruleset_fd = create_ruleset(
+		_metadata,
+		LANDLOCK_ACCESS_FS_READ_METADATA |
+			LANDLOCK_ACCESS_FS_WRITE_METADATA,
+		rules);
+	ASSERT_LE(0, ruleset_fd);
+
+	enforce_ruleset(_metadata, ruleset_fd);
+	ASSERT_EQ(0, close(ruleset_fd));
+
+	/*
+	 * The file descriptor is opened while the ruleset is enforced, so it
+	 * carries the metadata rights granted by the rule.
+	 */
+	fd = open(file1_s1d1, O_RDONLY | O_CLOEXEC);
+	ASSERT_LE(0, fd);
+
+	/* Allowed file: FS_IOC_GETFLAGS */
+	flags = 0;
+	EXPECT_EQ(0, test_fs_ioc_getflags_ioctl(fd, &flags));
+	EXPECT_EQ(0, flags & FS_NODUMP_FL);
+
+	/* Allowed file: FS_IOC_SETFLAGS */
+	EXPECT_EQ(0, test_setflags(fd, FS_NODUMP_FL));
+	flags = 0;
+	EXPECT_EQ(0, test_fs_ioc_getflags_ioctl(fd, &flags));
+	EXPECT_EQ(FS_NODUMP_FL, flags & FS_NODUMP_FL);
+	EXPECT_EQ(0, test_setflags(fd, 0));
+
+	/* Allowed file: file_getattr(2), with a path and with AT_EMPTY_PATH */
+	memset(&fattr, 0, sizeof(fattr));
+	EXPECT_EQ(0, test_file_getattr(AT_FDCWD, file1_s1d1, &fattr, 0));
+	EXPECT_EQ(0, fattr.fa_xflags & FS_XFLAG_NODUMP);
+	memset(&fattr, 0, sizeof(fattr));
+	EXPECT_EQ(0, test_file_getattr(fd, NULL, &fattr, AT_EMPTY_PATH));
+
+	/* Allowed file: file_setattr(2), with a path and with AT_EMPTY_PATH */
+	memset(&fattr, 0, sizeof(fattr));
+	fattr.fa_xflags = FS_XFLAG_NODUMP;
+	EXPECT_EQ(0, test_file_setattr(AT_FDCWD, file1_s1d1, &fattr, 0));
+	memset(&fattr, 0, sizeof(fattr));
+	EXPECT_EQ(0, test_file_getattr(AT_FDCWD, file1_s1d1, &fattr, 0));
+	EXPECT_EQ(FS_XFLAG_NODUMP, fattr.fa_xflags & FS_XFLAG_NODUMP);
+	memset(&fattr, 0, sizeof(fattr));
+	fattr.fa_xflags = 0;
+	EXPECT_EQ(0, test_file_setattr(fd, NULL, &fattr, AT_EMPTY_PATH));
+
+	/* Non-allowed file: FS_IOC_GETFLAGS and FS_IOC_SETFLAGS */
+	fd2 = open(file2_s1d1, O_RDONLY | O_CLOEXEC);
+	ASSERT_LE(0, fd2);
+	EXPECT_EQ(EACCES, test_fs_ioc_getflags_ioctl(fd2, &flags));
+	EXPECT_EQ(EACCES, test_setflags(fd2, FS_NODUMP_FL));
+
+	/* Non-allowed file: file_getattr(2) and file_setattr(2) */
+	memset(&fattr, 0, sizeof(fattr));
+	EXPECT_EQ(EACCES, test_file_getattr(AT_FDCWD, file2_s1d1, &fattr, 0));
+	fattr.fa_xflags = FS_XFLAG_NODUMP;
+	EXPECT_EQ(EACCES, test_file_setattr(AT_FDCWD, file2_s1d1, &fattr, 0));
+	memset(&fattr, 0, sizeof(fattr));
+	EXPECT_EQ(EACCES, test_file_getattr(fd2, NULL, &fattr, AT_EMPTY_PATH));
+	fattr.fa_xflags = FS_XFLAG_NODUMP;
+	EXPECT_EQ(EACCES, test_file_setattr(fd2, NULL, &fattr, AT_EMPTY_PATH));
+
+	ASSERT_EQ(0, close(fd));
+	ASSERT_EQ(0, close(fd2));
+}
+
+TEST_F(layout1, fileattr_write_only)
+{
+	const struct rule rules[] = {
+		{
+			.path = file1_s1d1,
+			.access = LANDLOCK_ACCESS_FS_WRITE_METADATA,
+		},
+		{},
+	};
+	struct file_attr fattr;
+	unsigned int flags;
+	int fd, fd2, ruleset_fd;
+
+	ruleset_fd = create_ruleset(_metadata,
+				    LANDLOCK_ACCESS_FS_WRITE_METADATA, rules);
+	ASSERT_LE(0, ruleset_fd);
+
+	enforce_ruleset(_metadata, ruleset_fd);
+	ASSERT_EQ(0, close(ruleset_fd));
+
+	/*
+	 * The file descriptor is opened while WRITE_METADATA is handled but
+	 * READ_METADATA is not, so it carries WRITE_METADATA and the
+	 * unrestricted READ_METADATA of that time.
+	 */
+	fd = open(file1_s1d1, O_RDONLY | O_CLOEXEC);
+	ASSERT_LE(0, fd);
+
+	/*
+	 * WRITE_METADATA alone must be enough to set flags: the kernel-side
+	 * read of the old flags must not require READ_METADATA.
+	 */
+	EXPECT_EQ(0, test_setflags(fd, FS_NODUMP_FL));
+	flags = 0;
+	/* READ_METADATA is not handled: reading is allowed. */
+	EXPECT_EQ(0, test_fs_ioc_getflags_ioctl(fd, &flags));
+	EXPECT_EQ(FS_NODUMP_FL, flags & FS_NODUMP_FL);
+
+	/*
+	 * Handle READ_METADATA as well, without granting it.  Reading is
+	 * now denied for file descriptors opened from now on, but writing
+	 * must still work because the kernel-side read of the old flags
+	 * does not go through the READ_METADATA check.
+	 */
+	ruleset_fd = create_ruleset(
+		_metadata,
+		LANDLOCK_ACCESS_FS_READ_METADATA |
+			LANDLOCK_ACCESS_FS_WRITE_METADATA,
+		rules);
+	ASSERT_LE(0, ruleset_fd);
+	enforce_ruleset(_metadata, ruleset_fd);
+	ASSERT_EQ(0, close(ruleset_fd));
+
+	fd2 = open(file1_s1d1, O_RDONLY | O_CLOEXEC);
+	ASSERT_LE(0, fd2);
+	EXPECT_EQ(EACCES, test_fs_ioc_getflags_ioctl(fd2, &flags));
+	memset(&fattr, 0, sizeof(fattr));
+	EXPECT_EQ(EACCES,
+		  test_file_getattr(fd2, NULL, &fattr, AT_EMPTY_PATH));
+
+	EXPECT_EQ(0, test_setflags(fd2, 0));
+	memset(&fattr, 0, sizeof(fattr));
+	fattr.fa_xflags = FS_XFLAG_NODUMP;
+	EXPECT_EQ(0, test_file_setattr(fd2, NULL, &fattr, AT_EMPTY_PATH));
+	memset(&fattr, 0, sizeof(fattr));
+	fattr.fa_xflags = 0;
+	EXPECT_EQ(0, test_file_setattr(fd2, NULL, &fattr, AT_EMPTY_PATH));
+
+	/*
+	 * Reading through the file descriptor opened before READ_METADATA
+	 * was handled is still allowed: it carries the rights of the time
+	 * it was opened with.
+	 */
+	EXPECT_EQ(0, test_fs_ioc_getflags_ioctl(fd, &flags));
+
+	ASSERT_EQ(0, close(fd));
+	ASSERT_EQ(0, close(fd2));
+}
+
+TEST_F(layout1, metadata_open_time)
+{
+	int file_fd, opath_fd, ruleset_fd;
+	struct stat statbuf;
+	unsigned int flags;
+	struct file_attr fattr;
+	const char *const file1 = file1_s1d1;
+	const struct rule rules[] = {
+		{
+			.path = file1,
+			.access = LANDLOCK_ACCESS_FS_READ_FILE |
+				  LANDLOCK_ACCESS_FS_WRITE_FILE,
+		},
+		{},
+	};
+
+	ruleset_fd = create_ruleset(_metadata, ACCESS_RW |
+				    LANDLOCK_ACCESS_FS_READ_METADATA |
+				    LANDLOCK_ACCESS_FS_WRITE_METADATA,
+				    rules);
+	ASSERT_LE(0, ruleset_fd);
+
+	/*
+	 * A file descriptor opened before the ruleset is enforced carries
+	 * all access rights: metadata accesses through it remain allowed
+	 * even though the current thread cannot access the file's metadata
+	 * anymore.
+	 */
+	file_fd = open(file1, O_RDWR | O_CLOEXEC);
+	ASSERT_LE(0, file_fd);
+
+	enforce_ruleset(_metadata, ruleset_fd);
+	ASSERT_EQ(0, close(ruleset_fd));
+
+	EXPECT_EQ(0, test_fchmod(file_fd, 0600));
+	EXPECT_EQ(0, test_fchown(file_fd, -1, getegid()));
+	EXPECT_EQ(0, test_futimens(file_fd));
+	EXPECT_EQ(0, test_fstat(file_fd, &statbuf));
+	EXPECT_EQ(0, test_fs_ioc_getflags_ioctl(file_fd, &flags));
+	EXPECT_EQ(0, test_fsetxattr(file_fd, "user.test", "a", 1));
+	EXPECT_EQ(0, test_fgetxattr(file_fd, "user.test", NULL, 0));
+	memset(&fattr, 0, sizeof(fattr));
+	EXPECT_EQ(0,
+		  test_file_getattr(file_fd, NULL, &fattr, AT_EMPTY_PATH));
+	memset(&fattr, 0, sizeof(fattr));
+	fattr.fa_xflags = FS_XFLAG_NODUMP;
+	EXPECT_EQ(0,
+		  test_file_setattr(file_fd, NULL, &fattr, AT_EMPTY_PATH));
+	memset(&fattr, 0, sizeof(fattr));
+	fattr.fa_xflags = 0;
+	EXPECT_EQ(0,
+		  test_file_setattr(file_fd, NULL, &fattr, AT_EMPTY_PATH));
+
+	/* Path-based accesses use the rights of the current thread. */
+	EXPECT_EQ(EACCES, test_chmod(file1, 0644));
+	EXPECT_EQ(EACCES, test_chown(file1, -1, getegid()));
+	EXPECT_EQ(EACCES, test_utimensat(file1));
+	EXPECT_EQ(EACCES, test_stat(file1, &statbuf));
+	EXPECT_EQ(EACCES, test_setxattr(file1, "user.test", "a", 1));
+	EXPECT_EQ(EACCES, test_getxattr(file1, "user.test", NULL, 0));
+
+	ASSERT_EQ(0, close(file_fd));
+
+	/*
+	 * A file descriptor opened while the ruleset is enforced only
+	 * carries the rights granted to the file: metadata accesses
+	 * through it are denied, but data accesses still work.
+	 */
+	file_fd = open(file1, O_RDWR | O_CLOEXEC);
+	ASSERT_LE(0, file_fd);
+
+	EXPECT_EQ(EACCES, test_fchmod(file_fd, 0600));
+	EXPECT_EQ(EACCES, test_fchown(file_fd, -1, getegid()));
+	EXPECT_EQ(EACCES, test_futimens(file_fd));
+	EXPECT_EQ(EACCES, test_fstat(file_fd, &statbuf));
+	EXPECT_EQ(EACCES, test_fs_ioc_getflags_ioctl(file_fd, &flags));
+	EXPECT_EQ(EACCES, test_fsetxattr(file_fd, "user.test", "a", 1));
+	EXPECT_EQ(EACCES, test_fgetxattr(file_fd, "user.test", NULL, 0));
+	memset(&fattr, 0, sizeof(fattr));
+	EXPECT_EQ(EACCES,
+		  test_file_getattr(file_fd, NULL, &fattr, AT_EMPTY_PATH));
+	memset(&fattr, 0, sizeof(fattr));
+	fattr.fa_xflags = FS_XFLAG_NODUMP;
+	EXPECT_EQ(EACCES,
+		  test_file_setattr(file_fd, NULL, &fattr, AT_EMPTY_PATH));
+
+	EXPECT_EQ(0, lseek(file_fd, 0, SEEK_SET));
+	EXPECT_EQ(1, write(file_fd, "a", 1));
+
+	/*
+	 * An O_PATH file descriptor does not carry open-time rights: it is
+	 * checked against the current domain, like path-based accesses.
+	 */
+	opath_fd = open(file1, O_PATH | O_CLOEXEC);
+	ASSERT_LE(0, opath_fd);
+	EXPECT_EQ(EACCES, test_fstat(opath_fd, &statbuf));
+
+	ASSERT_EQ(0, close(file_fd));
+	ASSERT_EQ(0, close(opath_fd));
+}
+
+TEST_F(layout1, metadata_transfer)
+{
+	int child, fd, status;
+	int socket_fds[2];
+	struct stat statbuf;
+	unsigned int flags;
+	const char *const file1 = file1_s1d1;
+	const struct rule rules[] = {
+		{
+			.path = file1,
+			.access = LANDLOCK_ACCESS_FS_READ_FILE |
+				  LANDLOCK_ACCESS_FS_WRITE_FILE,
+		},
+		{},
+	};
+
+	ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0,
+				socket_fds));
+
+	child = fork();
+	ASSERT_LE(0, child);
+	if (child == 0) {
+		/*
+		 * Enables Landlock in the child process, opens a file
+		 * descriptor without the metadata access rights and sends it
+		 * to the non-landlocked parent process.
+		 */
+		int fd;
+
+		enforce_fs(_metadata, ACCESS_RW |
+					  LANDLOCK_ACCESS_FS_READ_METADATA |
+					  LANDLOCK_ACCESS_FS_WRITE_METADATA,
+			   rules);
+
+		fd = open(file1, O_RDWR | O_CLOEXEC);
+		ASSERT_LE(0, fd);
+		ASSERT_EQ(0, send_fd(socket_fds[0], fd));
+		ASSERT_EQ(0, close(fd));
+		ASSERT_EQ(0, close(socket_fds[0]));
+
+		_exit(_metadata->exit_code);
+		return;
+	}
+
+	/*
+	 * The non-landlocked parent process can use the received file
+	 * descriptor for data accesses, but its metadata accesses are
+	 * still denied with the rights stashed at open time.
+	 */
+	fd = recv_fd(socket_fds[1]);
+	ASSERT_LE(0, fd);
+	EXPECT_EQ(1, write(fd, "a", 1));
+	EXPECT_EQ(EACCES, test_fchmod(fd, 0600));
+	EXPECT_EQ(EACCES, test_fchown(fd, -1, getegid()));
+	EXPECT_EQ(EACCES, test_futimens(fd));
+	EXPECT_EQ(EACCES, test_fstat(fd, &statbuf));
+	EXPECT_EQ(EACCES, test_fs_ioc_getflags_ioctl(fd, &flags));
+	ASSERT_EQ(0, close(fd));
+
+	ASSERT_EQ(child, waitpid(child, &status, 0));
+	ASSERT_EQ(1, WIFEXITED(status));
+	ASSERT_EQ(EXIT_SUCCESS, WEXITSTATUS(status));
+
+	ASSERT_EQ(0, close(socket_fds[0]));
+	ASSERT_EQ(0, close(socket_fds[1]));
+}
+
+TEST_F(layout2_overlay, fileattr)
+{
+	const struct rule rules[] = {
+		{
+			.path = MERGE_DATA,
+			.access = LANDLOCK_ACCESS_FS_READ_METADATA |
+				  LANDLOCK_ACCESS_FS_WRITE_METADATA,
+		},
+		{},
+	};
+	struct file_attr fattr;
+	unsigned int flags;
+	int fd, fd2, ruleset_fd;
+
+	if (self->skip_test)
+		SKIP(return, "overlayfs is not supported (test)");
+
+	ruleset_fd = create_ruleset(
+		_metadata,
+		LANDLOCK_ACCESS_FS_READ_METADATA |
+			LANDLOCK_ACCESS_FS_WRITE_METADATA,
+		rules);
+	ASSERT_LE(0, ruleset_fd);
+
+	enforce_ruleset(_metadata, ruleset_fd);
+	ASSERT_EQ(0, close(ruleset_fd));
+
+	/*
+	 * The overlay mount was created before the ruleset was enforced
+	 * (i.e. as an administrator): the internal forwards to the real
+	 * paths must not interfere with the allowed accesses below.
+	 */
+	fd = open(merge_fl1, O_RDONLY | O_CLOEXEC);
+	ASSERT_LE(0, fd);
+
+	flags = 0;
+	EXPECT_EQ(0, test_fs_ioc_getflags_ioctl(fd, &flags));
+	EXPECT_EQ(0, flags & FS_NODUMP_FL);
+	/* Copies the file up and sets the flag on the upper real file. */
+	EXPECT_EQ(0, test_setflags(fd, FS_NODUMP_FL));
+	flags = 0;
+	EXPECT_EQ(0, test_fs_ioc_getflags_ioctl(fd, &flags));
+	EXPECT_EQ(FS_NODUMP_FL, flags & FS_NODUMP_FL);
+	EXPECT_EQ(0, test_setflags(fd, 0));
+
+	/* Allowed file: file_getattr(2) and file_setattr(2) */
+	memset(&fattr, 0, sizeof(fattr));
+	EXPECT_EQ(0, test_file_getattr(AT_FDCWD, merge_fl1, &fattr, 0));
+	memset(&fattr, 0, sizeof(fattr));
+	fattr.fa_xflags = FS_XFLAG_NODUMP;
+	EXPECT_EQ(0, test_file_setattr(AT_FDCWD, merge_fl1, &fattr, 0));
+	memset(&fattr, 0, sizeof(fattr));
+	EXPECT_EQ(0, test_file_getattr(AT_FDCWD, merge_fl1, &fattr, 0));
+	EXPECT_EQ(FS_XFLAG_NODUMP, fattr.fa_xflags & FS_XFLAG_NODUMP);
+	memset(&fattr, 0, sizeof(fattr));
+	EXPECT_EQ(0, test_file_getattr(fd, NULL, &fattr, AT_EMPTY_PATH));
+	memset(&fattr, 0, sizeof(fattr));
+	fattr.fa_xflags = 0;
+	EXPECT_EQ(0, test_file_setattr(fd, NULL, &fattr, AT_EMPTY_PATH));
+
+	ASSERT_EQ(0, close(fd));
+
+	/* Non-allowed path: raw lower tmpfs path, outside of MERGE_DATA. */
+	fd2 = open(lower_fl1, O_RDONLY | O_CLOEXEC);
+	ASSERT_LE(0, fd2);
+	EXPECT_EQ(EACCES, test_fs_ioc_getflags_ioctl(fd2, &flags));
+	EXPECT_EQ(EACCES, test_setflags(fd2, FS_NODUMP_FL));
+	memset(&fattr, 0, sizeof(fattr));
+	EXPECT_EQ(EACCES, test_file_getattr(AT_FDCWD, lower_fl1, &fattr, 0));
+	memset(&fattr, 0, sizeof(fattr));
+	EXPECT_EQ(EACCES,
+		  test_file_getattr(fd2, NULL, &fattr, AT_EMPTY_PATH));
+	memset(&fattr, 0, sizeof(fattr));
+	fattr.fa_xflags = FS_XFLAG_NODUMP;
+	EXPECT_EQ(EACCES, test_file_setattr(AT_FDCWD, lower_fl1, &fattr, 0));
+	ASSERT_EQ(0, close(fd2));
+}
+
 TEST_HARNESS_MAIN
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 16/17] samples/landlock: Add metadata rights to sandboxer
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
                   ` (14 preceding siblings ...)
  2026-11-17 15:05 ` [PATCH -next -v4 15/17] selftests/landlock: Add tests for metadata " Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 15:04   ` sashiko-bot
  2026-11-17 15:05 ` [PATCH -next -v4 17/17] Documentation: Update landlock doc for metadata rights Cai Xinchen
  16 siblings, 1 reply; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

Handle the two new access rights in the sandboxer: READ_METADATA joins
the read-only set, WRITE_METADATA the read-write set, and both join
ACCESS_FILE.  Bump LANDLOCK_ABI_LAST to 13 and remove the rights for
ABI < 13 in the fallback switch.

Update the trace example in events-landlock.rst accordingly.

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 Documentation/trace/events-landlock.rst | 18 ++++++++++--------
 samples/landlock/sandboxer.c            | 16 +++++++++++++---
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/Documentation/trace/events-landlock.rst b/Documentation/trace/events-landlock.rst
index dc5f05a17c2c..f415eaa0eabf 100644
--- a/Documentation/trace/events-landlock.rst
+++ b/Documentation/trace/events-landlock.rst
@@ -88,7 +88,7 @@ Landlock, not from regular file permissions::
   $ LC_ALL=C LL_FS_RO=/usr:/lib:/lib64:/bin:/etc/ld.so.cache LL_FS_RW=/tmp \
       ./sandboxer cat /etc/passwd
   $ cat /sys/kernel/tracing/trace_pipe
-  cat-127 [...] landlock_create_ruleset: ruleset=195cc6b76.0 handled_fs=execute|write_file|read_file|read_dir|remove_dir|remove_file|make_char|make_dir|make_reg|make_sock|make_fifo|make_block|make_sym|refer|truncate|ioctl_dev|resolve_unix handled_net= scoped= handled_permissions=
+  cat-127 [...] landlock_create_ruleset: ruleset=195cc6b76.0 handled_fs=execute|write_file|read_file|read_dir|remove_dir|remove_file|make_char|make_dir|make_reg|make_sock|make_fifo|make_block|make_sym|refer|truncate|ioctl_dev|resolve_unix|read_metadata|write_metadata handled_net= scoped= handled_permissions=
   cat-127 [...] landlock_create_domain: domain=195cc6b7c parent=0 ruleset=195cc6b76.6
   cat-127 [...] landlock_enforce_domain: domain=195cc6b7c complete=1 process_wide=1 no_new_privs=1
   cat-127 [...] landlock_deny_access_fs: domain=195cc6b7c same_exec=0 logged=0 blockers=read_file dev=0:17 ino=5901179 path=/etc/passwd
@@ -279,20 +279,22 @@ For example, a program sandboxed with read and execute access to the
 whole filesystem reads ``/etc/passwd``; both the ``execve()`` and the
 read match the rule covering ``/`` (inode 2), so ``check_rule_inode`` fires
 with the requested rights intersected against what that rule grants.
-The ``access_request=`` mask includes ``truncate`` because the file-open hook
-evaluates that optional right alongside the required access, but the
-rule does not grant it, so ``truncate`` never appears in ``grants=``::
+The ``access_request=`` mask includes ``truncate``, ``read_metadata`` and
+``write_metadata`` because the file-open hook evaluates those optional rights
+alongside the required access.  The read-only rule grants ``read_metadata``,
+so it appears in ``grants=``, while ``truncate`` and ``write_metadata`` are
+not granted and therefore do not::
 
-  cat-127 [...] landlock_check_rule_inode: domain=1e40cb56f access_request=execute|read_file|truncate dev=0:17 ino=2 grants={execute|read_file}
-  cat-127 [...] landlock_check_rule_inode: domain=1e40cb56f access_request=read_file|truncate dev=0:17 ino=2 grants={read_file}
+  cat-127 [...] landlock_check_rule_inode: domain=1e40cb56f access_request=execute|read_file|truncate|read_metadata|write_metadata dev=0:17 ino=2 grants={execute|read_file|read_metadata}
+  cat-127 [...] landlock_check_rule_inode: domain=1e40cb56f access_request=read_file|truncate|read_metadata|write_metadata dev=0:17 ino=2 grants={read_file|read_metadata}
 
 The ``[...]`` replaces the ftrace CPU, flags, and timestamp columns.  A
 single ``grants=`` group means the enforcing domain has one layer.  With
 two nested sandboxes that each grant the same rights, the rule spans both
 layers, so ``grants=`` has one group per layer::
 
-  cat-128 [...] landlock_check_rule_inode: domain=184788b52 access_request=execute|read_file|truncate dev=0:17 ino=2 grants={execute|read_file,execute|read_file}
-  cat-128 [...] landlock_check_rule_inode: domain=184788b52 access_request=read_file|truncate dev=0:17 ino=2 grants={read_file,read_file}
+  cat-128 [...] landlock_check_rule_inode: domain=184788b52 access_request=execute|read_file|truncate|read_metadata|write_metadata dev=0:17 ino=2 grants={execute|read_file|read_metadata,execute|read_file|read_metadata}
+  cat-128 [...] landlock_check_rule_inode: domain=184788b52 access_request=read_file|truncate|read_metadata|write_metadata dev=0:17 ino=2 grants={read_file|read_metadata,read_file|read_metadata}
 
 eBPF access
 ===========
diff --git a/samples/landlock/sandboxer.c b/samples/landlock/sandboxer.c
index 1362f08ff14b..29965ef90bed 100644
--- a/samples/landlock/sandboxer.c
+++ b/samples/landlock/sandboxer.c
@@ -137,6 +137,8 @@ static int parse_path(char *env_path, const char ***const path_list)
 	LANDLOCK_ACCESS_FS_EXECUTE | \
 	LANDLOCK_ACCESS_FS_WRITE_FILE | \
 	LANDLOCK_ACCESS_FS_READ_FILE | \
+	LANDLOCK_ACCESS_FS_READ_METADATA | \
+	LANDLOCK_ACCESS_FS_WRITE_METADATA | \
 	LANDLOCK_ACCESS_FS_TRUNCATE | \
 	LANDLOCK_ACCESS_FS_IOCTL_DEV | \
 	LANDLOCK_ACCESS_FS_RESOLVE_UNIX)
@@ -487,7 +489,8 @@ static bool check_ruleset_scope(const char *const env_var,
 #define ACCESS_FS_ROUGHLY_READ ( \
 	LANDLOCK_ACCESS_FS_EXECUTE | \
 	LANDLOCK_ACCESS_FS_READ_FILE | \
-	LANDLOCK_ACCESS_FS_READ_DIR)
+	LANDLOCK_ACCESS_FS_READ_DIR | \
+	LANDLOCK_ACCESS_FS_READ_METADATA)
 
 #define ACCESS_FS_ROUGHLY_WRITE ( \
 	LANDLOCK_ACCESS_FS_WRITE_FILE | \
@@ -503,7 +506,8 @@ static bool check_ruleset_scope(const char *const env_var,
 	LANDLOCK_ACCESS_FS_REFER | \
 	LANDLOCK_ACCESS_FS_TRUNCATE | \
 	LANDLOCK_ACCESS_FS_IOCTL_DEV | \
-	LANDLOCK_ACCESS_FS_RESOLVE_UNIX)
+	LANDLOCK_ACCESS_FS_RESOLVE_UNIX | \
+	LANDLOCK_ACCESS_FS_WRITE_METADATA)
 
 /* clang-format on */
 
@@ -570,7 +574,7 @@ static int add_quiet_access(const char *const env_var,
 	return 0;
 }
 
-#define LANDLOCK_ABI_LAST 12
+#define LANDLOCK_ABI_LAST 13
 
 #define XSTR(s) #s
 #define STR(s) XSTR(s)
@@ -780,6 +784,12 @@ int main(const int argc, char *const argv[], char *const *const envp)
 		ruleset_attr.handled_permissions &=
 			~(LANDLOCK_PERMISSION_NAMESPACE_USE |
 			  LANDLOCK_PERMISSION_CAPABILITY_USE);
+		__attribute__((fallthrough));
+	case 12:
+		/* Removes metadata rights for ABI < 13 */
+		ruleset_attr.handled_access_fs &=
+			~(LANDLOCK_ACCESS_FS_READ_METADATA |
+			  LANDLOCK_ACCESS_FS_WRITE_METADATA);
 		/* Must be printed for any ABI < LANDLOCK_ABI_LAST. */
 		fprintf(stderr,
 			"Hint: You should update the running kernel "
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [PATCH -next -v4 17/17] Documentation: Update landlock doc for metadata rights
  2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
                   ` (15 preceding siblings ...)
  2026-11-17 15:05 ` [PATCH -next -v4 16/17] samples/landlock: Add metadata rights to sandboxer Cai Xinchen
@ 2026-11-17 15:05 ` Cai Xinchen
  2026-11-17 15:05   ` sashiko-bot
  16 siblings, 1 reply; 38+ messages in thread
From: Cai Xinchen @ 2026-11-17 15:05 UTC (permalink / raw)
  To: mic, gnoack, paul, brauner, jack, caixinchen1
  Cc: amir73il, andrii, apparmor, ast, axboe, bpf, casey, cel, cem,
	chenxiaosong, code, corbet, Dai.Ngo, dakr, daniel, dhowells,
	dlemoal, dmitry.kasatkin, driver-core, dsterba, ecryptfs, eddyz87,
	emil, eric.snowberg, exfat, georgia.garcia, gregkh, hch, hirofumi,
	hyc.lee, ihor.solodrai, jlayton, jmorris, johan, john.fastabend,
	john.johansen, jolsa, kpsingh, linkinjeon, linux-api, linux-block,
	linux-btrfs, linux-cifs, linux-doc, linux-fsdevel,
	linux-integrity, linux-kernel, linux-kselftest, linux-nfs,
	linux-security-module, linux-trace-kernel, linux-unionfs,
	linux-xfs, liubaolin12138, martin.lau, mason, mathieu.desnoyers,
	matt, memxor, mhiramat, miklos, neil, netfs, ntfs, okorniev,
	omosnacek, penguin-kernel, rafael, rdunlap, roberto.sassu,
	rostedt, selinux, senozhatsky, serge, sj1557.seo, skhan, song,
	stephen.smalley.work, takedakn, tom, viro, yonghong.song,
	yuezhang.mo, zohar, utilityemal77, lujialin4

Document the two new access rights: add them to the example ruleset and
to the ABI fallback switch, and describe their semantics in a new "File
metadata" section, including the open-time semantic, the exclusion of
implicit changes and the chown(2) special case, and the warning that
READ_METADATA usually needs to be granted together with READ_FILE and
READ_DIR.

Also rename the "Bind mounts and OverlayFS" section to "Bind mounts and
stacking filesystems" and describe how eCryptfs forwards attribute
changes under the caller's credentials, which causes the lower path to be
checked as well, and extend the blockers list in
Documentation/admin-guide/LSM/landlock.rst.

Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
 Documentation/admin-guide/LSM/landlock.rst |   2 +
 Documentation/userspace-api/landlock.rst   | 148 ++++++++++++++++++---
 2 files changed, 135 insertions(+), 15 deletions(-)

diff --git a/Documentation/admin-guide/LSM/landlock.rst b/Documentation/admin-guide/LSM/landlock.rst
index 946f3bf89650..86f8c7cbdacb 100644
--- a/Documentation/admin-guide/LSM/landlock.rst
+++ b/Documentation/admin-guide/LSM/landlock.rst
@@ -56,6 +56,8 @@ AUDIT_LANDLOCK_ACCESS
         - fs.truncate (ABI 3+)
         - fs.ioctl_dev (ABI 5+)
         - fs.resolve_unix (ABI 9+)
+        - fs.read_metadata (ABI 13+)
+        - fs.write_metadata (ABI 13+)
 
     **net.*** - Network access rights (ABI 4+):
         - net.bind_tcp - TCP port binding was denied
diff --git a/Documentation/userspace-api/landlock.rst b/Documentation/userspace-api/landlock.rst
index 24cfc2c23cb2..3aab4197319b 100644
--- a/Documentation/userspace-api/landlock.rst
+++ b/Documentation/userspace-api/landlock.rst
@@ -87,7 +87,9 @@ to be explicit about the denied-by-default access rights.
             LANDLOCK_ACCESS_FS_REFER |
             LANDLOCK_ACCESS_FS_TRUNCATE |
             LANDLOCK_ACCESS_FS_IOCTL_DEV |
-            LANDLOCK_ACCESS_FS_RESOLVE_UNIX,
+            LANDLOCK_ACCESS_FS_RESOLVE_UNIX |
+            LANDLOCK_ACCESS_FS_READ_METADATA |
+            LANDLOCK_ACCESS_FS_WRITE_METADATA,
         .handled_access_net =
             LANDLOCK_ACCESS_NET_BIND_TCP |
             LANDLOCK_ACCESS_NET_CONNECT_TCP |
@@ -159,6 +161,12 @@ version, and only use the available subset of access rights:
         ruleset_attr.handled_permissions &=
             ~(LANDLOCK_PERMISSION_NAMESPACE_USE |
               LANDLOCK_PERMISSION_CAPABILITY_USE);
+        __attribute__((fallthrough));
+    case 12:
+        /* Removes metadata rights for ABI < 13 */
+        ruleset_attr.handled_access_fs &=
+            ~(LANDLOCK_ACCESS_FS_READ_METADATA |
+              LANDLOCK_ACCESS_FS_WRITE_METADATA);
     }
 
 This enables the creation of an inclusive ruleset that will contain our rules.
@@ -175,10 +183,12 @@ This enables the creation of an inclusive ruleset that will contain our rules.
 
 We can now add a new rule to this ruleset thanks to the returned file
 descriptor referring to this ruleset.  The rule will allow reading and
-executing the file hierarchy ``/usr``.  Without another rule, write actions
-would then be denied by the ruleset.  To add ``/usr`` to the ruleset, we open
-it with the ``O_PATH`` flag and fill the &struct landlock_path_beneath_attr with
-this file descriptor.
+executing the file hierarchy ``/usr``, as well as reading its metadata (e.g.
+with :manpage:`stat(2)`): most programs do not expect metadata reads to fail
+and read metadata alongside file contents and directory listings.  Without
+another rule, write actions would then be denied by the ruleset.  To add
+``/usr`` to the ruleset, we open it with the ``O_PATH`` flag and fill the
+&struct landlock_path_beneath_attr with this file descriptor.
 
 .. code-block:: c
 
@@ -187,7 +197,8 @@ this file descriptor.
         .allowed_access =
             LANDLOCK_ACCESS_FS_EXECUTE |
             LANDLOCK_ACCESS_FS_READ_FILE |
-            LANDLOCK_ACCESS_FS_READ_DIR,
+            LANDLOCK_ACCESS_FS_READ_DIR |
+            LANDLOCK_ACCESS_FS_READ_METADATA,
     };
 
     path_beneath.allowed_access &= ruleset_attr.handled_access_fs;
@@ -359,8 +370,8 @@ no_new_privs should only be left unset if such a privilege transition is
 expected.
 
 We now have a ruleset with the first rule allowing read and execute access to
-``/usr`` while denying all other handled accesses for the filesystem, and two
-more rules allowing DNS queries.
+``/usr``, including reading its metadata, while denying all other handled
+accesses for the filesystem, and two more rules allowing DNS queries.
 
 .. code-block:: c
 
@@ -432,8 +443,8 @@ a file path if all its enforced policy layers grant the access as well as all
 the other system access controls (e.g. filesystem DAC, other LSM policies,
 etc.).
 
-Bind mounts and OverlayFS
--------------------------
+Bind mounts and stacking filesystems
+------------------------------------
 
 Landlock enables restricting access to file hierarchies, which means that these
 access rights can be propagated with bind mounts (cf.
@@ -458,6 +469,23 @@ OverlayFS layer will not restrict the resulted merged hierarchy, and vice versa.
 Landlock users should then only think about file hierarchies they want to allow
 access to, regardless of the underlying filesystem.
 
+eCryptfs is another stacking filesystem, but unlike OverlayFS it forwards some
+metadata changes to the lower filesystem under the credentials of the calling
+thread.  Forwarded attribute changes (:manpage:`chmod(2)`, :manpage:`chown(2)`,
+:manpage:`utimensat(2)`) are checked a second time, against the current
+Landlock domain, on the lower path, in addition to the check performed on the
+eCryptfs path.  The first check follows the usual semantics, including the
+open-time rights of file descriptor-based operations, but the forwarded one
+always uses the rights of the calling thread.  A sandboxed process changing
+attributes through an eCryptfs mount may therefore also need the corresponding
+metadata access rights on the lower path, even when the file descriptor was
+opened before the ruleset was enforced.  Extended attribute reads and removals
+are forwarded with the unchecked ``__vfs_getxattr()``, ``i_op->listxattr`` and
+``__vfs_removexattr()`` helpers and are only checked once, on the eCryptfs
+path, whereas setting an extended attribute, and reading or changing POSIX
+ACLs and file attributes, are forwarded with the checking helpers and are
+therefore checked on the lower path as well.
+
 Inheritance
 -----------
 
@@ -669,14 +697,91 @@ for writing, sidestepping the ``LANDLOCK_ACCESS_FS_TRUNCATE`` right.
 
 The truncate right is associated with the opened file (see below).
 
+File metadata
+-------------
+
+The ``LANDLOCK_ACCESS_FS_READ_METADATA`` right governs reading file and
+directory metadata: :manpage:`stat(2)` and friends, :manpage:`getxattr(2)`,
+:manpage:`listxattr(2)` and friends, the ``FS_IOC_GETFLAGS`` and
+``FS_IOC_FSGETXATTR`` ioctls, :manpage:`file_getattr(2)`, and POSIX ACL reads.
+Path-based checks also cover the metadata lookups that the kernel performs on
+behalf of the caller, for example when the ``LOOP_GET_STATUS`` ioctl reads
+the attributes of a loop device's backing file: a sandbox may therefore need
+to grant access to such paths as well.
+
+The ``LANDLOCK_ACCESS_FS_WRITE_METADATA`` right governs explicit changes to
+file and directory metadata: :manpage:`chmod(2)` and friends,
+:manpage:`chown(2)` and friends, :manpage:`utimensat(2)`,
+:manpage:`setxattr(2)`, :manpage:`removexattr(2)` and friends, the
+``FS_IOC_SETFLAGS`` and ``FS_IOC_FSSETXATTR`` ioctls,
+:manpage:`file_setattr(2)`, and POSIX ACL changes.  Both rights apply to files
+and directories alike.
+
+Metadata changes that the kernel performs implicitly on behalf of another
+operation are not restricted by ``LANDLOCK_ACCESS_FS_WRITE_METADATA``:
+reading a file may update its access time, writing a file updates its
+modification and change times and may change the file size, and writing to
+or truncating a file with a set-user-ID or set-group-ID bit clears these
+bits unless the caller holds ``CAP_FSETID`` (the set-group-ID bit is only
+cleared on a group-executable file whose group the caller is not a member
+of).  File size changes through
+:manpage:`truncate(2)` and friends are governed by
+``LANDLOCK_ACCESS_FS_TRUNCATE`` instead.
+
+``LANDLOCK_ACCESS_FS_WRITE_METADATA`` also governs the clearing of
+set-user-ID bits, set-group-ID bits and file capabilities requested by an
+explicit :manpage:`chown(2)`, whereas the same clearing performed implicitly
+after a write is not restricted.  A :manpage:`chown(2)` with owner and group
+``-1`` on a file without a set-user-ID bit, without file capabilities, and
+without a set-group-ID bit that the call would clear (as described above)
+changes nothing that ``LANDLOCK_ACCESS_FS_WRITE_METADATA`` governs, and is
+not restricted.
+
+.. warning::
+
+   Many programs read metadata as part of reading file contents or listing
+   directories (e.g. calling :manpage:`stat(2)` before or after
+   :manpage:`open(2)`), and do not expect such calls to fail with
+   ``EACCES``.  Most of the time, ``LANDLOCK_ACCESS_FS_READ_METADATA``
+   should therefore be granted together with
+   ``LANDLOCK_ACCESS_FS_READ_FILE`` and ``LANDLOCK_ACCESS_FS_READ_DIR``.
+   Conversely, denying only ``LANDLOCK_ACCESS_FS_READ_FILE`` or
+   ``LANDLOCK_ACCESS_FS_READ_DIR`` does not hide metadata: it remains
+   readable through :manpage:`stat(2)` and friends unless
+   ``LANDLOCK_ACCESS_FS_READ_METADATA`` is denied as well.  Tailored
+   programs that do not read metadata at all can still deny this right to
+   further restrict their sandbox.
+
+Both metadata rights are associated with opened files, like
+``LANDLOCK_ACCESS_FS_TRUNCATE`` (see below): metadata accesses and changes
+requested through an already opened file descriptor, e.g. with
+:manpage:`fchmod(2)`, :manpage:`fchown(2)`, :manpage:`utimensat(2)` on an
+empty path, :manpage:`fstat(2)`, :manpage:`fgetxattr(2)`,
+:manpage:`fsetxattr(2)`, :manpage:`ioctl(2)` with ``FS_IOC_GETFLAGS`` or
+``FS_IOC_SETFLAGS``, or ``file_getattr(2)`` and ``file_setattr(2)`` with
+``AT_EMPTY_PATH``, are granted according to the rights available at
+:manpage:`open(2)` time, not according to the rights of the calling thread.
+Metadata accesses requested through a path (e.g. :manpage:`chmod(2)`,
+:manpage:`stat(2)`) are always checked against the rights of the calling
+thread.  ``O_PATH`` file descriptors are not opened through the open
+permission checks: the metadata system calls that accept such descriptors
+(e.g. :manpage:`fstat(2)`, and :manpage:`statx(2)`, :manpage:`fchmodat(2)`,
+:manpage:`fchownat(2)` or :manpage:`utimensat(2)` with an empty path) are
+checked against the rights of the calling thread as well, while the other file
+descriptor based metadata system calls and the
+``FS_IOC_GETFLAGS``/``FS_IOC_SETFLAGS`` ioctls reject ``O_PATH`` descriptors
+with ``EBADF``.
+
 Rights associated with file descriptors
 ---------------------------------------
 
-When opening a file, the availability of the ``LANDLOCK_ACCESS_FS_TRUNCATE`` and
-``LANDLOCK_ACCESS_FS_IOCTL_DEV`` rights is associated with the newly created
-file descriptor and will be used for subsequent truncation and ioctl attempts
-using :manpage:`ftruncate(2)` and :manpage:`ioctl(2)`.  The behavior is similar
-to opening a file for reading or writing, where permissions are checked during
+When opening a file, the availability of the ``LANDLOCK_ACCESS_FS_TRUNCATE``,
+``LANDLOCK_ACCESS_FS_IOCTL_DEV``, ``LANDLOCK_ACCESS_FS_READ_METADATA`` and
+``LANDLOCK_ACCESS_FS_WRITE_METADATA`` rights is associated with the newly
+created file descriptor and will be used for subsequent truncation, ioctl
+and metadata attempts using :manpage:`ftruncate(2)`, :manpage:`ioctl(2)` and
+the file descriptor-based metadata system calls.  The behavior is similar to
+opening a file for reading or writing, where permissions are checked during
 :manpage:`open(2)`, but not during the subsequent :manpage:`read(2)` and
 :manpage:`write(2)` calls.
 
@@ -1054,6 +1159,19 @@ fd-reference acquisition (:manpage:`open_tree(2)`, :manpage:`fsmount(2)`) with
 the new ``LANDLOCK_PERMISSION_NAMESPACE_USE`` permission flag and
 ``LANDLOCK_RULE_NAMESPACE`` rule type.
 
+File metadata (ABI < 13)
+------------------------
+
+Starting with the Landlock ABI version 13, it is possible to restrict
+file metadata access with the new ``LANDLOCK_ACCESS_FS_READ_METADATA``
+and ``LANDLOCK_ACCESS_FS_WRITE_METADATA`` access rights, which control
+reading file and directory metadata (e.g. with :manpage:`stat(2)` and
+:manpage:`getxattr(2)`) and changing it (e.g. with :manpage:`chmod(2)`
+and :manpage:`setxattr(2)`).  As with ``LANDLOCK_ACCESS_FS_TRUNCATE``,
+these rights are tied to opened files: metadata accesses through an
+already opened file descriptor are granted according to the rights
+available at :manpage:`open(2)` time.
+
 .. _kernel_support:
 
 Kernel support
-- 
2.18.0.huawei.25


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 17/17] Documentation: Update landlock doc for metadata rights
  2026-11-17 15:05 ` [PATCH -next -v4 17/17] Documentation: Update landlock doc for metadata rights Cai Xinchen
@ 2026-11-17 15:05   ` sashiko-bot
  0 siblings, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 15:05 UTC (permalink / raw)
  Cc: linux-security-module, selinux

> Document the two new access rights: add them to the example ruleset and
> to the ABI fallback switch, and describe their semantics in a new "File
> metadata" section, including the open-time semantic, the exclusion of
> implicit changes and the chown(2) special case, and the warning that
> READ_METADATA usually needs to be granted together with READ_FILE and
> READ_DIR.
> 
> Also rename the "Bind mounts and OverlayFS" section to "Bind mounts and
> stacking filesystems" and describe how eCryptfs forwards attribute
> changes under the caller's credentials, which causes the lower path to be
> checked as well, and extend the blockers list in
> Documentation/admin-guide/LSM/landlock.rst.
> 
> Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=17


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 06/17] LSM: pass struct path and struct file to the inode posix acl hooks
  2026-11-17 15:05 ` [PATCH -next -v4 06/17] LSM: pass struct path and struct file to the inode posix acl hooks Cai Xinchen
@ 2026-11-17 15:07   ` sashiko-bot
  0 siblings, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 15:07 UTC (permalink / raw)
  Cc: linux-security-module, selinux

> Convert the inode_set_acl, inode_get_acl and inode_remove_acl hooks and
> their SELinux, Smack, EVM and IMA implementations to take a const struct
> path instead of a dentry.  The implementations derive the dentry they
> still need from the path, and the idmap stays a separate argument.
> 
> Also pass the struct file through which the operation is requested, when
> there is one, for the same reason as for the xattr hooks, and add strong
> definitions of the three bpf_lsm_* stubs naming it file__nullable.
> 
> Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=6


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 08/17] LSM: rename inode_setattr to path_setattr and pass struct path and file
  2026-11-17 15:05 ` [PATCH -next -v4 08/17] LSM: rename inode_setattr to path_setattr and pass struct path and file Cai Xinchen
@ 2026-11-17 15:11   ` sashiko-bot
  0 siblings, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 15:11 UTC (permalink / raw)
  To: Cai Xinchen
  Cc: bpf, linux-security-module, linux-trace-kernel, selinux, dsterba,
	Chuck Lever, Jeff Layton, Anna Schumaker

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] fs: missing struct file propagation to notify_change_target()
--

commit 283fceee103640c180b1123a9a7934aad545e43c
Author: Cai Xinchen <caixinchen1@huawei.com>

LSM: rename inode_setattr to path_setattr and pass struct path and file

This commit renames the inode_setattr LSM hook to path_setattr and passes
the caller's struct path, target dentry, and optional struct file through
notify_change() and notify_change_target().

> diff --git a/fs/ntfs/named_stream.c b/fs/ntfs/named_stream.c
> index 1c55588df5ba0..05cac62fca1d2 100644
> --- a/fs/ntfs/named_stream.c
> +++ b/fs/ntfs/named_stream.c
> @@ -901,7 +901,8 @@ static int ntfs_stream_setattr_common(const struct mnt_idmap *idmap,
>  				err = -EINVAL;
>  			} else {
>  				err = notify_change_target(idmap, attr->ia_path,
> -							   base_dentry, &base_attr, NULL);
> +							   base_dentry, &base_attr,
> +							   NULL, NULL);
>  			}
>  		} else {
>  			err = 0;

[Severity: Medium]
Does forwarding an attribute change from an NTFS named stream to its base
inode drop the caller's struct file?

do_notify_change() stashes path in attr->ia_path before calling
->setattr(), but does not record file, and ntfs_stream_setattr_common()
passes NULL for file to notify_change_target().  When fchmod(), fchown(),
or futimens() is called on an open named stream fd, the second
security_path_setattr() call on base_dentry runs with file == NULL, so
LSMs and BPF LSM programs treat the forwarded check as a path-based
operation evaluated against current rather than the open file.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=8

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 15/17] selftests/landlock: Add tests for metadata access rights
  2026-11-17 15:05 ` [PATCH -next -v4 15/17] selftests/landlock: Add tests for metadata " Cai Xinchen
@ 2026-11-17 15:12   ` sashiko-bot
  0 siblings, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 15:12 UTC (permalink / raw)
  Cc: linux-security-module, selinux

> Add layout1 and layout2_overlay tests for the two new rights:
> unhandled_metadata, write_metadata, read_metadata, fileattr,
> fileattr_write_only, metadata_open_time and metadata_transfer.  They
> cover the metadata system calls, the fileattr interfaces, the open-time
> semantic and the transfer of file descriptors between processes.
> 
> The file descriptor-based checks reopen their files after the ruleset is
> enforced, so that the rights come from the rules rather than from
> descriptors opened before the sandbox, and the chown(2) no-op tests use
> the effective group ID so that they also pass as non-root.
> 
> The fallback syscall numbers for file_getattr(2) and file_setattr(2) are
> overridden on alpha and MIPS, which do not use the generic numbers.
> 
> Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=15


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 09/17] LSM: rename inode_getattr to path_getattr and pass struct file
  2026-11-17 15:05 ` [PATCH -next -v4 09/17] LSM: rename inode_getattr to path_getattr and pass struct file Cai Xinchen
@ 2026-11-17 15:30   ` sashiko-bot
  0 siblings, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 15:30 UTC (permalink / raw)
  To: Cai Xinchen
  Cc: bpf, linux-security-module, linux-trace-kernel, selinux, dsterba,
	Chuck Lever, Jeff Layton, Anna Schumaker

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bpf: missing vfs_getattr_file() in btf_allowlist_d_path
  breaks stat tracing
--

commit 0fd5e45352f3174f9865b405ef695f6fda94ab43
Author: Cai Xinchen <caixinchen1@huawei.com>

LSM: rename inode_getattr to path_getattr and pass struct file

This commit renames the inode_getattr LSM hook and security_inode_getattr()
to path_getattr and security_path_getattr(), adds a struct file parameter,
and introduces vfs_getattr_file() for callers that hold an open file.

> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 3107400454982..7006e1830269d 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -962,7 +962,7 @@ BPF_CALL_3(bpf_d_path, const struct path *, path, char *, buf, u32, sz)
>  BTF_SET_START(btf_allowlist_d_path)
>  #ifdef CONFIG_SECURITY
>  BTF_ID(func, security_file_permission)
> -BTF_ID(func, security_inode_getattr)
> +BTF_ID(func, security_path_getattr)
>  BTF_ID(func, security_file_open)
>  #endif
>  #ifdef CONFIG_SECURITY_PATH

[Severity: Medium]
Should vfs_getattr_file also be added to btf_allowlist_d_path alongside
vfs_getattr?

vfs_fstat() and vfs_statx_path() now call vfs_getattr_file() directly
instead of vfs_getattr(), so fentry/vfs_getattr and fexit/vfs_getattr
programs no longer fire on stat-family syscalls.  Without
BTF_ID(func, vfs_getattr_file) in btf_allowlist_d_path,
bpf_d_path_allowed() rejects tracing programs that attach to
vfs_getattr_file() and call bpf_d_path(), and on kernels with
CONFIG_SECURITY disabled no allowlisted function remains on those syscall
paths.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=9

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 14/17] landlock: Add READ_METADATA and WRITE_METADATA access rights
  2026-11-17 15:05 ` [PATCH -next -v4 14/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
@ 2026-11-17 15:49   ` sashiko-bot
  0 siblings, 0 replies; 38+ messages in thread
From: sashiko-bot @ 2026-11-17 15:49 UTC (permalink / raw)
  To: Cai Xinchen
  Cc: bpf, linux-security-module, linux-trace-kernel, selinux, dsterba,
	Chuck Lever, Jeff Layton, Anna Schumaker

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] landlock: open-fd setattr denied on NTFS streams in
  hook_path_setattr()
- [Medium] fs/stat: duplicate and broken audit_names entries in
  vfs_statx_fd()
- [Medium] selftests/landlock: audit_layout1 tests broken by
  READ_METADATA in ACCESS_FILE
--

commit 14db7d890cf459274a57d8c4bb2e8249b1cd4223
Author: Cai Xinchen <caixinchen1@huawei.com>

landlock: Add READ_METADATA and WRITE_METADATA access rights

This commit introduces the LANDLOCK_ACCESS_FS_READ_METADATA and
LANDLOCK_ACCESS_FS_WRITE_METADATA access rights and hooks the corresponding
VFS metadata paths to enforce them on paths and opened files.

> diff --git a/fs/stat.c b/fs/stat.c
> index e68dc17f23c46..a1a5bd83b5079 100644
> --- a/fs/stat.c
> +++ b/fs/stat.c
> @@ -19,6 +19,7 @@
>  #include <linux/pagemap.h>
>  #include <linux/compat.h>
>  #include <linux/iversion.h>
> +#include <linux/audit.h>
>  
>  #include <linux/uaccess.h>
>  #include <asm/unistd.h>
> @@ -361,6 +362,7 @@ static int vfs_statx_fd(int fd, int flags, struct kstat *stat,
>  	CLASS(fd_raw, f)(fd);
>  	if (fd_empty(f))
>  		return -EBADF;
> +	audit_file(fd_file(f));
>  	return vfs_statx_path(&fd_file(f)->f_path, flags, stat, request_mask,
>  			      fd_file(f));
>  }
> @@ -391,6 +393,18 @@ static int vfs_statx(int dfd, struct filename *filename, int flags,
>  		      AT_STATX_SYNC_TYPE))
>  		return -EINVAL;
>  
> +	/*
> +	 * An empty pathname with AT_EMPTY_PATH refers to the file descriptor
> +	 * itself.  Resolve it as such so that the struct file is passed down
> +	 * to the LSM hooks, like sys_statx() does for a NULL pathname and
> +	 * unlike a plain path lookup from the file descriptor.  This branch
> +	 * replaces a path lookup, so vfs_statx_fd() keeps auditing the file
> +	 * descriptor as that lookup would have.
> +	 */
> +	if ((flags & AT_EMPTY_PATH) && dfd >= 0 && !IS_ERR_OR_NULL(filename) &&
> +	    !filename->name[0])
> +		return vfs_statx_fd(dfd, flags, stat, request_mask);

[Severity: Medium]
Does dropping filename when redirecting to vfs_statx_fd() produce duplicate
and incomplete AUDIT_PATH records for IORING_OP_STATX with AT_EMPTY_PATH and
an empty string?

io_statx_prep() and io_statx() allocate filename via delayed_getname_uflags()
and complete_getname(), which calls audit_getname() and attaches an
unpopulated audit_names entry (filename->aname) to the audit context.
Previously, filename_lookup() called audit_inode(filename, path.dentry, 0) to
populate filename->aname in place.  With this change, vfs_statx_fd() calls
audit_file() instead, which passes name = NULL to __audit_inode():

kernel/auditsc.c:__audit_inode() {
    ...
	if (!name)
		goto out_alloc;

	/*
	 * If we have a pointer to an audit_names entry already, then we can
	 * just use it directly if the type is correct.
	 */
	n = name->aname;
    ...
}

Because name is NULL, __audit_inode() allocates a second audit_names entry
with name=(null) and nametype=NORMAL while leaving filename->aname
unpopulated with nametype=UNKNOWN.

> diff --git a/security/landlock/fs.c b/security/landlock/fs.c
> index 2ab67bcad1983..7d0e539b4cda7 100644
> --- a/security/landlock/fs.c
> +++ b/security/landlock/fs.c
[ ... ]
> +static int hook_path_setattr(const struct mnt_idmap *const idmap,
> +			     const struct path *const path,
> +			     struct dentry *const dentry,
> +			     struct iattr *const attr,
> +			     struct file *const file)
> +{
> +	unsigned int ia_valid = attr->ia_valid;
> +
[ ... ]
> +	if (ia_valid & ATTR_FORCE)
> +		ia_valid &= ~(ATTR_KILL_SUID | ATTR_KILL_SGID |
> +			      ATTR_KILL_PRIV | ATTR_MODE);
> +
> +	if (!(ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
> +			  ATTR_TIMES_SET | ATTR_TOUCH | ATTR_KILL_PRIV)))
> +		return 0;
> +
> +	return check_access_path_or_file(path, file,
> +					 LANDLOCK_ACCESS_FS_WRITE_METADATA);
> +}

[Severity: Medium]
Can hook_path_setattr() reject fchmod(), fchown(), or futimens() on an
already-opened NTFS named stream file descriptor with -EACCES when the
calling thread's current domain denies LANDLOCK_ACCESS_FS_WRITE_METADATA?

When notify_change() is called with a non-NULL file, the outer
do_notify_change() call authorizes the operation against
landlock_file(file)->allowed_access, stores only path in attr->ia_path, and
invokes inode->i_op->setattr().  On NTFS named streams,
ntfs_stream_setattr_common() then propagates shared attribute changes to the
base inode without a file pointer:

fs/ntfs/named_stream.c:ntfs_stream_setattr_common() {
    ...
			err = notify_change_target(idmap, attr->ia_path,
						   base_dentry, &base_attr,
						   NULL, NULL);
    ...
}

That second do_notify_change() call invokes hook_path_setattr() with
path = attr->ia_path, dentry = base_dentry, and file = NULL, causing
check_access_path_or_file() to check attr->ia_path against current_cred()
instead of the open file's credentials and emit a false audit denial.

> diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
> index 48c1f896dc9a0..2593db7ef25c1 100644
> --- a/tools/testing/selftests/landlock/fs_test.c
> +++ b/tools/testing/selftests/landlock/fs_test.c
> @@ -571,11 +571,13 @@ TEST_F_FORK(layout1, inval)
>  	LANDLOCK_ACCESS_FS_EXECUTE | \
>  	LANDLOCK_ACCESS_FS_WRITE_FILE | \
>  	LANDLOCK_ACCESS_FS_READ_FILE | \
> +	LANDLOCK_ACCESS_FS_READ_METADATA | \
> +	LANDLOCK_ACCESS_FS_WRITE_METADATA | \
>  	LANDLOCK_ACCESS_FS_TRUNCATE | \
>  	LANDLOCK_ACCESS_FS_IOCTL_DEV | \
>  	LANDLOCK_ACCESS_FS_RESOLVE_UNIX)

[Severity: Medium]
Does adding LANDLOCK_ACCESS_FS_READ_METADATA to ACCESS_FILE (and therefore
ACCESS_ALL) break the audit_layout1 tests in fs_test.c?

Tests in audit_layout1 such as execute_read, write_file, and read_file call
enforce_fs(_metadata, ACCESS_ALL, NULL) with no allow rules, and then call
matches_log_fs() or matches_log_fs_extra() from the same sandboxed process:

tools/testing/selftests/landlock/fs_test.c:matches_log_fs_extra() {
    ...
	absolute_path = realpath(path, NULL);
	if (!absolute_path)
		return -errno;
    ...
}

Because LANDLOCK_ACCESS_FS_READ_METADATA is now denied by ACCESS_ALL, the
stat calls inside realpath() fail with EACCES and generate unexpected
fs.read_metadata audit records, causing those 18 audit_layout1 tests to fail.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117150542.1169451-1-caixinchen1@huawei.com?part=14

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 01/17] fs: pass struct path to notify_change()
  2026-11-17 15:05 ` [PATCH -next -v4 01/17] fs: pass struct path to notify_change() Cai Xinchen
  2026-11-17 14:48   ` sashiko-bot
@ 2026-11-17 18:30   ` Al Viro
  2026-11-17 18:34     ` Al Viro
  1 sibling, 1 reply; 38+ messages in thread
From: Al Viro @ 2026-11-17 18:30 UTC (permalink / raw)
  To: Cai Xinchen
  Cc: mic, gnoack, paul, brauner, jack, amir73il, andrii, apparmor, ast,
	axboe, bpf, casey, cel, cem, chenxiaosong, code, corbet, Dai.Ngo,
	dakr, daniel, dhowells, dlemoal, dmitry.kasatkin, driver-core,
	dsterba, ecryptfs, eddyz87, emil, eric.snowberg, exfat,
	georgia.garcia, gregkh, hch, hirofumi, hyc.lee, ihor.solodrai,
	jlayton, jmorris, johan, john.fastabend, john.johansen, jolsa,
	kpsingh, linkinjeon, linux-api, linux-block, linux-btrfs,
	linux-cifs, linux-doc, linux-fsdevel, linux-integrity,
	linux-kernel, linux-kselftest, linux-nfs, linux-security-module,
	linux-trace-kernel, linux-unionfs, linux-xfs, liubaolin12138,
	martin.lau, mason, mathieu.desnoyers, matt, memxor, mhiramat,
	miklos, neil, netfs, ntfs, okorniev, omosnacek, penguin-kernel,
	rafael, rdunlap, roberto.sassu, rostedt, selinux, senozhatsky,
	serge, sj1557.seo, skhan, song, stephen.smalley.work, takedakn,
	tom, yonghong.song, yuezhang.mo, zohar, utilityemal77, lujialin4

On Tue, Nov 17, 2026 at 11:05:26PM +0800, Cai Xinchen wrote:

> +notify_change() and do_truncate() now take a const struct path * instead
> +of a struct dentry *.  They use path->dentry, so callers that only have a
> +dentry must provide a struct path.  struct iattr has a new ia_path member,
> +which notify_change() sets for the duration of the call; it must not be
> +stored beyond that.  Filesystems that forward a change to another inode
> +can use notify_change_target() to update the target dentry while keeping
> +the caller-supplied path in ia_path.

That needs a bit along the lines of "path MUST be consistent - don't combine
a dentry from one filesystem with mount of another".  All in-kernel callers
might have appropriate struct mount references on hand, but for out-of-tree
code that might be not true and we'd better be upfront about the headache
we are inflicting.

I'm not sure we really want to provide those mount references, TBH - it does
add a constraint not just on out-of-tree callers, but upon the future uses
in the kernel.  If NTFS is the only reason... ugh.

> diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
> index 11c70888f38b..410906a66ee9 100644
> --- a/drivers/base/devtmpfs.c
> +++ b/drivers/base/devtmpfs.c
> @@ -284,13 +284,14 @@ static int handle_create(const char *nodename, umode_t mode, kuid_t uid,
>  			dev->devt, NULL);
>  	if (!err) {
>  		struct iattr newattrs;
> +		struct path attr_path = { .mnt = path.mnt, .dentry = dentry };
>  
>  		newattrs.ia_mode = mode;
>  		newattrs.ia_uid = uid;
>  		newattrs.ia_gid = gid;
>  		newattrs.ia_valid = ATTR_MODE|ATTR_UID|ATTR_GID;
>  		inode_lock(d_inode(dentry));
> -		notify_change(&nop_mnt_idmap, dentry, &newattrs, NULL);
> +		notify_change(&nop_mnt_idmap, &attr_path, &newattrs, NULL);

BTW, why not something like

		notify_change(&nop_mnt_idmap,
			      &(struct path){.mnt = path.mnt, .dentry = dentry},
			      &newattrs, NULL);
instead of that named local?  Same question for other places like that...

> +int notify_change_target(const struct mnt_idmap *idmap,
> +			 const struct path *path, struct dentry *target,
> +			 struct iattr *attr,
> +			 struct delegated_inode *delegated_inode)
> +{
> +	if (WARN_ON_ONCE(!target))
> +		return -EINVAL;
> +	return do_notify_change(path, idmap, target, attr, delegated_inode);
> +}


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 01/17] fs: pass struct path to notify_change()
  2026-11-17 18:30   ` Al Viro
@ 2026-11-17 18:34     ` Al Viro
  0 siblings, 0 replies; 38+ messages in thread
From: Al Viro @ 2026-11-17 18:34 UTC (permalink / raw)
  To: Cai Xinchen
  Cc: mic, gnoack, paul, brauner, jack, amir73il, andrii, apparmor, ast,
	axboe, bpf, casey, cel, cem, chenxiaosong, code, corbet, Dai.Ngo,
	dakr, daniel, dhowells, dlemoal, dmitry.kasatkin, driver-core,
	dsterba, ecryptfs, eddyz87, emil, eric.snowberg, exfat,
	georgia.garcia, gregkh, hch, hirofumi, hyc.lee, ihor.solodrai,
	jlayton, jmorris, johan, john.fastabend, john.johansen, jolsa,
	kpsingh, linkinjeon, linux-api, linux-block, linux-btrfs,
	linux-cifs, linux-doc, linux-fsdevel, linux-integrity,
	linux-kernel, linux-kselftest, linux-nfs, linux-security-module,
	linux-trace-kernel, linux-unionfs, linux-xfs, liubaolin12138,
	martin.lau, mason, mathieu.desnoyers, matt, memxor, mhiramat,
	miklos, neil, netfs, ntfs, okorniev, omosnacek, penguin-kernel,
	rafael, rdunlap, roberto.sassu, rostedt, selinux, senozhatsky,
	serge, sj1557.seo, skhan, song, stephen.smalley.work, takedakn,
	tom, yonghong.song, yuezhang.mo, zohar, utilityemal77, lujialin4

On Tue, Nov 17, 2026 at 06:30:59PM +0000, Al Viro wrote:
> On Tue, Nov 17, 2026 at 11:05:26PM +0800, Cai Xinchen wrote:
> 
> > +notify_change() and do_truncate() now take a const struct path * instead
> > +of a struct dentry *.  They use path->dentry, so callers that only have a
> > +dentry must provide a struct path.  struct iattr has a new ia_path member,
> > +which notify_change() sets for the duration of the call; it must not be
> > +stored beyond that.  Filesystems that forward a change to another inode
> > +can use notify_change_target() to update the target dentry while keeping
> > +the caller-supplied path in ia_path.
> 
> That needs a bit along the lines of "path MUST be consistent - don't combine
> a dentry from one filesystem with mount of another".  All in-kernel callers
> might have appropriate struct mount references on hand, but for out-of-tree
> code that might be not true and we'd better be upfront about the headache
> we are inflicting.
> 
> I'm not sure we really want to provide those mount references, TBH - it does
> add a constraint not just on out-of-tree callers, but upon the future uses
> in the kernel.  If NTFS is the only reason... ugh.

Incidentally, will the mount reference you are supplying in case of overlayfs
upper layer be any good for LSM users?

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [PATCH -next -v4 02/17] LSM: pass struct path to the inode_setsecctx hook
  2026-11-17 15:05 ` [PATCH -next -v4 02/17] LSM: pass struct path to the inode_setsecctx hook Cai Xinchen
  2026-11-17 14:43   ` sashiko-bot
@ 2026-11-17 18:43   ` Al Viro
  1 sibling, 0 replies; 38+ messages in thread
From: Al Viro @ 2026-11-17 18:43 UTC (permalink / raw)
  To: Cai Xinchen
  Cc: mic, gnoack, paul, brauner, jack, amir73il, andrii, apparmor, ast,
	axboe, bpf, casey, cel, cem, chenxiaosong, code, corbet, Dai.Ngo,
	dakr, daniel, dhowells, dlemoal, dmitry.kasatkin, driver-core,
	dsterba, ecryptfs, eddyz87, emil, eric.snowberg, exfat,
	georgia.garcia, gregkh, hch, hirofumi, hyc.lee, ihor.solodrai,
	jlayton, jmorris, johan, john.fastabend, john.johansen, jolsa,
	kpsingh, linkinjeon, linux-api, linux-block, linux-btrfs,
	linux-cifs, linux-doc, linux-fsdevel, linux-integrity,
	linux-kernel, linux-kselftest, linux-nfs, linux-security-module,
	linux-trace-kernel, linux-unionfs, linux-xfs, liubaolin12138,
	martin.lau, mason, mathieu.desnoyers, matt, memxor, mhiramat,
	miklos, neil, netfs, ntfs, okorniev, omosnacek, penguin-kernel,
	rafael, rdunlap, roberto.sassu, rostedt, selinux, senozhatsky,
	serge, sj1557.seo, skhan, song, stephen.smalley.work, takedakn,
	tom, yonghong.song, yuezhang.mo, zohar, utilityemal77, lujialin4

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@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.

^ permalink raw reply	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2026-11-17 18:43 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 15:05 [PATCH -next -v4 00/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
2026-11-17 15:05 ` [PATCH -next -v4 01/17] fs: pass struct path to notify_change() Cai Xinchen
2026-11-17 14:48   ` sashiko-bot
2026-11-17 18:30   ` Al Viro
2026-11-17 18:34     ` Al Viro
2026-11-17 15:05 ` [PATCH -next -v4 02/17] LSM: pass struct path to the inode_setsecctx hook Cai Xinchen
2026-11-17 14:43   ` sashiko-bot
2026-11-17 18:43   ` Al Viro
2026-11-17 15:05 ` [PATCH -next -v4 03/17] fs: pass struct path to xattr helpers Cai Xinchen
2026-11-17 14:59   ` sashiko-bot
2026-11-17 15:05 ` [PATCH -next -v4 04/17] fs: pass struct path to POSIX ACL helpers Cai Xinchen
2026-11-17 14:45   ` sashiko-bot
2026-11-17 15:05 ` [PATCH -next -v4 05/17] LSM: pass struct path and struct file to the inode xattr hooks Cai Xinchen
2026-11-17 15:03   ` sashiko-bot
2026-11-17 15:05 ` [PATCH -next -v4 06/17] LSM: pass struct path and struct file to the inode posix acl hooks Cai Xinchen
2026-11-17 15:07   ` sashiko-bot
2026-11-17 15:05 ` [PATCH -next -v4 07/17] LSM: pass struct path and struct file to the inode fileattr hooks Cai Xinchen
2026-11-17 14:51   ` sashiko-bot
2026-11-17 15:05 ` [PATCH -next -v4 08/17] LSM: rename inode_setattr to path_setattr and pass struct path and file Cai Xinchen
2026-11-17 15:11   ` sashiko-bot
2026-11-17 15:05 ` [PATCH -next -v4 09/17] LSM: rename inode_getattr to path_getattr and pass struct file Cai Xinchen
2026-11-17 15:30   ` sashiko-bot
2026-11-17 15:05 ` [PATCH -next -v4 10/17] LSM: rename the inode xattr hooks to path_xattr hooks Cai Xinchen
2026-11-17 14:55   ` sashiko-bot
2026-11-17 15:05 ` [PATCH -next -v4 11/17] LSM: rename the inode posix acl hooks to path_*_acl hooks Cai Xinchen
2026-11-17 14:55   ` sashiko-bot
2026-11-17 15:05 ` [PATCH -next -v4 12/17] LSM: rename the inode fileattr hooks to path_file_* hooks Cai Xinchen
2026-11-17 15:02   ` sashiko-bot
2026-11-17 15:05 ` [PATCH -next -v4 13/17] LSM: rename inode_setsecctx to path_setsecctx Cai Xinchen
2026-11-17 14:59   ` sashiko-bot
2026-11-17 15:05 ` [PATCH -next -v4 14/17] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
2026-11-17 15:49   ` sashiko-bot
2026-11-17 15:05 ` [PATCH -next -v4 15/17] selftests/landlock: Add tests for metadata " Cai Xinchen
2026-11-17 15:12   ` sashiko-bot
2026-11-17 15:05 ` [PATCH -next -v4 16/17] samples/landlock: Add metadata rights to sandboxer Cai Xinchen
2026-11-17 15:04   ` sashiko-bot
2026-11-17 15:05 ` [PATCH -next -v4 17/17] Documentation: Update landlock doc for metadata rights Cai Xinchen
2026-11-17 15:05   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox