Skip to content

Commit 0476fd4

Browse files
Tetsuo HandaTetsuo Handa
authored andcommitted
tomoyo: use realpath if symlink's pathname refers to procfs
Fedora 41 has reached Linux 6.12 kernel with TOMOYO enabled. I observed that /usr/lib/systemd/systemd executes /usr/lib/systemd/systemd-executor by passing dirfd == 9 or dirfd == 16 upon execveat(). Commit ada1986 ("tomoyo: fallback to realpath if symlink's pathname does not exist") used realpath only if symlink's pathname does not exist. But an out of tree patch suggested that it will be reasonable to always use realpath if symlink's pathname refers to proc filesystem. Therefore, this patch changes the pathname used for checking "file execute" and the domainname used after a successful execve() request. Before: <kernel> /usr/lib/systemd/systemd file execute proc:/self/fd/16 exec.realpath="/usr/lib/systemd/systemd-executor" exec.argv[0]="/usr/lib/systemd/systemd-executor" file execute proc:/self/fd/9 exec.realpath="/usr/lib/systemd/systemd-executor" exec.argv[0]="/usr/lib/systemd/systemd-executor" <kernel> /usr/lib/systemd/systemd proc:/self/fd/16 file execute /usr/sbin/auditd exec.realpath="/usr/sbin/auditd" exec.argv[0]="/usr/sbin/auditd" <kernel> /usr/lib/systemd/systemd proc:/self/fd/16 /usr/sbin/auditd <kernel> /usr/lib/systemd/systemd proc:/self/fd/9 file execute /usr/bin/systemctl exec.realpath="/usr/bin/systemctl" exec.argv[0]="/usr/bin/systemctl" <kernel> /usr/lib/systemd/systemd proc:/self/fd/9 /usr/bin/systemctl After: <kernel> /usr/lib/systemd/systemd file execute /usr/lib/systemd/systemd-executor exec.realpath="/usr/lib/systemd/systemd-executor" exec.argv[0]="/usr/lib/systemd/systemd-executor" <kernel> /usr/lib/systemd/systemd /usr/lib/systemd/systemd-executor file execute /usr/bin/systemctl exec.realpath="/usr/bin/systemctl" exec.argv[0]="/usr/bin/systemctl" file execute /usr/sbin/auditd exec.realpath="/usr/sbin/auditd" exec.argv[0]="/usr/sbin/auditd" <kernel> /usr/lib/systemd/systemd /usr/lib/systemd/systemd-executor /usr/bin/systemctl <kernel> /usr/lib/systemd/systemd /usr/lib/systemd/systemd-executor /usr/sbin/auditd Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
1 parent 3df7546 commit 0476fd4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

security/tomoyo/domain.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,17 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
722722
ee->bprm = bprm;
723723
ee->r.obj = &ee->obj;
724724
ee->obj.path1 = bprm->file->f_path;
725-
/* Get symlink's pathname of program. */
725+
/*
726+
* Get symlink's pathname of program, but fallback to realpath if
727+
* symlink's pathname does not exist or symlink's pathname refers
728+
* to proc filesystem (e.g. /dev/fd/<num> or /proc/self/fd/<num> ).
729+
*/
726730
exename.name = tomoyo_realpath_nofollow(original_name);
731+
if (exename.name && !strncmp(exename.name, "proc:/", 6)) {
732+
kfree(exename.name);
733+
exename.name = NULL;
734+
}
727735
if (!exename.name) {
728-
/* Fallback to realpath if symlink's pathname does not exist. */
729736
exename.name = tomoyo_realpath_from_path(&bprm->file->f_path);
730737
if (!exename.name)
731738
goto out;

0 commit comments

Comments
 (0)