Linux Security Modules development
 help / color / mirror / Atom feed
From: Shawn Shao <shawnq1@163.com>
To: casey@schaufler-ca.com
Cc: Paul Moore <paul@paul-moore.com>,
	James Morris <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2] smack: mediate file attribute syscalls
Date: Mon, 30 Nov 2026 07:48:45 +0000	[thread overview]
Message-ID: <20261130074845.2537541-1-shawnq1@163.com> (raw)
In-Reply-To: <9cd7e2c5-22a0-45fc-ad41-56bac8bcbbeb@schaufler-ca.com>

Hello,

Thanks for the review. I added kernel-doc comments to both new hook
functions, including their parameters and return value.

Smack lacks the inode_file_getattr and inode_file_setattr hooks. As a
result, file_getattr() and file_setattr() could bypass Smack's existing
read and write checks. The patch implements both hooks with the same access
checks as the existing getattr and setattr hooks.

The reproducer runs as uid 1000 without capabilities and changes its Smack
label to Subject. A stat() on /mnt/secret is denied, but file_getattr() on
the same file succeeds. Subject can read the Control label but cannot write
it. Yet file_setattr() clears flags on /mnt/control. Ordinary
open() checks continue to be enforced. With the patch, denied calls return
-EACCES, while permitted operations on /mnt/public still succeed.

Tested source:  v7.3-23903-g7cd8495c0f162
compiler:       gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

The CONFIG_SECURITY_SMACK-enabled smack_lsm.o build completed with
KCFLAGS=-Wframe-larger-than=1280. The kernel-doc check for both callbacks
completed without warnings. The behavioral reproducer and console output
are unchanged from v1:
https://gist.github.com/shaos26/fbf8b7f663ee82593d7d41623aa2e2c4

Fixes: defdd02d783c ("lsm: introduce new hooks for setting/getting inode fsxattr")
Signed-off-by: Shawn Shao <shawnq1@163.com>
---
Changes in v2:
- Add kernel-doc comments for both new Smack hooks.

 security/smack/smack_lsm.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 3a4a33568297b..493d66f83e96a 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1311,6 +1311,48 @@ static int smack_inode_getattr(const struct path *path)
 	return rc;
 }
 
+/**
+ * smack_inode_file_getattr - Smack check for retrieving file attributes
+ * @dentry: file to retrieve filesystem attributes from
+ * @fa: attributes to get
+ *
+ * Returns 0 if access is permitted, an error code otherwise.
+ */
+static int smack_inode_file_getattr(struct dentry *dentry,
+				    struct file_kattr *fa)
+{
+	struct smk_audit_info ad;
+	struct inode *inode = d_backing_inode(dentry);
+	int rc;
+
+	smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_DENTRY);
+	smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
+	rc = smk_curacc(smk_of_inode(inode), MAY_READ, &ad);
+	rc = smk_bu_inode(inode, MAY_READ, rc);
+	return rc;
+}
+
+/**
+ * smack_inode_file_setattr - Smack check for setting file attributes
+ * @dentry: file to set filesystem attributes on
+ * @fa: attributes to set
+ *
+ * Returns 0 if access is permitted, an error code otherwise.
+ */
+static int smack_inode_file_setattr(struct dentry *dentry,
+				    struct file_kattr *fa)
+{
+	struct smk_audit_info ad;
+	struct inode *inode = d_backing_inode(dentry);
+	int rc;
+
+	smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_DENTRY);
+	smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
+	rc = smk_curacc(smk_of_inode(inode), MAY_WRITE, &ad);
+	rc = smk_bu_inode(inode, MAY_WRITE, rc);
+	return rc;
+}
+
 /**
  * smack_inode_xattr_skipcap - Skip the xattr capability checks?
  * @name: name of the xattr
@@ -5185,6 +5227,8 @@ static struct security_hook_list smack_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(inode_permission, smack_inode_permission),
 	LSM_HOOK_INIT(inode_setattr, smack_inode_setattr),
 	LSM_HOOK_INIT(inode_getattr, smack_inode_getattr),
+	LSM_HOOK_INIT(inode_file_getattr, smack_inode_file_getattr),
+	LSM_HOOK_INIT(inode_file_setattr, smack_inode_file_setattr),
 	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),
-- 
2.34.1


  reply	other threads:[~2026-11-30  7:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  8:28 [PATCH] smack: mediate file attribute syscalls shaos
2026-11-28  8:46 ` sashiko-bot
2026-11-28 17:37 ` Casey Schaufler
2026-11-30  7:48   ` Shawn Shao [this message]
2026-11-30  8:00     ` [PATCH v2] " sashiko-bot

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=20261130074845.2537541-1-shawnq1@163.com \
    --to=shawnq1@163.com \
    --cc=casey@schaufler-ca.com \
    --cc=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=serge@hallyn.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