All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ntfs: avoid re-locking the parent for stream timestamps
@ 2026-11-26  3:40 shaos
  2026-11-28  1:04 ` Namjae Jeon
  0 siblings, 1 reply; 9+ messages in thread
From: shaos @ 2026-11-26  3:40 UTC (permalink / raw)
  To: Namjae Jeon; +Cc: Hyunchul Lee, ntfs, stable

Hello,

The VFS holds a directory's i_rwsem while calling ->create() and
->unlink(). A legacy NTFS named-stream path can use that same directory
as the stream's base inode. Creating or removing the stream then calls
ntfs_stream_update_base_time(), which attempts to acquire the already
held i_rwsem and leaves the caller blocked in down_write_nested().

Pass the VFS-locked parent to the timestamp update path. When the base
inode is that parent, update its timestamps under the lock already
held. Other callers retain the existing lock and update behavior.

A crafted NTFS directory entry reproduces both create and unlink
deadlocks as uid 65534. The same operations complete with this change.
The unlink harness also emits a lockdep circular-dependency warning
during stream setup on both the vulnerable and fixed kernels. That
warning is separate from the reproduced self-deadlock and is not
claimed to be fixed here.

HEAD commit:    8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
Git tree:       fe970b05333fb8e41da21e9e289f652abcc7cba7
Source version: Linux 7.4.0-rc4
Compiler:       gcc 11.4.0, GNU ld 2.38
Test runtime:   QEMU 6.2.0, x86-64 TCG

The evidence, create and unlink PoCs, and image/initramfs helpers are
in this unlisted Gist:

https://gist.github.com/shaos26/eb846131f7945b8541b2f1b99fd5c34e

Console output:
https://gist.githubusercontent.com/shaos26/eb846131f7945b8541b2f1b99fd5c34e/raw/c9b6fcec4363c6b1ea2f168f12a2b4918dd29af3/console-output.txt
Kernel config:
https://gist.githubusercontent.com/shaos26/eb846131f7945b8541b2f1b99fd5c34e/raw/c9b6fcec4363c6b1ea2f168f12a2b4918dd29af3/kernel-config.txt
Create PoC:
https://gist.githubusercontent.com/shaos26/eb846131f7945b8541b2f1b99fd5c34e/raw/c9b6fcec4363c6b1ea2f168f12a2b4918dd29af3/poc.c
Unlink PoC:
https://gist.githubusercontent.com/shaos26/eb846131f7945b8541b2f1b99fd5c34e/raw/c9b6fcec4363c6b1ea2f168f12a2b4918dd29af3/unlink-poc.c

The reproduction script needs QEMU and the ntfs-3g tools mkntfs,
ntfscp, and ntfsinfo. It builds the test kernel and initramfs, creates
fresh crafted images, and runs create, unlink, and normal-image control
cases:

    git clone https://gist.github.com/eb846131f7945b8541b2f1b99fd5c34e.git repro
    git -C repro checkout c9b6fcec4363c6b1ea2f168f12a2b4918dd29af3
    chmod +x repro/*.sh
    ./repro/reproduce.sh

The vulnerable create runs reached D state in down_write_nested() with
ntfs_stream_update_base_time() on the stack. On the patched kernel,
create returned instead of hanging; unlink completed with rc=0. The
normal-image control also completed. The unlink logs retain the
independent lockdep warning described above.

Fixes: 3f11c48d4f94 ("ntfs: add pathname access for named streams")
Cc: stable@vger.kernel.org
Signed-off-by: shaos <shawnq1@163.com>

---
 fs/ntfs/named_stream.c | 47 +++++++++++++++++++++++++++++++++++-------
 fs/ntfs/stream.h       |  3 ++-
 2 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/fs/ntfs/named_stream.c b/fs/ntfs/named_stream.c
index 70c5892077133..8bae9a9f53047 100644
--- a/fs/ntfs/named_stream.c
+++ b/fs/ntfs/named_stream.c
@@ -82,6 +82,13 @@ void ntfs_stream_inode_refresh(struct inode *vi)
 	vi->i_generation = base_vi->i_generation;
 }
 
+/* Caller must hold the base inode's i_rwsem. */
+static void ntfs_stream_set_base_time(struct inode *base_vi)
+{
+	inode_set_mtime_to_ts(base_vi, inode_set_ctime_current(base_vi));
+	mark_inode_dirty(base_vi);
+}
+
 /*
  * ntfs_stream_update_base_time() - Update base timestamps after a stream change
  * @base_ni: base inode containing the stream attribute
@@ -94,11 +101,32 @@ void ntfs_stream_update_base_time(struct ntfs_inode *base_ni)
 	struct inode *base_vi = VFS_I(base_ni);
 
 	inode_lock_nested(base_vi, I_MUTEX_PARENT);
-	inode_set_mtime_to_ts(base_vi, inode_set_ctime_current(base_vi));
-	mark_inode_dirty(base_vi);
+	ntfs_stream_set_base_time(base_vi);
 	inode_unlock(base_vi);
 }
 
+/*
+ * ntfs_update_base_time_for_dir() - Update base timestamps from
+ * a directory operation
+ * @base_ni: base inode containing the stream attribute
+ * @locked_dir: parent directory locked by the VFS, or NULL
+ *
+ * The VFS already holds @locked_dir's i_rwsem for create and unlink. Avoid
+ * recursively acquiring it when the base inode is that directory itself.
+ */
+static void ntfs_update_base_time_for_dir(struct ntfs_inode *base_ni,
+					  struct inode *locked_dir)
+{
+	struct inode *base_vi = VFS_I(base_ni);
+
+	if (base_vi != locked_dir) {
+		ntfs_stream_update_base_time(base_ni);
+		return;
+	}
+
+	ntfs_stream_set_base_time(base_vi);
+}
+
 /*
  * ntfs_stream_inode_validate() - Validate a named-stream inode
  * @vi: stream inode to validate
@@ -653,7 +681,7 @@ struct inode *ntfs_create_named_stream(const struct mnt_idmap *idmap,
 		}
 		mutex_unlock(&base_ni->mrec_lock);
 		if (stream_created)
-			ntfs_stream_update_base_time(base_ni);
+			ntfs_update_base_time_for_dir(base_ni, dir);
 		if (!IS_ERR(stream_vi))
 			iput(stream_vi);
 		if (rollback_vi)
@@ -663,7 +691,7 @@ struct inode *ntfs_create_named_stream(const struct mnt_idmap *idmap,
 	}
 	mutex_unlock(&base_ni->mrec_lock);
 	if (stream_created)
-		ntfs_stream_update_base_time(base_ni);
+		ntfs_update_base_time_for_dir(base_ni, dir);
 	iput(base_vi);
 	return stream_vi;
 
@@ -720,7 +748,7 @@ int ntfs_unlink_named_stream(struct inode *dir, struct dentry *dentry)
 	 * file write access. The shared helper enforces NTFS delete restrictions.
 	 */
 	err = ntfs_remove_named_stream(NTFS_I(base_vi), stream_name,
-			stream_len, dentry->d_inode);
+			stream_len, dentry->d_inode, dir);
 
 out_iput:
 	iput(base_vi);
@@ -1076,6 +1104,7 @@ int ntfs_stream_put(struct inode *vi)
  * @uname: UTF-16LE stream name
  * @uname_len: length of @uname in UTF-16 code units
  * @expected_vi: expected cached stream inode, or NULL
+ * @locked_dir: parent directory locked by the VFS, or NULL
  *
  * Refuse removal while the stream is open. If @expected_vi is non-NULL, it
  * must be the inode currently associated with the named attribute.
@@ -1084,7 +1113,8 @@ int ntfs_stream_put(struct inode *vi)
  * errno.
  */
 int ntfs_remove_named_stream(struct ntfs_inode *ni, __le16 *uname,
-		u32 uname_len, struct inode *expected_vi)
+		u32 uname_len, struct inode *expected_vi,
+		struct inode *locked_dir)
 {
 	struct inode *attr_vi;
 	struct ntfs_inode *attr_ni;
@@ -1137,7 +1167,7 @@ int ntfs_remove_named_stream(struct ntfs_inode *ni, __le16 *uname,
 
 	err = ntfs_stream_finish_remove(attr_vi);
 	if (!err)
-		ntfs_stream_update_base_time(ni);
+		ntfs_update_base_time_for_dir(ni, locked_dir);
 	iput(attr_vi);
 	return err;
 
@@ -1444,7 +1474,8 @@ static long ntfs_ioctl_stream(struct file *filp, unsigned long arg,
 		err = mnt_want_write_file(filp);
 		if (err)
 			goto out_free;
-		err = ntfs_remove_named_stream(base_ni, sname, sname_len, NULL);
+		err = ntfs_remove_named_stream(base_ni, sname,
+					       sname_len, NULL, NULL);
 		mnt_drop_write_file(filp);
 		goto out_free;
 	}
diff --git a/fs/ntfs/stream.h b/fs/ntfs/stream.h
index 76b6c9cca5cc0..18b20e7d7ff48 100644
--- a/fs/ntfs/stream.h
+++ b/fs/ntfs/stream.h
@@ -46,7 +46,8 @@ bool ntfs_stream_unlinked(struct ntfs_inode *base_ni,
 		const __le16 *name, u32 name_len);
 int ntfs_stream_put(struct inode *inode);
 int ntfs_remove_named_stream(struct ntfs_inode *ni, __le16 *name,
-		u32 name_len, struct inode *expected_inode);
+		u32 name_len, struct inode *expected_inode,
+		struct inode *locked_dir);
 
 int ntfs_stream_validate_for_mutation(struct inode *inode, bool nowait);
 long ntfs_ioctl_stream_read(struct file *file, unsigned long arg);
-- 
2.34.1


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

* Re: [PATCH] ntfs: avoid re-locking the parent for stream timestamps
  2026-11-26  3:40 [PATCH] ntfs: avoid re-locking the parent for stream timestamps shaos
@ 2026-11-28  1:04 ` Namjae Jeon
  2026-12-01 14:18   ` [PATCH v2] " Shawn Shao
  0 siblings, 1 reply; 9+ messages in thread
From: Namjae Jeon @ 2026-11-28  1:04 UTC (permalink / raw)
  To: shaos; +Cc: Hyunchul Lee, ntfs, stable

> Fixes: 3f11c48d4f94 ("ntfs: add pathname access for named streams")
> Cc: stable@vger.kernel.org
> Signed-off-by: shaos <shawnq1@163.com>
Please use your real name.
Thanks.

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

* [PATCH] smack: mediate file attribute syscalls
@ 2026-11-28  8:28 shaos
  2026-11-28  8:46 ` sashiko-bot
  2026-11-28 17:37 ` Casey Schaufler
  0 siblings, 2 replies; 9+ 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 related	[flat|nested] 9+ 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  8:46 ` sashiko-bot
  2026-11-28 17:37 ` Casey Schaufler
  1 sibling, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-28  8:46 UTC (permalink / raw)
  Cc: linux-security-module

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] smack: missing IS_PRIVATE() check in
  smack_inode_file_getattr() and setattr
- [Low] smack: overly verbose commit message with greeting and
  reproducer harness
--

commit b900878f18c1c73fc5f6dfbdfbd197ec123d665a
Author: shaos <shawnq1@163.com>

> smack: mediate file attribute syscalls
> 
> 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>

[Severity: Low]
This isn't a bug, but the commit message includes an email greeting,
external gist URLs, step-by-step QEMU reproduction instructions, and a
trailing colon before the Fixes: trailer.  Could the greeting, ephemeral
links, and test harness instructions be moved below the "---" tearline so
the commit log stays concise?

> diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
> index 8e88ac65fd7fc..9ea1c574156f5 100644
> --- a/security/smack/smack_lsm.c
> +++ b/security/smack/smack_lsm.c
> @@ -1308,6 +1308,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;
> +}

[Severity: Medium]
Should smack_inode_file_getattr() and smack_inode_file_setattr() skip
IS_PRIVATE(inode) inodes?

Unlike security_inode_getattr() and security_inode_setattr(),
security_inode_file_getattr() and security_inode_file_setattr() do not
filter out IS_PRIVATE() inodes before invoking the LSM hooks:

security/security.c:security_inode_file_setattr() {
	return call_int_hook(inode_file_setattr, dentry, fa);
}

When a task calls ioctl(fd, FS_IOC_GETFLAGS) or ioctl(fd, FS_IOC_SETFLAGS)
on a kernel-internal S_PRIVATE tmpfs inode (such as an anonymous shared
mapping passed across a Smack label transition), smack_file_ioctl()
explicitly returns 0 for IS_PRIVATE(inode), but vfs_fileattr_get() and
vfs_fileattr_set() then call into these new hooks and fail with -EACCES if
the current task's label cannot access the label of the task that created
the inode.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261128082823.3074924-1-shawnq1@163.com?part=1

^ permalink raw reply	[flat|nested] 9+ 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  8:46 ` sashiko-bot
@ 2026-11-28 17:37 ` Casey Schaufler
  2026-11-30  7:48   ` [PATCH v2] " Shawn Shao
  1 sibling, 1 reply; 9+ 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] 9+ messages in thread

* [PATCH v2] smack: mediate file attribute syscalls
  2026-11-28 17:37 ` Casey Schaufler
@ 2026-11-30  7:48   ` Shawn Shao
  2026-11-30  8:00     ` sashiko-bot
  2026-12-01 22:36     ` Casey Schaufler
  0 siblings, 2 replies; 9+ messages in thread
From: Shawn Shao @ 2026-11-30  7:48 UTC (permalink / raw)
  To: casey
  Cc: Paul Moore, James Morris, Serge E. Hallyn, linux-security-module,
	linux-kernel

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


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

* Re: [PATCH v2] smack: mediate file attribute syscalls
  2026-11-30  7:48   ` [PATCH v2] " Shawn Shao
@ 2026-11-30  8:00     ` sashiko-bot
  2026-12-01 22:36     ` Casey Schaufler
  1 sibling, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-30  8:00 UTC (permalink / raw)
  Cc: linux-security-module

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] smack: missing IS_PRIVATE() check in
  smack_inode_file_getattr() and setattr
- [Low] smack: conversational reply and revision notes in commit message
--

commit def34cb2a8662edb62c35fd5980f1b8b6195ff82
Author: Shawn Shao <shawnq1@163.com>

> smack: mediate file attribute syscalls
>
> 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>

[Severity: Low]
This isn't a bug, but the conversational reply ("Hello, Thanks for the
review..."), v1 comparison notes, local build environment details, and
external gist URL should be moved below the "---" tearline so they do not
become part of the permanent git commit log.

> diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
> index 8e88ac65fd7fc..da0aab6812b99 100644
> --- a/security/smack/smack_lsm.c
> +++ b/security/smack/smack_lsm.c
> @@ -1308,6 +1308,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;
> +}

[Severity: Medium]
Should smack_inode_file_getattr() and smack_inode_file_setattr() return 0
when IS_PRIVATE(inode) is true?

Unlike security_inode_getattr() and security_inode_setattr(),
security_inode_file_getattr() and security_inode_file_setattr() do not
filter out S_PRIVATE inodes before invoking the LSM hooks:

security/security.c:security_inode_file_setattr() {
	return call_int_hook(inode_file_setattr, dentry, fa);
}

Other Smack hooks whose LSM wrappers do not check IS_PRIVATE(), such as
smack_file_ioctl() and smack_file_receive(), explicitly check
IS_PRIVATE(inode).  Without that check here, vfs_fileattr_get() and
vfs_fileattr_set() (for example via FS_IOC_GETFLAGS or file_getattr()) on
an S_PRIVATE tmpfs inode received over SCM_RIGHTS or retained across a
Smack label change will fail with -EACCES when the caller's label lacks
access to the allocator's label.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130074845.2537541-1-shawnq1@163.com?part=1

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

* [PATCH v2] ntfs: avoid re-locking the parent for stream timestamps
  2026-11-28  1:04 ` Namjae Jeon
@ 2026-12-01 14:18   ` Shawn Shao
  0 siblings, 0 replies; 9+ messages in thread
From: Shawn Shao @ 2026-12-01 14:18 UTC (permalink / raw)
  To: Namjae Jeon; +Cc: Hyunchul Lee, ntfs, stable

Hello Namjae,

Thanks for the reminder. This version corrects the From and
Signed-off-by names; the code is unchanged.

Hello,

The VFS holds a directory's i_rwsem while calling ->create() and
->unlink(). A legacy NTFS named-stream path can use that same directory
as the stream's base inode. Creating or removing the stream then calls
ntfs_stream_update_base_time(), which attempts to acquire the already
held i_rwsem and leaves the caller blocked in down_write_nested().

Pass the VFS-locked parent to the timestamp update path. When the base
inode is that parent, update its timestamps under the lock already
held. Other callers retain the existing lock and update behavior.

A crafted NTFS directory entry reproduces both create and unlink
deadlocks as uid 65534. The same operations complete with this change.
The unlink harness also emits a lockdep circular-dependency warning
during stream setup on both the vulnerable and fixed kernels. That
warning is separate from the reproduced self-deadlock and is not
claimed to be fixed here.

HEAD commit:    8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
Git tree:       fe970b05333fb8e41da21e9e289f652abcc7cba7
Source version: Linux 7.4.0-rc4
Compiler:       gcc 11.4.0, GNU ld 2.38
Test runtime:   QEMU 6.2.0, x86-64 TCG

The evidence, create and unlink PoCs, and image/initramfs helpers are
in this unlisted Gist:

https://gist.github.com/shaos26/eb846131f7945b8541b2f1b99fd5c34e

Console output:
https://gist.githubusercontent.com/shaos26/eb846131f7945b8541b2f1b99fd5c34e/raw/c9b6fcec4363c6b1ea2f168f12a2b4918dd29af3/console-output.txt
Kernel config:
https://gist.githubusercontent.com/shaos26/eb846131f7945b8541b2f1b99fd5c34e/raw/c9b6fcec4363c6b1ea2f168f12a2b4918dd29af3/kernel-config.txt
Create PoC:
https://gist.githubusercontent.com/shaos26/eb846131f7945b8541b2f1b99fd5c34e/raw/c9b6fcec4363c6b1ea2f168f12a2b4918dd29af3/poc.c
Unlink PoC:
https://gist.githubusercontent.com/shaos26/eb846131f7945b8541b2f1b99fd5c34e/raw/c9b6fcec4363c6b1ea2f168f12a2b4918dd29af3/unlink-poc.c

The reproduction script needs QEMU and the ntfs-3g tools mkntfs,
ntfscp, and ntfsinfo. It builds the test kernel and initramfs, creates
fresh crafted images, and runs create, unlink, and normal-image control
cases:

    git clone https://gist.github.com/eb846131f7945b8541b2f1b99fd5c34e.git repro
    git -C repro checkout c9b6fcec4363c6b1ea2f168f12a2b4918dd29af3
    chmod +x repro/*.sh
    ./repro/reproduce.sh

The vulnerable create runs reached D state in down_write_nested() with
ntfs_stream_update_base_time() on the stack. On the patched kernel,
create returned instead of hanging; unlink completed with rc=0. The
normal-image control also completed. The unlink logs retain the
independent lockdep warning described above.

Fixes: 3f11c48d4f94 ("ntfs: add pathname access for named streams")
Cc: stable@vger.kernel.org
Changes in v2:
- Use my full name in From and Signed-off-by.

Thanks,
Shawn Shao

Signed-off-by: Shawn Shao <shawnq1@163.com>

---
 fs/ntfs/named_stream.c | 47 +++++++++++++++++++++++++++++++++++-------
 fs/ntfs/stream.h       |  3 ++-
 2 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/fs/ntfs/named_stream.c b/fs/ntfs/named_stream.c
index 70c5892077133..8bae9a9f53047 100644
--- a/fs/ntfs/named_stream.c
+++ b/fs/ntfs/named_stream.c
@@ -82,6 +82,13 @@ void ntfs_stream_inode_refresh(struct inode *vi)
 	vi->i_generation = base_vi->i_generation;
 }
 
+/* Caller must hold the base inode's i_rwsem. */
+static void ntfs_stream_set_base_time(struct inode *base_vi)
+{
+	inode_set_mtime_to_ts(base_vi, inode_set_ctime_current(base_vi));
+	mark_inode_dirty(base_vi);
+}
+
 /*
  * ntfs_stream_update_base_time() - Update base timestamps after a stream change
  * @base_ni: base inode containing the stream attribute
@@ -94,11 +101,32 @@ void ntfs_stream_update_base_time(struct ntfs_inode *base_ni)
 	struct inode *base_vi = VFS_I(base_ni);
 
 	inode_lock_nested(base_vi, I_MUTEX_PARENT);
-	inode_set_mtime_to_ts(base_vi, inode_set_ctime_current(base_vi));
-	mark_inode_dirty(base_vi);
+	ntfs_stream_set_base_time(base_vi);
 	inode_unlock(base_vi);
 }
 
+/*
+ * ntfs_update_base_time_for_dir() - Update base timestamps from
+ * a directory operation
+ * @base_ni: base inode containing the stream attribute
+ * @locked_dir: parent directory locked by the VFS, or NULL
+ *
+ * The VFS already holds @locked_dir's i_rwsem for create and unlink. Avoid
+ * recursively acquiring it when the base inode is that directory itself.
+ */
+static void ntfs_update_base_time_for_dir(struct ntfs_inode *base_ni,
+					  struct inode *locked_dir)
+{
+	struct inode *base_vi = VFS_I(base_ni);
+
+	if (base_vi != locked_dir) {
+		ntfs_stream_update_base_time(base_ni);
+		return;
+	}
+
+	ntfs_stream_set_base_time(base_vi);
+}
+
 /*
  * ntfs_stream_inode_validate() - Validate a named-stream inode
  * @vi: stream inode to validate
@@ -653,7 +681,7 @@ struct inode *ntfs_create_named_stream(const struct mnt_idmap *idmap,
 		}
 		mutex_unlock(&base_ni->mrec_lock);
 		if (stream_created)
-			ntfs_stream_update_base_time(base_ni);
+			ntfs_update_base_time_for_dir(base_ni, dir);
 		if (!IS_ERR(stream_vi))
 			iput(stream_vi);
 		if (rollback_vi)
@@ -663,7 +691,7 @@ struct inode *ntfs_create_named_stream(const struct mnt_idmap *idmap,
 	}
 	mutex_unlock(&base_ni->mrec_lock);
 	if (stream_created)
-		ntfs_stream_update_base_time(base_ni);
+		ntfs_update_base_time_for_dir(base_ni, dir);
 	iput(base_vi);
 	return stream_vi;
 
@@ -720,7 +748,7 @@ int ntfs_unlink_named_stream(struct inode *dir, struct dentry *dentry)
 	 * file write access. The shared helper enforces NTFS delete restrictions.
 	 */
 	err = ntfs_remove_named_stream(NTFS_I(base_vi), stream_name,
-			stream_len, dentry->d_inode);
+			stream_len, dentry->d_inode, dir);
 
 out_iput:
 	iput(base_vi);
@@ -1076,6 +1104,7 @@ int ntfs_stream_put(struct inode *vi)
  * @uname: UTF-16LE stream name
  * @uname_len: length of @uname in UTF-16 code units
  * @expected_vi: expected cached stream inode, or NULL
+ * @locked_dir: parent directory locked by the VFS, or NULL
  *
  * Refuse removal while the stream is open. If @expected_vi is non-NULL, it
  * must be the inode currently associated with the named attribute.
@@ -1084,7 +1113,8 @@ int ntfs_stream_put(struct inode *vi)
  * errno.
  */
 int ntfs_remove_named_stream(struct ntfs_inode *ni, __le16 *uname,
-		u32 uname_len, struct inode *expected_vi)
+		u32 uname_len, struct inode *expected_vi,
+		struct inode *locked_dir)
 {
 	struct inode *attr_vi;
 	struct ntfs_inode *attr_ni;
@@ -1137,7 +1167,7 @@ int ntfs_remove_named_stream(struct ntfs_inode *ni, __le16 *uname,
 
 	err = ntfs_stream_finish_remove(attr_vi);
 	if (!err)
-		ntfs_stream_update_base_time(ni);
+		ntfs_update_base_time_for_dir(ni, locked_dir);
 	iput(attr_vi);
 	return err;
 
@@ -1444,7 +1474,8 @@ static long ntfs_ioctl_stream(struct file *filp, unsigned long arg,
 		err = mnt_want_write_file(filp);
 		if (err)
 			goto out_free;
-		err = ntfs_remove_named_stream(base_ni, sname, sname_len, NULL);
+		err = ntfs_remove_named_stream(base_ni, sname,
+					       sname_len, NULL, NULL);
 		mnt_drop_write_file(filp);
 		goto out_free;
 	}
diff --git a/fs/ntfs/stream.h b/fs/ntfs/stream.h
index 76b6c9cca5cc0..18b20e7d7ff48 100644
--- a/fs/ntfs/stream.h
+++ b/fs/ntfs/stream.h
@@ -46,7 +46,8 @@ bool ntfs_stream_unlinked(struct ntfs_inode *base_ni,
 		const __le16 *name, u32 name_len);
 int ntfs_stream_put(struct inode *inode);
 int ntfs_remove_named_stream(struct ntfs_inode *ni, __le16 *name,
-		u32 name_len, struct inode *expected_inode);
+		u32 name_len, struct inode *expected_inode,
+		struct inode *locked_dir);
 
 int ntfs_stream_validate_for_mutation(struct inode *inode, bool nowait);
 long ntfs_ioctl_stream_read(struct file *file, unsigned long arg);
-- 
2.34.1


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

* Re: [PATCH v2] smack: mediate file attribute syscalls
  2026-11-30  7:48   ` [PATCH v2] " Shawn Shao
  2026-11-30  8:00     ` sashiko-bot
@ 2026-12-01 22:36     ` Casey Schaufler
  1 sibling, 0 replies; 9+ messages in thread
From: Casey Schaufler @ 2026-12-01 22:36 UTC (permalink / raw)
  To: Shawn Shao
  Cc: Paul Moore, James Morris, Serge E. Hallyn, linux-security-module,
	linux-kernel, Casey Schaufler

On 11/29/2026 11:48 PM, Shawn Shao wrote:
> 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>

Applied to smack-next. Thank you.

> ---
> 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),

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

end of thread, other threads:[~2026-12-01 22:36 UTC | newest]

Thread overview: 9+ 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  8:46 ` sashiko-bot
2026-11-28 17:37 ` Casey Schaufler
2026-11-30  7:48   ` [PATCH v2] " Shawn Shao
2026-11-30  8:00     ` sashiko-bot
2026-12-01 22:36     ` Casey Schaufler
  -- strict thread matches above, loose matches on Subject: below --
2026-11-26  3:40 [PATCH] ntfs: avoid re-locking the parent for stream timestamps shaos
2026-11-28  1:04 ` Namjae Jeon
2026-12-01 14:18   ` [PATCH v2] " Shawn Shao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.