From: sashiko-bot@kernel.org
To: "Cai Xinchen" <caixinchen1@huawei.com>
Cc: bpf@vger.kernel.org, linux-security-module@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, selinux@vger.kernel.org,
dsterba@suse.cz, "Chuck Lever" <cel@kernel.org>,
"Jeff Layton" <jlayton@kernel.org>,
"Anna Schumaker" <anna@kernel.org>
Subject: Re: [PATCH -next -v4 14/17] landlock: Add READ_METADATA and WRITE_METADATA access rights
Date: Tue, 17 Nov 2026 15:49:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-219110@kernel.org> (raw)
In-Reply-To: <20261117150542.1169451-15-caixinchen1@huawei.com>
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
next prev parent reply other threads:[~2026-11-17 15:49 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` [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 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: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 ` [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 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 [this message]
2026-11-17 15:05 ` [PATCH -next -v4 15/17] selftests/landlock: Add tests for metadata " Cai Xinchen
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
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=sashiko-outbox-219110@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=anna@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=caixinchen1@huawei.com \
--cc=cel@kernel.org \
--cc=dsterba@suse.cz \
--cc=jlayton@kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=selinux@vger.kernel.org \
/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