[PATCH STAGING v2 13/16] fchroot10: test failfs entry without no_new_privs
Andrea Cervesato <[email protected]>
| Newsgroups | gmane.linux.ltp |
|---|---|
| Message-ID | <[email protected]> |
From: Andrea Cervesato <andrea.cervesato-IBi9RG/[email protected]> Verify that unprivileged fchroot() into failfs is refused without no_new_privs: without it a setuid binary on a regular mount is still reachable via an inherited directory fd, and executing it with an unusable root directory is the classic confused deputy, so the kernel refuses the syscall with EPERM. Signed-off-by: Andrea Cervesato <andrea.cervesato-IBi9RG/[email protected]> --- runtest/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot10.c | 50 +++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/runtest/staging b/runtest/staging index 23f6c6a20..9ec2a7897 100644 --- a/runtest/staging +++ b/runtest/staging @@ -9,3 +9,4 @@ fchroot06 fchroot06 fchroot07 fchroot07 fchroot08 fchroot08 fchroot09 fchroot09 +fchroot10 fchroot10 diff --git a/testcases/kernel/syscalls/fchroot/.gitignore b/testcases/kernel/syscalls/fchroot/.gitignore index e803fa2b7..570da2b98 100644 --- a/testcases/kernel/syscalls/fchroot/.gitignore +++ b/testcases/kernel/syscalls/fchroot/.gitignore @@ -7,3 +7,4 @@ fchroot06 fchroot07 fchroot08 fchroot09 +fchroot10 diff --git a/testcases/kernel/syscalls/fchroot/fchroot10.c b/testcases/kernel/syscalls/fchroot/fchroot10.c new file mode 100644 index 000000000..0cce3e40a --- /dev/null +++ b/testcases/kernel/syscalls/fchroot/fchroot10.c @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2026 SUSE LLC Andrea Cervesato <andrea.cervesato-IBi9RG/[email protected]> + */ + +/*\ + * Test that unprivileged :manpage:`fchroot(2)` into failfs is refused + * without no_new_privs. + * + * Without no_new_privs a setuid binary on a regular mount is still + * reachable via an inherited directory file descriptor, and executing it + * with an unusable root directory is the classic confused deputy, so the + * kernel refuses the syscall with ``EPERM``. + * + * Root is required to drop to an unprivileged user in the forked child. + */ + +#define _GNU_SOURCE +#include <pwd.h> +#include "tst_test.h" +#include "lapi/fcntl.h" +#include "lapi/syscalls.h" + +static struct passwd *ltpuser; + +static void run(void) +{ + if (SAFE_FORK()) + return; + + SAFE_SETRESUID(ltpuser->pw_uid, ltpuser->pw_uid, + ltpuser->pw_uid); + + TST_EXP_FAIL(tst_syscall(__NR_fchroot, FD_FAILFS_ROOT, 0), + EPERM, "unprivileged fchroot() without no_new_privs"); + + exit(0); +} + +static void setup(void) +{ + ltpuser = SAFE_GETPWNAM("nobody"); +} + +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root = 1, + .forks_child = 1, +}; -- 2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp