From: Cai Xinchen <caixinchen1@huawei.com>
To: <mic@digikod.net>, <gnoack@google.com>, <paul@paul-moore.com>,
<jmorris@namei.org>, <serge@hallyn.com>, <corbet@lwn.net>,
<skhan@linuxfoundation.org>
Cc: <rdunlap@infradead.org>, <gregkh@linuxfoundation.org>,
<rafael@kernel.org>, <dakr@kernel.org>, <dlemoal@kernel.org>,
<hch@lst.de>, <axboe@kernel.dk>, <viro@zeniv.linux.org.uk>,
<brauner@kernel.org>, <jack@suse.cz>, <dhowells@redhat.com>,
<code@tyhicks.com>, <linkinjeon@kernel.org>,
<sj1557.seo@samsung.com>, <yuezhang.mo@sony.com>,
<hirofumi@mail.parknet.co.jp>, <cel@kernel.org>,
<jlayton@kernel.org>, <neil@brown.name>, <okorniev@redhat.com>,
<Dai.Ngo@oracle.com>, <tom@talpey.com>, <miklos@szeredi.hu>,
<amir73il@gmail.com>, <senozhatsky@chromium.org>,
<chenxiaosong@chenxiaosong.com>, <zohar@linux.ibm.com>,
<roberto.sassu@huawei.com>, <dmitry.kasatkin@gmail.com>,
<eric.snowberg@oracle.com>, <stephen.smalley.work@gmail.com>,
<omosnacek@gmail.com>, <casey@schaufler-ca.com>,
<nanx95726@gmail.com>, <djwong@kernel.org>,
<daniel@iogearbox.net>, <linux-security-module@vger.kernel.org>,
<linux-doc@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<driver-core@lists.linux.dev>, <linux-block@vger.kernel.org>,
<linux-fsdevel@vger.kernel.org>, <netfs@lists.linux.dev>,
<ecryptfs@vger.kernel.org>, <exfat@lists.linux.dev>,
<linux-nfs@vger.kernel.org>, <linux-unionfs@vger.kernel.org>,
<linux-cifs@vger.kernel.org>, <linux-integrity@vger.kernel.org>,
<selinux@vger.kernel.org>, <linux-kselftest@vger.kernel.org>,
<xiujianfeng@huawei.com>, <caixinchen1@huawei.com>,
<lujialin4@huawei.com>
Subject: [PATCH RFC -next 05/12] LSM: pass struct path to the inode_setattr hook
Date: Thu, 24 Sep 2026 18:48:24 +0800 [thread overview]
Message-ID: <20260924104831.1081137-6-caixinchen1@huawei.com> (raw)
In-Reply-To: <20260924104831.1081137-1-caixinchen1@huawei.com>
The inode_setattr hook is called from notify_change(), which now
holds a struct path and used to derive the idmap and dentry from it
just for the hook. The other in-kernel caller, the fat and exfat
attribute ioctls, already holds a struct file and can pass its
f_path directly.
Convert the hook and its SELinux, Smack and EVM implementations to
take a const struct path. The implementations derive the idmap and
dentry they still need from the path, so this is a purely mechanical
change with no behavior change.
Assisted-by: opencode: glm-5.3
Signed-off-by: Cai Xinchen <caixinchen1@huawei.com>
---
fs/attr.c | 2 +-
fs/exfat/file.c | 3 +--
fs/fat/file.c | 3 +--
include/linux/lsm_hook_defs.h | 2 +-
include/linux/security.h | 6 ++----
security/integrity/evm/evm_main.c | 7 ++++---
security/security.c | 10 ++++------
security/selinux/hooks.c | 3 ++-
security/smack/smack_lsm.c | 3 ++-
9 files changed, 18 insertions(+), 21 deletions(-)
diff --git a/fs/attr.c b/fs/attr.c
index ea91e4471faa..f0eb4be496fc 100644
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -537,7 +537,7 @@ int notify_change(const struct path *path, struct iattr *attr,
!vfsgid_valid(i_gid_into_vfsgid(idmap, inode)))
return -EOVERFLOW;
- error = security_inode_setattr(idmap, dentry, attr);
+ error = security_inode_setattr(path, attr);
if (error)
return error;
diff --git a/fs/exfat/file.c b/fs/exfat/file.c
index a2a9ee1a2004..db62a8c85d64 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -493,8 +493,7 @@ 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_inode_setattr(&file->f_path, &ia);
if (err)
goto out_unlock_inode;
diff --git a/fs/fat/file.c b/fs/fat/file.c
index 6c475c53334c..c0ec05825517 100644
--- a/fs/fat/file.c
+++ b/fs/fat/file.c
@@ -92,8 +92,7 @@ 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_inode_setattr(&file->f_path, &ia);
if (err)
goto out_unlock_inode;
diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h
index b22f7928523e..b54fdf7d32e8 100644
--- a/include/linux/lsm_hook_defs.h
+++ b/include/linux/lsm_hook_defs.h
@@ -142,7 +142,7 @@ LSM_HOOK(int, 0, inode_follow_link, struct dentry *dentry, struct inode *inode,
bool rcu)
LSM_HOOK(int, 0, inode_permission, struct mnt_idmap *idmap,
struct inode *inode, int mask)
-LSM_HOOK(int, 0, inode_setattr, struct mnt_idmap *idmap, struct dentry *dentry,
+LSM_HOOK(int, 0, inode_setattr, const struct path *path,
struct iattr *attr)
LSM_HOOK(void, LSM_RET_VOID, inode_post_setattr, struct mnt_idmap *idmap,
struct dentry *dentry, int ia_valid)
diff --git a/include/linux/security.h b/include/linux/security.h
index 6ac9fb634017..09c14c83e58f 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -429,8 +429,7 @@ int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
bool rcu);
int security_inode_permission(struct mnt_idmap *idmap, struct inode *inode,
int mask);
-int security_inode_setattr(struct mnt_idmap *idmap,
- struct dentry *dentry, struct iattr *attr);
+int security_inode_setattr(const struct path *path, struct iattr *attr);
void security_inode_post_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
int ia_valid);
int security_inode_getattr(const struct path *path);
@@ -1001,8 +1000,7 @@ static inline int security_inode_permission(struct mnt_idmap *idmap,
return 0;
}
-static inline int security_inode_setattr(struct mnt_idmap *idmap,
- struct dentry *dentry,
+static inline int security_inode_setattr(const struct path *path,
struct iattr *attr)
{
return 0;
diff --git a/security/integrity/evm/evm_main.c b/security/integrity/evm/evm_main.c
index b59e3f121b8a..b0af1bf86ab5 100644
--- a/security/integrity/evm/evm_main.c
+++ b/security/integrity/evm/evm_main.c
@@ -949,18 +949,19 @@ static int evm_attr_change(struct mnt_idmap *idmap,
/**
* evm_inode_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
* @attr: iattr structure containing the new file attributes
*
* 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(struct mnt_idmap *idmap, struct dentry *dentry,
+static int evm_inode_setattr(const struct path *path,
struct iattr *attr)
{
unsigned int ia_valid = attr->ia_valid;
enum integrity_status evm_status;
+ struct dentry *dentry = path->dentry;
+ struct mnt_idmap *idmap = mnt_idmap(path->mnt);
/* Policy permits modification of the protected attrs even though
* there's no HMAC key loaded
diff --git a/security/security.c b/security/security.c
index de3ed5c18802..ce74b9f1d110 100644
--- a/security/security.c
+++ b/security/security.c
@@ -1891,8 +1891,7 @@ int security_inode_permission(struct mnt_idmap *idmap, struct inode *inode,
/**
* security_inode_setattr() - Check if setting file attributes is allowed
- * @idmap: idmap of the mount
- * @dentry: file
+ * @path: file
* @attr: new attributes
*
* Check permission before setting file attributes. Note that the kernel call
@@ -1902,12 +1901,11 @@ int security_inode_permission(struct mnt_idmap *idmap, struct inode *inode,
*
* Return: Returns 0 if permission is granted.
*/
-int security_inode_setattr(struct mnt_idmap *idmap,
- struct dentry *dentry, struct iattr *attr)
+int security_inode_setattr(const struct path *path, struct iattr *attr)
{
- if (unlikely(IS_PRIVATE(d_backing_inode(dentry))))
+ if (unlikely(IS_PRIVATE(d_backing_inode(path->dentry))))
return 0;
- return call_int_hook(inode_setattr, idmap, dentry, attr);
+ return call_int_hook(inode_setattr, path, attr);
}
EXPORT_SYMBOL_GPL(security_inode_setattr);
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 1d06b08f3c41..49785dd62df4 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3339,10 +3339,11 @@ static int selinux_inode_permission(struct mnt_idmap *idmap,
return rc;
}
-static int selinux_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
+static int selinux_inode_setattr(const struct path *path,
struct iattr *iattr)
{
const struct cred *cred = current_cred();
+ struct dentry *dentry = path->dentry;
struct inode *inode = d_backing_inode(dentry);
unsigned int ia_valid = iattr->ia_valid;
u32 av = FILE__WRITE;
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index e517809c230d..991b967c4c4e 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1272,10 +1272,11 @@ static int smack_inode_permission(struct mnt_idmap *idmap, struct inode *inode,
*
* Returns 0 if access is permitted, an error code otherwise
*/
-static int smack_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
+static int smack_inode_setattr(const struct path *path,
struct iattr *iattr)
{
struct smk_audit_info ad;
+ struct dentry *dentry = path->dentry;
int rc;
/*
--
2.18.0.huawei.25
next prev parent reply other threads:[~2026-09-24 10:22 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 10:48 [PATCH RFC -next 00/12] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
2026-09-24 10:48 ` [PATCH RFC -next 01/12] fs: pass struct path to notify_change() Cai Xinchen
2026-09-24 10:48 ` [PATCH RFC -next 02/12] LSM: pass struct path to the inode_setsecctx hook Cai Xinchen
2026-09-24 10:48 ` [PATCH RFC -next 03/12] fs: pass struct path to xattr helpers Cai Xinchen
2026-09-24 11:12 ` Amir Goldstein
2026-09-28 8:44 ` Cai Xinchen
2026-10-06 15:31 ` Casey Schaufler
2026-09-24 10:48 ` [PATCH RFC -next 04/12] fs: pass struct path to POSIX ACL helpers Cai Xinchen
2026-09-24 10:48 ` Cai Xinchen [this message]
2026-09-24 10:48 ` [PATCH RFC -next 06/12] LSM: pass struct path to the inode xattr hooks Cai Xinchen
2026-09-24 10:48 ` [PATCH RFC -next 07/12] LSM: pass struct path to the inode posix acl hooks Cai Xinchen
2026-10-06 15:30 ` Casey Schaufler
2026-09-24 10:48 ` [PATCH RFC -next 08/12] landlock: Add READ_METADATA and WRITE_METADATA access rights Cai Xinchen
2026-09-24 10:48 ` [PATCH RFC -next 09/12] landlock: Implement metadata access hooks Cai Xinchen
2026-09-26 8:38 ` Günther Noack
2026-09-28 6:19 ` Cai Xinchen
2026-09-24 10:48 ` [PATCH RFC -next 10/12] selftests/landlock: Add tests for metadata access rights Cai Xinchen
2026-09-24 10:48 ` [PATCH RFC -next 11/12] samples/landlock: Add metadata rights to sandboxer Cai Xinchen
2026-09-24 10:48 ` [PATCH RFC -next 12/12] Documentation: Update landlock doc for metadata rights Cai Xinchen
2026-09-25 15:33 ` [PATCH RFC -next 00/12] landlock: Add READ_METADATA and WRITE_METADATA access rights Christian Brauner
2026-09-25 17:07 ` Paul Moore
2026-09-28 19:27 ` Mickaël Salaün
2026-09-25 18:03 ` Justin Suess
2026-09-26 7:56 ` Günther Noack
2026-09-28 17:13 ` Justin Suess
2026-09-28 19:25 ` Mickaël Salaün
2026-09-29 12:12 ` Günther Noack
2026-09-29 17:27 ` Justin Suess
2026-09-29 18:51 ` Mickaël Salaün
2026-10-01 13:47 ` Justin Suess
2026-09-26 8:27 ` Günther Noack
2026-09-28 6:52 ` Cai Xinchen
2026-09-28 19:46 ` Mickaël Salaün
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260924104831.1081137-6-caixinchen1@huawei.com \
--to=caixinchen1@huawei.com \
--cc=Dai.Ngo@oracle.com \
--cc=amir73il@gmail.com \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=casey@schaufler-ca.com \
--cc=cel@kernel.org \
--cc=chenxiaosong@chenxiaosong.com \
--cc=code@tyhicks.com \
--cc=corbet@lwn.net \
--cc=dakr@kernel.org \
--cc=daniel@iogearbox.net \
--cc=dhowells@redhat.com \
--cc=djwong@kernel.org \
--cc=dlemoal@kernel.org \
--cc=dmitry.kasatkin@gmail.com \
--cc=driver-core@lists.linux.dev \
--cc=ecryptfs@vger.kernel.org \
--cc=eric.snowberg@oracle.com \
--cc=exfat@lists.linux.dev \
--cc=gnoack@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=hch@lst.de \
--cc=hirofumi@mail.parknet.co.jp \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=jmorris@namei.org \
--cc=linkinjeon@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=lujialin4@huawei.com \
--cc=mic@digikod.net \
--cc=miklos@szeredi.hu \
--cc=nanx95726@gmail.com \
--cc=neil@brown.name \
--cc=netfs@lists.linux.dev \
--cc=okorniev@redhat.com \
--cc=omosnacek@gmail.com \
--cc=paul@paul-moore.com \
--cc=rafael@kernel.org \
--cc=rdunlap@infradead.org \
--cc=roberto.sassu@huawei.com \
--cc=selinux@vger.kernel.org \
--cc=senozhatsky@chromium.org \
--cc=serge@hallyn.com \
--cc=sj1557.seo@samsung.com \
--cc=skhan@linuxfoundation.org \
--cc=stephen.smalley.work@gmail.com \
--cc=tom@talpey.com \
--cc=viro@zeniv.linux.org.uk \
--cc=xiujianfeng@huawei.com \
--cc=yuezhang.mo@sony.com \
--cc=zohar@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox