]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tomoyo: fallback to realpath if symlink's pathname does not exist
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Wed, 25 Sep 2024 13:30:59 +0000 (22:30 +0900)
committerTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Wed, 25 Sep 2024 13:30:59 +0000 (22:30 +0900)
Alfred Agrell found that TOMOYO cannot handle execveat(AT_EMPTY_PATH)
inside chroot environment where /dev and /proc are not mounted, for
commit 51f39a1f0cea ("syscalls: implement execveat() system call") missed
that TOMOYO tries to canonicalize argv[0] when the filename fed to the
executed program as argv[0] is supplied using potentially nonexistent
pathname.

Since "/dev/fd/<fd>" already lost symlink information used for obtaining
that <fd>, it is too late to reconstruct symlink's pathname. Although
<filename> part of "/dev/fd/<fd>/<filename>" might not be canonicalized,
TOMOYO cannot use tomoyo_realpath_nofollow() when /dev or /proc is not
mounted. Therefore, fallback to tomoyo_realpath_from_path() when
tomoyo_realpath_nofollow() failed.

Reported-by: Alfred Agrell <blubban@gmail.com>
Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1082001
Fixes: 51f39a1f0cea ("syscalls: implement execveat() system call")
Cc: stable@vger.kernel.org # v3.19+
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
security/tomoyo/domain.c

index 90b53500a236bdcd5cb98c10fd63dd9844a2253c..aed9e3ef2c9ecb4673bfd7167a4a69e7a19ebe8c 100644 (file)
@@ -723,10 +723,13 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
        ee->r.obj = &ee->obj;
        ee->obj.path1 = bprm->file->f_path;
        /* Get symlink's pathname of program. */
-       retval = -ENOENT;
        exename.name = tomoyo_realpath_nofollow(original_name);
-       if (!exename.name)
-               goto out;
+       if (!exename.name) {
+               /* Fallback to realpath if symlink's pathname does not exist. */
+               exename.name = tomoyo_realpath_from_path(&bprm->file->f_path);
+               if (!exename.name)
+                       goto out;
+       }
        tomoyo_fill_path_info(&exename);
 retry:
        /* Check 'aggregator' directive. */