[PATCH -next] tomoyo: check file getattr permission in file_getattr()
Christopher Lusk via B4 Relay
devnull+clusk.northecho.dev at kernel.org
Sun Nov 29 15:23:52 UTC 2026
From: Christopher Lusk <clusk at northecho.dev>
file_getattr(2) reaches the path_file_getattr hook but not path_getattr.
TOMOYO does not implement path_file_getattr, so "file getattr" is not
checked: in a domain that enforces file::getattr, stat() on a path
without a "file getattr" entry fails with EPERM, but file_getattr() on
the same path succeeds and returns the file's attribute flags and
project ID.
Check "file getattr" in the path_file_getattr hook, as
tomoyo_path_getattr() does for stat(). The FS_IOC_GETFLAGS and
FS_IOC_FSGETXATTR ioctls reach the same hook, so they now need
"file getattr" in addition to "file ioctl", as fstat() does.
Found with LLM-assisted testing of LSM hook coverage.
Fixes: be7efb2d20d6 ("fs: introduce file_getattr and file_setattr syscalls")
Signed-off-by: Christopher Lusk <clusk at northecho.dev>
---
This is on top of Cai Xinchen's "landlock: Add READ_METADATA and
WRITE_METADATA access rights" v4 [1], which passes a struct path to the
fileattr hooks. In mainline the hook gets only a dentry, which TOMOYO
cannot turn into the pathname its policy matches, so the fix needs a
path. Cai, please fold this into your series if that is easier; I can
rebase it on v5.
Tested in QEMU on next-20261116 plus Cai's v4, with and without this
patch. In a domain whose profile enforces only file::getattr, with
"file getattr" allowed on one file, uid 1000 on another file gets:
without with
stat() EPERM EPERM
file_getattr() ok EPERM
file_getattr(AT_EMPTY_PATH) ok EPERM
ioctl(FS_IOC_FSGETXATTR) ok EPERM
file_setattr() ok ok
Each denial is logged as "file getattr <path>". The allowed file works
on both kernels. Same results in three fresh VMs per kernel.
Two questions for Tetsuo:
- With this patch FS_IOC_GETFLAGS and FS_IOC_FSGETXATTR need
"file getattr" as well as "file ioctl". The same applies on the real
path under stacked filesystems: overlayfs, whose copy-up already
checks those ioctls there, and ecryptfs, on the lower path. Is that
what you want?
- TOMOYO does not check file_setattr(2), while FS_IOC_FSSETXATTR is
checked as "file ioctl". No TOMOYO permission seems to fit attribute
changes, so I left it alone. Should it map to one?
The gap was found with LLM-assisted testing. The patch and the test were
written with an AI coding assistant (Claude); I reviewed the change and
checked the results.
[1] https://lore.kernel.org/r/20261117150542.1169451-1-caixinchen1@huawei.com
---
security/tomoyo/tomoyo.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
index cf0090df7eab..5d0fe089919e 100644
--- a/security/tomoyo/tomoyo.c
+++ b/security/tomoyo/tomoyo.c
@@ -125,6 +125,21 @@ static int tomoyo_path_getattr(const struct path *path,
return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, path, NULL);
}
+/**
+ * tomoyo_path_file_getattr - Target for security_path_file_getattr().
+ *
+ * @path: Pointer to "struct path".
+ * @fa: Pointer to "struct file_kattr".
+ * @file: Pointer to "struct file", or NULL.
+ *
+ * Returns 0 on success, negative value otherwise.
+ */
+static int tomoyo_path_file_getattr(const struct path *path,
+ struct file_kattr *fa, struct file *file)
+{
+ return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, path, NULL);
+}
+
/**
* tomoyo_path_truncate - Target for security_path_truncate().
*
@@ -573,6 +588,7 @@ static struct security_hook_list tomoyo_hooks[] __ro_after_init = {
LSM_HOOK_INIT(path_link, tomoyo_path_link),
LSM_HOOK_INIT(path_rename, tomoyo_path_rename),
LSM_HOOK_INIT(path_getattr, tomoyo_path_getattr),
+ LSM_HOOK_INIT(path_file_getattr, tomoyo_path_file_getattr),
LSM_HOOK_INIT(file_ioctl, tomoyo_file_ioctl),
LSM_HOOK_INIT(file_ioctl_compat, tomoyo_file_ioctl),
LSM_HOOK_INIT(path_chmod, tomoyo_path_chmod),
---
base-commit: 749a4de370409464cf8501ec5b2451df45c84eb4
change-id: 20261129-tomoyo-file-getattr-9c5be65b1a70
Best regards,
--
Christopher Lusk <clusk at northecho.dev>
More information about the Linux-security-module-archive
mailing list