[PATCH -next] tomoyo: check file getattr permission in file_getattr()
Christopher Lusk
clusk at northecho.dev
Sun Nov 29 16:32:06 UTC 2026
On Sun, Nov 29, 2026 at 10:23 AM Christopher Lusk <clusk at northecho.dev> wrote:
> 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.
"as fstat() does" is unclear: fstat() needs only "file getattr".
A second AI-assisted review found an overlayfs case that my notes
understate. Copy-up of a lower file with FS_SYNC_FL or FS_NOATIME_FL
reads the temporary upper file's attributes in ovl_copy_fileattr().
With this patch that read is checked against "file getattr" on the
work directory, which TOMOYO names relative to the upper filesystem.
On next-20261116 plus Cai's v4, with file::getattr enforcing and
"file getattr" allowed on the merged, lower and upper paths, an
O_WRONLY open of a lower-only file with chattr +S fails with EPERM:
file getattr dev(7,0):/work/work/#18
overlayfs: failed to retrieve upper fileattr (work/#18, err=-1)
Without the patch the open succeeds and the flag is copied up. A
lower file without flags is not affected. Same results in three fresh
VMs per kernel.
>From the code (not tested): FS_IOC_SETFLAGS and FS_IOC_FSSETXATTR on
overlayfs and ecryptfs also gain a "file getattr" check on the backing
path. do_vfs_fileattr_set() reads the old attributes with
__vfs_fileattr_get(), but the stacked ->fileattr_get() calls
vfs_fileattr_get() on the backing path.
Tetsuo, should TOMOYO check these internal backing-path reads? If not,
the hook cannot tell them apart from file_getattr(2) by path, since
both pass file == NULL, so it would need a change on the overlayfs
side or in the hook arguments. I can send a v2 either way.
Thanks,
Christopher
More information about the Linux-security-module-archive
mailing list