* [PATCH] smack: mediate file attribute syscalls
@ 2026-11-28 8:28 shaos
2026-11-28 17:37 ` Casey Schaufler
0 siblings, 1 reply; 2+ messages in thread
From: shaos @ 2026-11-28 8:28 UTC (permalink / raw)
To: casey
Cc: Paul Moore, James Morris, Serge E. Hallyn, linux-security-module,
linux-kernel
Hello,
Smack does not implement the inode_file_getattr and inode_file_setattr
hooks. As a result, the file_getattr() and file_setattr() system calls
bypass Smack's existing read and write checks.
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. The Subject label has only
read access to the Control label, yet file_setattr() clears the file
flags on /mnt/control. Ordinary open() checks continue to be enforced.
This bypass exposes file attribute metadata and permits changes to file
attributes that the Smack policy denies. It does not expose file contents
or demonstrate privilege escalation.
Tested source revision:
HEAD commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
git tree: fe970b05333fb8e41da21e9e289f652abcc7cba7
source version: Linux 7.4.0-rc4
compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0,
GNU ld 2.38
console output:
https://gist.githubusercontent.com/shaos26/fbf8b7f663ee82593d7d41623aa2e2c4/raw/2ad22ab46d2cf376b59ef361d9c7ca2b691c6eda/console-output.txt
kernel config:
https://gist.githubusercontent.com/shaos26/fbf8b7f663ee82593d7d41623aa2e2c4/raw/f9e1ceca2f52ead87738af313610fc49834654dc/kernel-config.txt
reproducer:
https://gist.githubusercontent.com/shaos26/fbf8b7f663ee82593d7d41623aa2e2c4/raw/d9b447aad65076391390d150d752b6b9cb116abc/poc.c
Build the kernel at the tested revision with the attached configuration.
The reproducer is a static init program and expects an ext4 image on
/dev/vda containing empty files named secret, control, and public:
truncate -s 32M smack.img
mkfs.ext4 -F smack.img
mkdir mnt
mount -o loop smack.img mnt
touch mnt/secret mnt/control mnt/public
umount mnt
gcc -O2 -Wall -Wextra -static -o poc poc.c
mkdir -p rootfs
cp poc rootfs/init
chmod 0755 rootfs/init
(cd rootfs && find . -print0 | cpio --null -o -H newc) |
gzip -9 > initramfs.cpio.gz
Boot the initramfs and ext4 image with:
qemu-system-x86_64 -m 2G -smp 2 \
-kernel <linux-tree>/arch/x86/boot/bzImage \
-initrd initramfs.cpio.gz \
-drive file=smack.img,format=raw,if=virtio \
-append 'console=ttyS0 rdinit=/init lsm=smack loglevel=7' \
-nographic -monitor none -no-reboot
On two vulnerable boots, file_getattr() on /mnt/secret returned success
while stat() returned -EACCES. file_setattr() on /mnt/control also
returned success and cleared its flags. With this patch, both denied
operations return -EACCES; permitted operations on /mnt/public still
succeed.
Implement both hooks with the same Smack access checks used by the
existing getattr and setattr hooks:
Fixes: defdd02d783c ("lsm: introduce new hooks for setting/getting inode fsxattr")
Signed-off-by: shaos <shawnq1@163.com>
---
security/smack/smack_lsm.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 3a4a33568297b..6da2492f9bb61 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1311,6 +1311,34 @@ static int smack_inode_getattr(const struct path *path)
return rc;
}
+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;
+}
+
+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 +5213,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
Thanks,
shaos
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] smack: mediate file attribute syscalls
2026-11-28 8:28 [PATCH] smack: mediate file attribute syscalls shaos
@ 2026-11-28 17:37 ` Casey Schaufler
0 siblings, 0 replies; 2+ messages in thread
From: Casey Schaufler @ 2026-11-28 17:37 UTC (permalink / raw)
To: shaos
Cc: Paul Moore, James Morris, Serge E. Hallyn, linux-security-module,
linux-kernel, Casey Schaufler
On 11/28/2026 12:28 AM, shaos wrote:
> Hello,
>
> Smack does not implement the inode_file_getattr and inode_file_setattr
> hooks. As a result, the file_getattr() and file_setattr() system calls
> bypass Smack's existing read and write checks.
>
> 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. The Subject label has only
> read access to the Control label, yet file_setattr() clears the file
> flags on /mnt/control. Ordinary open() checks continue to be enforced.
>
> This bypass exposes file attribute metadata and permits changes to file
> attributes that the Smack policy denies. It does not expose file contents
> or demonstrate privilege escalation.
>
> Tested source revision:
> HEAD commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
> git tree: fe970b05333fb8e41da21e9e289f652abcc7cba7
> source version: Linux 7.4.0-rc4
> compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0,
> GNU ld 2.38
>
> console output:
> https://gist.githubusercontent.com/shaos26/fbf8b7f663ee82593d7d41623aa2e2c4/raw/2ad22ab46d2cf376b59ef361d9c7ca2b691c6eda/console-output.txt
> kernel config:
> https://gist.githubusercontent.com/shaos26/fbf8b7f663ee82593d7d41623aa2e2c4/raw/f9e1ceca2f52ead87738af313610fc49834654dc/kernel-config.txt
> reproducer:
> https://gist.githubusercontent.com/shaos26/fbf8b7f663ee82593d7d41623aa2e2c4/raw/d9b447aad65076391390d150d752b6b9cb116abc/poc.c
>
> Build the kernel at the tested revision with the attached configuration.
> The reproducer is a static init program and expects an ext4 image on
> /dev/vda containing empty files named secret, control, and public:
>
> truncate -s 32M smack.img
> mkfs.ext4 -F smack.img
> mkdir mnt
> mount -o loop smack.img mnt
> touch mnt/secret mnt/control mnt/public
> umount mnt
> gcc -O2 -Wall -Wextra -static -o poc poc.c
> mkdir -p rootfs
> cp poc rootfs/init
> chmod 0755 rootfs/init
> (cd rootfs && find . -print0 | cpio --null -o -H newc) |
> gzip -9 > initramfs.cpio.gz
>
> Boot the initramfs and ext4 image with:
>
> qemu-system-x86_64 -m 2G -smp 2 \
> -kernel <linux-tree>/arch/x86/boot/bzImage \
> -initrd initramfs.cpio.gz \
> -drive file=smack.img,format=raw,if=virtio \
> -append 'console=ttyS0 rdinit=/init lsm=smack loglevel=7' \
> -nographic -monitor none -no-reboot
>
> On two vulnerable boots, file_getattr() on /mnt/secret returned success
> while stat() returned -EACCES. file_setattr() on /mnt/control also
> returned success and cleared its flags. With this patch, both denied
> operations return -EACCES; permitted operations on /mnt/public still
> succeed.
>
> Implement both hooks with the same Smack access checks used by the
> existing getattr and setattr hooks:
>
> Fixes: defdd02d783c ("lsm: introduce new hooks for setting/getting inode fsxattr")
> Signed-off-by: shaos <shawnq1@163.com>
> ---
> security/smack/smack_lsm.c | 30 ++++++++++++++++++++++++++++++
> 1 file changed, 30 insertions(+)
>
> diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
> index 3a4a33568297b..6da2492f9bb61 100644
> --- a/security/smack/smack_lsm.c
> +++ b/security/smack/smack_lsm.c
> @@ -1311,6 +1311,34 @@ static int smack_inode_getattr(const struct path *path)
> return rc;
> }
>
Please include a kernel-doc comment on each of these functions.
> +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;
> +}
> +
> +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 +5213,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),
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-28 17:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-28 8:28 [PATCH] smack: mediate file attribute syscalls shaos
2026-11-28 17:37 ` Casey Schaufler
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®