Skip to contentSkip to conversation

fchroot: add fchroot() testing suite

PATCH Applied Andrea Cervesato 4 participants 24 messages Oct 20

lore
Share & tools
lore
#0 lore raw

v5 cover fchroot: add fchroot() testing suite

fchroot() is a new syscall introduced in Linux v7.3 together with failfs, a kernel internal filesystem where every operation fails with EOPNOTSUPP. The syscall is the fd-based counterpart of chroot(2): it moves the process root to the directory referenced by a file descriptor, or to the failfs root via the FD_FAILFS_ROOT sentinel.

The series adds lapi fallback definitions for the new fd sentinels and adds 13 tests covering:

- the basic directory fd use case and the argument error paths (EINVAL, EBADF, ENOTDIR)
- the permission checks, both execute permission and CAP_SYS_CHROOT
- entering failfs as root: EOPNOTSUPP on every absolute lookup, unreachable working directory, root that can not be referenced or pinned, path walks anchored at file descriptors, execve blocked, fork inheritance and the setns() escape
- the unprivileged entry rules: no_new_privs, shared fs_struct and the already chrooted case

The testing suite creation has been assisted by GLM 5.3.

---
Changes in v5:
- drop syscall table commits already merged in master
- drop [STAGING] prefix and move runtest entries to runtest/syscalls
- remove redundant exit(0) in forked test processes
- fchroot04, fchroot11: use /dev/zero instead of /etc/passwd
- fchroot06: simplify upwards path construction and use SAFE_STAT()
- fchroot08, fchroot09: drop unnecessary symlink setup and open "/" directly
- fchroot09: clarify setns() escape description
- fchroot11: check unprivileged userns support before testing failfs block
- Link to v4: https://lore.kernel.org/[email protected]

Changes in v4:
- restore fchroot08 commit
- fix descriptions
- improve setup() inside tests
- Link to v3: https://lore.kernel.org/[email protected]

Changes in v3:
- remove order specific tests inside the descriptions
- fchroot07: add child
- fix snprintf() possible overflows
- fix tests using TST_EXP_* macros
- use stat(".", ..) where it's needed
- Link to v2: https://lore.kernel.org/[email protected]

Changes in v2:
- make description more readable
- invert fork() logic for the main test process
- fix the issues found by the agent
- Link to v1: https://lore.kernel.org/[email protected]

To: Linux Test Project <[email protected]>

---
Andrea Cervesato (14):
lapi: fallback fchroot() parameters
fchroot01: test fchroot() with a directory fd
fchroot02: test fchroot() invalid arguments
fchroot03: test fchroot() permission checks
fchroot04: test fchroot() into failfs as root
fchroot05: test failfs root can not be referenced
fchroot06: test path walks under failfs root
fchroot07: test execve blocked by failfs root
fchroot08: test failfs root fork inheritance
fchroot09: test setns escape from failfs root
fchroot10: test failfs entry without no_new_privs
fchroot11: test failfs entry with no_new_privs
fchroot12: test failfs entry with shared fs_struct
fchroot13: test failfs entry when chrooted

 include/lapi/fcntl.h                               |  13 +++
 runtest/syscalls                                   |  14 +++
 testcases/kernel/syscalls/fchroot/.gitignore       |  14 +++
 testcases/kernel/syscalls/fchroot/Makefile         |   7 ++
 testcases/kernel/syscalls/fchroot/fchroot01.c      |  56 ++++++++++
 testcases/kernel/syscalls/fchroot/fchroot02.c      |  75 +++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot03.c      |  70 ++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot04.c      |  67 +++++++++++
 testcases/kernel/syscalls/fchroot/fchroot05.c      |  73 ++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot06.c      | 124 +++++++++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot07.c      |  58 ++++++++++
 .../kernel/syscalls/fchroot/fchroot07_child.c      |  16 +++
 testcases/kernel/syscalls/fchroot/fchroot08.c      |  52 +++++++++
 testcases/kernel/syscalls/fchroot/fchroot09.c      |  68 +++++++++++
 testcases/kernel/syscalls/fchroot/fchroot10.c      |  52 +++++++++
 testcases/kernel/syscalls/fchroot/fchroot11.c      |  85 ++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot12.c      |  83 ++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot13.c      |  61 ++++++++++
 18 files changed, 988 insertions(+)

---
base-commit: 1aae0e4d9d1e2e7818fda773b372cee8fb856de7
change-id: 20260819-fchroot-66115fd0d497

Best regards,

Signature · 5 lines
Andrea Cervesato <[email protected]>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v5 1/14 lapi: fallback fchroot() parameters

From: Andrea Cervesato <[email protected]>

Add to fcntl.h fallback definitions:

- FD_PIDFS_ROOT
- FD_NSFS_ROOT
- FD_FAILFS_ROOT

---
 include/lapi/fcntl.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
include/lapi/fcntl.h +13 -0
index 6a9ef11ce..d70954ea7 100644
@@ -144,6 +144,19 @@
 # endif
 #endif
 
+/* Roots of kernel internal pseudo filesystems, usable as fd sentinels */
+#ifndef FD_PIDFS_ROOT
+# define FD_PIDFS_ROOT		-10002
+#endif
+
+#ifndef FD_NSFS_ROOT
+# define FD_NSFS_ROOT		-10003
+#endif
+
+#ifndef FD_FAILFS_ROOT
+# define FD_FAILFS_ROOT		-10004
+#endif
+
 #ifndef FALLOC_FL_KEEP_SIZE
 # define FALLOC_FL_KEEP_SIZE 1
 #endif
Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] lapi: fallback fchroot() parameters

In reply to Andrea Cervesato

Hi Andrea,

Quoted 1 line · Andrea Cervesato

lapi: fallback fchroot() parameters

--- [PATCH 5/14] ---

testcases/kernel/syscalls/fchroot/fchroot04.c

Quoted 3 lines
testcases/kernel/syscalls/fchroot/fchroot04.c +2 -0
+	TST_EXP_PASS(tst_syscall(__NR_fchroot, FD_FAILFS_ROOT, 0),
+		"fchroot() with the FD_FAILFS_ROOT sentinel");

High: Stop the child if this expectation fails; TST_EXP_PASS records a failure but continues execution. For example, root without CAP_SYS_CHROOT and without no_new_privs gets EPERM, then mkdir("/foo") can create a directory in the real root that tmpdir cleanup never removes. Check TST_PASS and exit before executing the absolute-path operations.

--- [PATCH 6/14] ---

testcases/kernel/syscalls/fchroot/fchroot05.c

Quoted 4 lines
testcases/kernel/syscalls/fchroot/fchroot05.c +3 -0
+	len = readlinkat(procfd, "self/root", buf, sizeof(buf) - 1);
+	if (len < 0) {
+		tst_res(TFAIL | TTERRNO, "readlinkat() of /proc/self/root");

Low: TTERRNO still reads the preceding fstatat() error from TST_ERR, not readlinkat()'s errno. Wrap readlinkat() in TEST() or TST_EXP_POSITIVE() so a failure reports the actual error.

--- [PATCH 8/14] ---

testcases/kernel/syscalls/fchroot/fchroot07.c

Quoted 2 lines
testcases/kernel/syscalls/fchroot/fchroot07.c +1 -0
+	SAFE_WAIT(NULL);

High: A successfully executed helper can fail in tst_reinit() while reopening its absolute IPC pathname under failfs, before it can publish TFAIL through shared memory. SAFE_WAIT(NULL) discards that nonzero exit, leaving only the earlier fchroot TPASS and a false pass. Use tst_reap_children() to retain child-failure detection.

testcases/kernel/syscalls/fchroot/fchroot07.c

Quoted 2 lines
testcases/kernel/syscalls/fchroot/fchroot07.c +2 -0
+	if (tst_get_path(CHILD_EXEC, child_path, sizeof(child_path)))
+		tst_brk(TCONF, "Couldn't find %s in $PATH", CHILD_EXEC);

Medium: Make child_path absolute before entering failfs. Despite its API comment, tst_get_path() returns ./fchroot07_child when the helper is found through an empty or relative PATH component, including the empty component inserted by the framework when running from the build directory. This tests relative execution and, for a dynamic binary, its interpreter lookup rather than the claimed absolute executable lookup.

--- [PATCH 12/14] ---

testcases/kernel/syscalls/fchroot/fchroot11.c

Quoted 5 lines
testcases/kernel/syscalls/fchroot/fchroot11.c +4 -0
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_USER_NS=y",
+		NULL,
+	}

Medium: Gate only the user-namespace subcase, not the entire test. Unprivileged failfs entry with no_new_privs works without CONFIG_USER_NS, but this descriptor skips its success and lookup checks as well. Keep those checks enabled and report TCONF only for the unavailable namespace subcase.

Verdict - Needs revision

Pre-existing issue: include/tst_fs.h documents tst_get_path() as returning an absolute path, but lib/get_path.c preserves relative PATH entries.

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] lapi: fallback fchroot() parameters

Quoted 7 lines

Hi Andrea,

Quoted 1 line · Andrea Cervesato

lapi: fallback fchroot() parameters

--- [PATCH 5/14] ---

Quoted 9 lines

testcases/kernel/syscalls/fchroot/fchroot04.c

Quoted 3 lines
testcases/kernel/syscalls/fchroot/fchroot04.c +2 -0
+	TST_EXP_PASS(tst_syscall(__NR_fchroot, FD_FAILFS_ROOT, 0),
+		"fchroot() with the FD_FAILFS_ROOT sentinel");

High: Stop the child if this expectation fails; TST_EXP_PASS records a failure but continues execution. For example, root without CAP_SYS_CHROOT and without no_new_privs gets EPERM, then mkdir("/foo") can create a directory in the real root that tmpdir cleanup never removes. Check TST_PASS and exit before executing the absolute-path operations.

Valid

Quoted 12 lines

--- [PATCH 6/14] ---

testcases/kernel/syscalls/fchroot/fchroot05.c

Quoted 4 lines
testcases/kernel/syscalls/fchroot/fchroot05.c +3 -0
+	len = readlinkat(procfd, "self/root", buf, sizeof(buf) - 1);
+	if (len < 0) {
+		tst_res(TFAIL | TTERRNO, "readlinkat() of /proc/self/root");

Low: TTERRNO still reads the preceding fstatat() error from TST_ERR, not readlinkat()'s errno. Wrap readlinkat() in TEST() or TST_EXP_POSITIVE() so a failure reports the actual error.

Valid

Quoted 11 lines

--- [PATCH 8/14] ---

testcases/kernel/syscalls/fchroot/fchroot07.c

Quoted 2 lines
testcases/kernel/syscalls/fchroot/fchroot07.c +1 -0
+	SAFE_WAIT(NULL);

High: A successfully executed helper can fail in tst_reinit() while reopening its absolute IPC pathname under failfs, before it can publish TFAIL through shared memory. SAFE_WAIT(NULL) discards that nonzero exit, leaving only the earlier fchroot TPASS and a false pass. Use tst_reap_children() to retain child-failure detection.

Quoted 9 lines

testcases/kernel/syscalls/fchroot/fchroot07.c

Quoted 2 lines
testcases/kernel/syscalls/fchroot/fchroot07.c +2 -0
+	if (tst_get_path(CHILD_EXEC, child_path, sizeof(child_path)))
+		tst_brk(TCONF, "Couldn't find %s in $PATH", CHILD_EXEC);

Medium: Make child_path absolute before entering failfs. Despite its API comment, tst_get_path() returns ./fchroot07_child when the helper is found through an empty or relative PATH component, including the empty component inserted by the framework when running from the build directory. This tests relative execution and, for a dynamic binary, its interpreter lookup rather than the claimed absolute executable lookup.

All failfs assumptions don't make any sense, let's skip these.

Quoted 14 lines

--- [PATCH 12/14] ---

testcases/kernel/syscalls/fchroot/fchroot11.c

Quoted 5 lines
testcases/kernel/syscalls/fchroot/fchroot11.c +4 -0
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_USER_NS=y",
+		NULL,
+	}

Medium: Gate only the user-namespace subcase, not the entire test. Unprivileged failfs entry with no_new_privs works without CONFIG_USER_NS, but this descriptor skips its success and lookup checks as well. Keep those checks enabled and report TCONF only for the unavailable namespace subcase.

Valid

Quoted 5 lines

Verdict - Needs revision

Pre-existing issue: include/tst_fs.h documents tst_get_path() as returning an absolute path, but lib/get_path.c preserves relative PATH entries.

This is a documentation bug

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

PATCH v5 2/14 fchroot01: test fchroot() with a directory fd

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Verify that fchroot() with a directory fd moves the process root to the directory referenced by the fd.

---
 runtest/syscalls                              |  2 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/Makefile    |  7 ++++
 testcases/kernel/syscalls/fchroot/fchroot01.c | 56 +++++++++++++++++++++++++++
 4 files changed, 66 insertions(+)
runtest/syscalls +2 -0
index accdf2df9..558ad1732 100644
@@ -316,6 +316,8 @@ fchownat01 fchownat01
 fchownat02 fchownat02
 fchownat03 fchownat03
 
+fchroot01 fchroot01
+
 fcntl01 fcntl01
 fcntl01_64 fcntl01_64
 fcntl02 fcntl02
testcases/kernel/syscalls/fchroot/.gitignore new file +1 -0
new file mode 100644
index 000000000..03ebdbe7a
@@ -0,0 +1 @@
+fchroot01
testcases/kernel/syscalls/fchroot/Makefile new file +7 -0
new file mode 100644
index 000000000..137550149
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2026 SUSE LLC Andrea Cervesato <[email protected]>
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/fchroot/fchroot01.c new file +56 -0

56 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

PATCH v5 3/14 fchroot02: test fchroot() invalid arguments

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Verify the fchroot() error paths: a non-zero flags argument fails with EINVAL before anything else, an invalid fd fails with EBADF, including the FD_PIDFS_ROOT and FD_NSFS_ROOT sentinels, and a fd referring to a regular file fails with ENOTDIR. All these checks happen before the CAP_SYS_CHROOT check, so no privileges are needed.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot02.c | 75 +++++++++++++++++++++++++++
 3 files changed, 77 insertions(+)
runtest/syscalls +1 -0
index 558ad1732..c4070e970 100644
@@ -317,6 +317,7 @@ fchownat02 fchownat02
 fchownat03 fchownat03
 
 fchroot01 fchroot01
+fchroot02 fchroot02
 
 fcntl01 fcntl01
 fcntl01_64 fcntl01_64
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
index 03ebdbe7a..fb3287612 100644
@@ -1 +1,2 @@
 fchroot01
+fchroot02
testcases/kernel/syscalls/fchroot/fchroot02.c new file +75 -0

75 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

PATCH v5 4/14 fchroot03: test fchroot() permission checks

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Verify that with a regular directory fd the kernel first checks the execute permission on the directory and then CAP_SYS_CHROOT: an unprivileged process with an accessible directory fails with EPERM and a process without execute permission fails with EACCES.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot03.c | 70 +++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
runtest/syscalls +1 -0
index c4070e970..3b05e15eb 100644
@@ -318,6 +318,7 @@ fchownat03 fchownat03
 
 fchroot01 fchroot01
 fchroot02 fchroot02
+fchroot03 fchroot03
 
 fcntl01 fcntl01
 fcntl01_64 fcntl01_64
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
index fb3287612..235befd99 100644
@@ -1,2 +1,3 @@
 fchroot01
 fchroot02
+fchroot03
testcases/kernel/syscalls/fchroot/fchroot03.c new file +70 -0

70 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw

PATCH v5 5/14 fchroot04: test fchroot() into failfs as root

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Verify that entering failfs with the FD_FAILFS_ROOT sentinel succeeds with CAP_SYS_CHROOT and that every absolute path lookup then fails with EOPNOTSUPP, while the working directory is reported as unreachable by getcwd().

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot04.c | 67 +++++++++++++++++++++++++++
 3 files changed, 69 insertions(+)
runtest/syscalls +1 -0
index 3b05e15eb..a7483f97b 100644
@@ -319,6 +319,7 @@ fchownat03 fchownat03
 fchroot01 fchroot01
 fchroot02 fchroot02
 fchroot03 fchroot03
+fchroot04 fchroot04
 
 fcntl01 fcntl01
 fcntl01_64 fcntl01_64
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
index 235befd99..9270c1408 100644
@@ -1,3 +1,4 @@
 fchroot01
 fchroot02
 fchroot03
+fchroot04
testcases/kernel/syscalls/fchroot/fchroot04.c new file +67 -0

67 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw

PATCH v5 6/14 fchroot05: test failfs root can not be referenced

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Verify that once fchroot() moved the root into failfs, the root directory can not be opened anymore, not even with O_PATH, nor pinned by following the /proc/self/root magic link, although readlink() still names it as "failfs:/" since it does not follow the link.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot05.c | 73 +++++++++++++++++++++++++++
 3 files changed, 75 insertions(+)
runtest/syscalls +1 -0
index a7483f97b..a5ed6792e 100644
@@ -320,6 +320,7 @@ fchroot01 fchroot01
 fchroot02 fchroot02
 fchroot03 fchroot03
 fchroot04 fchroot04
+fchroot05 fchroot05
 
 fcntl01 fcntl01
 fcntl01_64 fcntl01_64
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
index 9270c1408..0697f10eb 100644
@@ -2,3 +2,4 @@ fchroot01
 fchroot02
 fchroot03
 fchroot04
+fchroot05
testcases/kernel/syscalls/fchroot/fchroot05.c new file +73 -0

73 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw

PATCH v5 7/14 fchroot06: test path walks under failfs root

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Verify that once the root is in failfs only lookups anchored at a file descriptor keep working: relative lookups from the working directory and from a pre-opened directory fd succeed, absolute symlinks fail with EOPNOTSUPP and ".." walks clamp at the top of the mount tree, landing on the real root.

---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |   1 +
 testcases/kernel/syscalls/fchroot/fchroot06.c | 124 ++++++++++++++++++++++++++
 3 files changed, 126 insertions(+)
runtest/syscalls +1 -0
index a5ed6792e..8b688cbe2 100644
@@ -321,6 +321,7 @@ fchroot02 fchroot02
 fchroot03 fchroot03
 fchroot04 fchroot04
 fchroot05 fchroot05
+fchroot06 fchroot06
 
 fcntl01 fcntl01
 fcntl01_64 fcntl01_64
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
index 0697f10eb..12151270a 100644
@@ -3,3 +3,4 @@ fchroot02
 fchroot03
 fchroot04
 fchroot05
+fchroot06
testcases/kernel/syscalls/fchroot/fchroot06.c new file +124 -0

124 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw

PATCH v5 8/14 fchroot07: test execve blocked by failfs root

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Verify that after fchroot() moved the root into failfs, loading a binary by absolute path fails with EOPNOTSUPP. The exec runs in a grandchild so a wrongly successful exec is still detected through the exit code.

---
 runtest/syscalls                                   |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore       |  2 +
 testcases/kernel/syscalls/fchroot/fchroot07.c      | 58 ++++++++++++++++++++++
 .../kernel/syscalls/fchroot/fchroot07_child.c      | 16 ++++++
 4 files changed, 77 insertions(+)
runtest/syscalls +1 -0
index 8b688cbe2..bc2dffdca 100644
@@ -322,6 +322,7 @@ fchroot03 fchroot03
 fchroot04 fchroot04
 fchroot05 fchroot05
 fchroot06 fchroot06
+fchroot07 fchroot07
 
 fcntl01 fcntl01
 fcntl01_64 fcntl01_64
testcases/kernel/syscalls/fchroot/.gitignore +2 -0
index 12151270a..bfa2a8ce1 100644
@@ -4,3 +4,5 @@ fchroot03
 fchroot04
 fchroot05
 fchroot06
+fchroot07
+fchroot07_child
testcases/kernel/syscalls/fchroot/fchroot07.c new file +58 -0

58 lines not on this page · raw message

testcases/kernel/syscalls/fchroot/fchroot07_child.c new file +16 -0
new file mode 100644
index 000000000..3d731781c
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 SUSE LLC Andrea Cervesato <[email protected]>
+ */
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+
+int main(void)
+{
+	tst_reinit();
+
+	tst_res(TFAIL, "child executed");
+
+	return 0;
+}
Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw

PATCH v5 9/14 fchroot08: test failfs root fork inheritance

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Verify that the root moved into failfs by fchroot() lives in the fs_struct which is duplicated on fork, so a child of a process with the failfs root also fails every absolute path lookup with EOPNOTSUPP.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot08.c | 52 +++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)
runtest/syscalls +1 -0
index bc2dffdca..24d9b1b4a 100644
@@ -323,6 +323,7 @@ fchroot04 fchroot04
 fchroot05 fchroot05
 fchroot06 fchroot06
 fchroot07 fchroot07
+fchroot08 fchroot08
 
 fcntl01 fcntl01
 fcntl01_64 fcntl01_64
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
index bfa2a8ce1..0a2510d8a 100644
@@ -6,3 +6,4 @@ fchroot05
 fchroot06
 fchroot07
 fchroot07_child
+fchroot08
testcases/kernel/syscalls/fchroot/fchroot08.c new file +52 -0

52 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#15 lore raw

PATCH v5 10/14 fchroot09: test setns escape from failfs root

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Verify that entering failfs with fchroot() is hard to undo: a process inside counts as chrooted, and one way out is a pre-opened mount namespace fd. setns() into it resets both the root and the working directory.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot09.c | 68 +++++++++++++++++++++++++++
 3 files changed, 70 insertions(+)
runtest/syscalls +1 -0
index 24d9b1b4a..b4723fee4 100644
@@ -324,6 +324,7 @@ fchroot05 fchroot05
 fchroot06 fchroot06
 fchroot07 fchroot07
 fchroot08 fchroot08
+fchroot09 fchroot09
 
 fcntl01 fcntl01
 fcntl01_64 fcntl01_64
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
index 0a2510d8a..b577da61f 100644
@@ -7,3 +7,4 @@ fchroot06
 fchroot07
 fchroot07_child
 fchroot08
+fchroot09
testcases/kernel/syscalls/fchroot/fchroot09.c new file +68 -0

68 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#17 lore raw

PATCH v5 11/14 fchroot10: test failfs entry without no_new_privs

In reply to Andrea Cervesato

From: Andrea Cervesato <[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.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot10.c | 52 +++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)
runtest/syscalls +1 -0
index b4723fee4..429e2740c 100644
@@ -325,6 +325,7 @@ fchroot06 fchroot06
 fchroot07 fchroot07
 fchroot08 fchroot08
 fchroot09 fchroot09
+fchroot10 fchroot10
 
 fcntl01 fcntl01
 fcntl01_64 fcntl01_64
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
index b577da61f..53a1fa1d0 100644
@@ -8,3 +8,4 @@ fchroot07
 fchroot07_child
 fchroot08
 fchroot09
+fchroot10
testcases/kernel/syscalls/fchroot/fchroot10.c new file +52 -0

52 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#18 lore raw

PATCH v5 12/14 fchroot11: test failfs entry with no_new_privs

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Verify that an unprivileged process may enter failfs when it committed to no_new_privs, since setuid binaries then pose no confused deputy risk anymore. The test also verifies that a process which entered failfs counts as chrooted: it can no longer create a user namespace with unshare() to regain CAP_SYS_CHROOT.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot11.c | 85 +++++++++++++++++++++++++++
 3 files changed, 87 insertions(+)
runtest/syscalls +1 -0
index 429e2740c..bd7b352fd 100644
@@ -326,6 +326,7 @@ fchroot07 fchroot07
 fchroot08 fchroot08
 fchroot09 fchroot09
 fchroot10 fchroot10
+fchroot11 fchroot11
 
 fcntl01 fcntl01
 fcntl01_64 fcntl01_64
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
index 53a1fa1d0..650ef2690 100644
@@ -9,3 +9,4 @@ fchroot07_child
 fchroot08
 fchroot09
 fchroot10
+fchroot11
testcases/kernel/syscalls/fchroot/fchroot11.c new file +85 -0

85 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v5 12/14
#19 lore raw

Re: [LTP] [PATCH v5 12/14] fchroot11: test failfs entry with no_new_privs

Hi!

Quoted 8 lines
testcases/kernel/syscalls/fchroot/fchroot11.c new file +8 -0
+static void run(void)
+{
+	int status;
+	pid_t pid;
+
+	if (SAFE_FORK())
+		return;
+

testcases/kernel/syscalls/fchroot/fchroot11.c line 52

Quoted 10 lines
testcases/kernel/syscalls/fchroot/fchroot11.c new file +10 -0
+	SAFE_SETRESUID(ltpuser->pw_uid, ltpuser->pw_uid,
+		ltpuser->pw_uid);
+
+	SAFE_PRCTL(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
+
+	pid = SAFE_FORK();
+	if (!pid) {
+		if (unshare(CLONE_NEWUSER) == -1)
+			exit(1);
+		return;

It would be a bit cleaner to do the unpriviledged user namespace support probe in setup. But that is minor.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#20 lore raw

PATCH v5 13/14 fchroot12: test failfs entry with shared fs_struct

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Verify that unprivileged fchroot() into failfs is refused with a shared fs_struct: a CLONE_FS sibling without no_new_privs could execute a setuid binary with the failfs root, so entry requires fs->users == 1, the same restriction setns() applies for the mount namespace. The sibling bumps fs->users to 2, making the syscall fail with EINVAL.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot12.c | 83 +++++++++++++++++++++++++++
 3 files changed, 85 insertions(+)
runtest/syscalls +1 -0
index bd7b352fd..bd3bbff4a 100644
@@ -327,6 +327,7 @@ fchroot08 fchroot08
 fchroot09 fchroot09
 fchroot10 fchroot10
 fchroot11 fchroot11
+fchroot12 fchroot12
 
 fcntl01 fcntl01
 fcntl01_64 fcntl01_64
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
index 650ef2690..e8a6730ee 100644
@@ -10,3 +10,4 @@ fchroot08
 fchroot09
 fchroot10
 fchroot11
+fchroot12
testcases/kernel/syscalls/fchroot/fchroot12.c new file +83 -0

83 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#21 lore raw

PATCH v5 14/14 fchroot13: test failfs entry when chrooted

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

Verify that unprivileged fchroot() into failfs is refused when the process is already chrooted: moving the root of a chrooted task into failfs would allow it to escape its chroot via openat(fd, "..") with a pre-opened directory fd, so the kernel refuses the syscall with EPERM.

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot13.c | 61 +++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)
runtest/syscalls +1 -0
index bd3bbff4a..2bdb4a9a2 100644
@@ -328,6 +328,7 @@ fchroot09 fchroot09
 fchroot10 fchroot10
 fchroot11 fchroot11
 fchroot12 fchroot12
+fchroot13 fchroot13
 
 fcntl01 fcntl01
 fcntl01_64 fcntl01_64
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
index e8a6730ee..3e77e3762 100644
@@ -11,3 +11,4 @@ fchroot09
 fchroot10
 fchroot11
 fchroot12
+fchroot13
testcases/kernel/syscalls/fchroot/fchroot13.c new file +61 -0

61 lines not on this page · raw message

Signature · 5 lines
2.51.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp