fchroot: add fchroot() testing suite
v4 cover fchroot: add fchroot() testing suite
fchroot() is a new syscall introduced in the Linux v7.3 development cycle 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 first updates the architecture syscall number tables and adds lapi fallback definitions for the new fd sentinels, then 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
fchroot() is not part of any released kernel yet, so the tests are added to runtest/staging and each patch carries the [STAGING] prefix as required by the LTP ground rules.
The testing suite creation has been assisted by GLM 5.3.
---
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 (16):
syscalls: add v7.3 syscall numbers
syscalls: update outdated syscall entries [STAGING] lapi: fallback fchroot() parameters [STAGING] fchroot01: test fchroot() with a directory fd [STAGING] fchroot02: test fchroot() invalid arguments [STAGING] fchroot03: test fchroot() permission checks [STAGING] fchroot04: test fchroot() into failfs as root [STAGING] fchroot05: test failfs root can not be referenced [STAGING] fchroot06: test path walks under failfs root [STAGING] fchroot07: test execve blocked by failfs root [STAGING] fchroot08: test failfs root fork inheritance [STAGING] fchroot09: test setns escape from failfs root [STAGING] fchroot10: test failfs entry without no_new_privs [STAGING] fchroot11: test failfs entry with no_new_privs [STAGING] fchroot12: test failfs entry with shared fs_struct [STAGING] fchroot13: test failfs entry when chrooted
include/lapi/fcntl.h | 13 +++ include/lapi/syscalls/arc.in | 3 + include/lapi/syscalls/arm.in | 4 +- include/lapi/syscalls/arm64.in | 3 + include/lapi/syscalls/i386.in | 4 +- include/lapi/syscalls/loongarch64.in | 3 + include/lapi/syscalls/mips64.in | 5 +- include/lapi/syscalls/mips64n32.in | 5 +- include/lapi/syscalls/mipso32.in | 5 +- include/lapi/syscalls/parisc.in | 4 +- include/lapi/syscalls/powerpc.in | 4 +- include/lapi/syscalls/powerpc64.in | 4 +- include/lapi/syscalls/s390.in | 5 +- include/lapi/syscalls/s390x.in | 5 +- include/lapi/syscalls/sh.in | 4 +- include/lapi/syscalls/sparc.in | 5 +- include/lapi/syscalls/sparc64.in | 5 +- include/lapi/syscalls/x86_64.in | 5 +- runtest/staging | 14 +++ testcases/kernel/syscalls/fchroot/.gitignore | 14 +++ testcases/kernel/syscalls/fchroot/Makefile | 7 ++ testcases/kernel/syscalls/fchroot/fchroot01.c | 58 ++++++++++ testcases/kernel/syscalls/fchroot/fchroot02.c | 75 ++++++++++++ testcases/kernel/syscalls/fchroot/fchroot03.c | 72 ++++++++++++ testcases/kernel/syscalls/fchroot/fchroot04.c | 69 +++++++++++ testcases/kernel/syscalls/fchroot/fchroot05.c | 75 ++++++++++++ testcases/kernel/syscalls/fchroot/fchroot06.c | 126 +++++++++++++++++++++ testcases/kernel/syscalls/fchroot/fchroot07.c | 59 ++++++++++ .../kernel/syscalls/fchroot/fchroot07_child.c | 16 +++ testcases/kernel/syscalls/fchroot/fchroot08.c | 69 +++++++++++ testcases/kernel/syscalls/fchroot/fchroot09.c | 86 ++++++++++++++ testcases/kernel/syscalls/fchroot/fchroot10.c | 54 +++++++++ testcases/kernel/syscalls/fchroot/fchroot11.c | 70 ++++++++++++ testcases/kernel/syscalls/fchroot/fchroot12.c | 85 ++++++++++++++ testcases/kernel/syscalls/fchroot/fchroot13.c | 63 +++++++++++ 35 files changed, 1079 insertions(+), 19 deletions(-)
---
base-commit: 3c0271a307bd765c2fd652c325762a90ddf5d46f
change-id: 20260819-fchroot-66115fd0d497
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 1/16 syscalls: add v7.3 syscall numbers
From: Andrea Cervesato <[email protected]>
Add listns (470), rseq_slice_yield (471) and fchroot (472), which are reserved for all architectures during the Linux v7.3 development cycle.
--- include/lapi/syscalls/arc.in | 3 +++ include/lapi/syscalls/arm.in | 3 +++ include/lapi/syscalls/arm64.in | 3 +++ include/lapi/syscalls/i386.in | 3 +++ include/lapi/syscalls/loongarch64.in | 3 +++ include/lapi/syscalls/mips64.in | 3 +++ include/lapi/syscalls/mips64n32.in | 3 +++ include/lapi/syscalls/mipso32.in | 3 +++ include/lapi/syscalls/parisc.in | 3 +++ include/lapi/syscalls/powerpc.in | 3 +++ include/lapi/syscalls/powerpc64.in | 3 +++ include/lapi/syscalls/s390.in | 3 +++ include/lapi/syscalls/s390x.in | 3 +++ include/lapi/syscalls/sh.in | 3 +++ include/lapi/syscalls/sparc.in | 3 +++ include/lapi/syscalls/sparc64.in | 3 +++ include/lapi/syscalls/x86_64.in | 3 +++ 17 files changed, 51 insertions(+)
include/lapi/syscalls/arc.in +3 -0
@@ -347,3 +347,6 @@ removexattrat 466 open_tree_attr 467 file_getattr 468 file_setattr 469 +listns 470 +rseq_slice_yield 471 +fchroot 472
include/lapi/syscalls/arm.in +3 -0
@@ -420,3 +420,6 @@ removexattrat 466 open_tree_attr 467 file_getattr 468 file_setattr 469 +listns 470 +rseq_slice_yield 471 +fchroot 472
include/lapi/syscalls/arm64.in +3 -0
@@ -323,3 +323,6 @@ removexattrat 466 open_tree_attr 467 file_getattr 468 file_setattr 469 +listns 470 +rseq_slice_yield 471 +fchroot 472
include/lapi/syscalls/i386.in +3 -0
@@ -454,3 +454,6 @@ removexattrat 466 open_tree_attr 467 file_getattr 468 file_setattr 469 +listns 470 +rseq_slice_yield 471 +fchroot 472
include/lapi/syscalls/loongarch64.in +3 -0
@@ -320,3 +320,6 @@ removexattrat 466 open_tree_attr 467 file_getattr 468 file_setattr 469 +listns 470 +rseq_slice_yield 471 +fchroot 472
include/lapi/syscalls/mips64.in +3 -0
@@ -369,3 +369,6 @@ removexattrat 5466 open_tree_attr 5467 file_getattr 5468 file_setattr 5469 +listns 5470 +rseq_slice_yield 5471 +fchroot 5472
include/lapi/syscalls/mips64n32.in +3 -0
@@ -393,3 +393,6 @@ removexattrat 6466 open_tree_attr 6467 file_getattr 6468 file_setattr 6469 +listns 6470 +rseq_slice_yield 6471 +fchroot 6472
include/lapi/syscalls/mipso32.in +3 -0
@@ -433,3 +433,6 @@ removexattrat 4466 open_tree_attr 4467 file_getattr 4468 file_setattr 4469 +listns 4470 +rseq_slice_yield 4471 +fchroot 4472
include/lapi/syscalls/parisc.in +3 -0
@@ -402,3 +402,6 @@ removexattrat 466 open_tree_attr 467 file_getattr 468 file_setattr 469 +listns 470 +rseq_slice_yield 471 +fchroot 472
include/lapi/syscalls/powerpc.in +3 -0
@@ -444,3 +444,6 @@ removexattrat 466 open_tree_attr 467 file_getattr 468 file_setattr 469 +listns 470 +rseq_slice_yield 471 +fchroot 472
include/lapi/syscalls/powerpc64.in +3 -0
@@ -416,3 +416,6 @@ removexattrat 466 open_tree_attr 467 file_getattr 468 file_setattr 469 +listns 470 +rseq_slice_yield 471 +fchroot 472
include/lapi/syscalls/s390.in +3 -0
@@ -437,3 +437,6 @@ removexattrat 466 open_tree_attr 467 file_getattr 468 file_setattr 469 +listns 470 +rseq_slice_yield 471 +fchroot 472
include/lapi/syscalls/s390x.in +3 -0
@@ -385,3 +385,6 @@ removexattrat 466 open_tree_attr 467 file_getattr 468 file_setattr 469 +listns 470 +rseq_slice_yield 471 +fchroot 472
include/lapi/syscalls/sh.in +3 -0
@@ -431,3 +431,6 @@ removexattrat 466 open_tree_attr 467 file_getattr 468 file_setattr 469 +listns 470 +rseq_slice_yield 471 +fchroot 472
include/lapi/syscalls/sparc.in +3 -0
@@ -435,3 +435,6 @@ removexattrat 466 open_tree_attr 467 file_getattr 468 file_setattr 469 +listns 470 +rseq_slice_yield 471 +fchroot 472
include/lapi/syscalls/sparc64.in +3 -0
@@ -398,3 +398,6 @@ removexattrat 466 open_tree_attr 467 file_getattr 468 file_setattr 469 +listns 470 +rseq_slice_yield 471 +fchroot 472
include/lapi/syscalls/x86_64.in +3 -0
@@ -380,3 +380,6 @@ removexattrat 466 open_tree_attr 467 file_getattr 468 file_setattr 469 +listns 470 +rseq_slice_yield 471 +fchroot 472
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 2/16 syscalls: update outdated syscall entries
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Add uprobe (336) on x86_64 and clone3 (435) on sparc, which were missing from the architecture syscall tables.
Drop the _sysctl and timerfd entries because both are wired to sys_ni_syscall in the kernel syscall tables and cannot be called.
--- include/lapi/syscalls/arm.in | 1 - include/lapi/syscalls/i386.in | 1 - include/lapi/syscalls/mips64.in | 2 -- include/lapi/syscalls/mips64n32.in | 2 -- include/lapi/syscalls/mipso32.in | 2 -- include/lapi/syscalls/parisc.in | 1 - include/lapi/syscalls/powerpc.in | 1 - include/lapi/syscalls/powerpc64.in | 1 - include/lapi/syscalls/s390.in | 2 -- include/lapi/syscalls/s390x.in | 2 -- include/lapi/syscalls/sh.in | 1 - include/lapi/syscalls/sparc.in | 2 +- include/lapi/syscalls/sparc64.in | 2 +- include/lapi/syscalls/x86_64.in | 2 +- 14 files changed, 3 insertions(+), 19 deletions(-)
include/lapi/syscalls/arm.in +0 -1
@@ -109,7 +109,6 @@ readv 145 writev 146 getsid 147 fdatasync 148 -_sysctl 149 mlock 150 munlock 151 mlockall 152
include/lapi/syscalls/i386.in +0 -1
@@ -145,7 +145,6 @@ readv 145 writev 146 getsid 147 fdatasync 148 -_sysctl 149 mlock 150 munlock 151 mlockall 152
include/lapi/syscalls/mips64.in +0 -2
@@ -150,7 +150,6 @@ mlockall 5148 munlockall 5149 vhangup 5150 pivot_root 5151 -_sysctl 5152 prctl 5153 adjtimex 5154 setrlimit 5155
@@ -272,7 +271,6 @@ ioprio_set 5273 ioprio_get 5274 utimensat 5275 signalfd 5276 -timerfd 5277 eventfd 5278 fallocate 5279 timerfd_create 5280
include/lapi/syscalls/mips64n32.in +0 -2
@@ -150,7 +150,6 @@ mlockall 6148 munlockall 6149 vhangup 6150 pivot_root 6151 -_sysctl 6152 prctl 6153 adjtimex 6154 setrlimit 6155
@@ -276,7 +275,6 @@ ioprio_set 6277 ioprio_get 6278 utimensat 6279 signalfd 6280 -timerfd 6281 eventfd 6282 fallocate 6283 timerfd_create 6284
include/lapi/syscalls/mipso32.in +0 -2
@@ -144,7 +144,6 @@ cachectl 4148 sysmips 4149 getsid 4151 fdatasync 4152 -_sysctl 4153 mlock 4154 munlock 4155 mlockall 4156
@@ -307,7 +306,6 @@ ioprio_set 4314 ioprio_get 4315 utimensat 4316 signalfd 4317 -timerfd 4318 eventfd 4319 fallocate 4320 timerfd_create 4321
include/lapi/syscalls/parisc.in +0 -1
@@ -142,7 +142,6 @@ readv 145 writev 146 getsid 147 fdatasync 148 -_sysctl 149 mlock 150 munlock 151 mlockall 152
include/lapi/syscalls/powerpc.in +0 -1
@@ -145,7 +145,6 @@ readv 145 writev 146 getsid 147 fdatasync 148 -_sysctl 149 mlock 150 munlock 151 mlockall 152
include/lapi/syscalls/powerpc64.in +0 -1
@@ -145,7 +145,6 @@ readv 145 writev 146 getsid 147 fdatasync 148 -_sysctl 149 mlock 150 munlock 151 mlockall 152
include/lapi/syscalls/s390.in +0 -2
@@ -126,7 +126,6 @@ readv 145 writev 146 getsid 147 fdatasync 148 -_sysctl 149 mlock 150 munlock 151 mlockall 152
@@ -291,7 +290,6 @@ utimes 313 fallocate 314 utimensat 315 signalfd 316 -timerfd 317 eventfd 318 timerfd_create 319 timerfd_settime 320
include/lapi/syscalls/s390x.in +0 -2
@@ -107,7 +107,6 @@ readv 145 writev 146 getsid 147 fdatasync 148 -_sysctl 149 mlock 150 munlock 151 mlockall 152
@@ -258,7 +257,6 @@ utimes 313 fallocate 314 utimensat 315 signalfd 316 -timerfd 317 eventfd 318 timerfd_create 319 timerfd_settime 320
include/lapi/syscalls/sh.in +0 -1
@@ -128,7 +128,6 @@ readv 145 writev 146 getsid 147 fdatasync 148 -_sysctl 149 mlock 150 munlock 151 mlockall 152
include/lapi/syscalls/sparc.in +1 -1
@@ -246,7 +246,6 @@ sched_get_priority_min 247 sched_rr_get_interval 248 nanosleep 249 mremap 250 -_sysctl 251 getsid 252 fdatasync 253 nfsservctl 254
@@ -402,6 +401,7 @@ fsconfig 431 fsmount 432 fspick 433 pidfd_open 434 +clone3 435 close_range 436 openat2 437 pidfd_getfd 438
include/lapi/syscalls/sparc64.in +1 -1
@@ -228,7 +228,6 @@ sched_get_priority_min 247 sched_rr_get_interval 248 nanosleep 249 mremap 250 -_sysctl 251 getsid 252 fdatasync 253 nfsservctl 254
@@ -365,6 +364,7 @@ fsconfig 431 fsmount 432 fspick 433 pidfd_open 434 +clone3 435 close_range 436 openat2 437 pidfd_getfd 438
include/lapi/syscalls/x86_64.in +1 -1
@@ -154,7 +154,6 @@ munlockall 152 vhangup 153 modify_ldt 154 pivot_root 155 -_sysctl 156 prctl 157 arch_prctl 158 adjtimex 159
@@ -334,6 +333,7 @@ statx 332 io_pgetevents 333 rseq 334 uretprobe 335 +uprobe 336 pidfd_send_signal 424 io_uring_setup 425 io_uring_enter 426
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 3/16 lapi: fallback fchroot() parameters
In reply to Andrea CervesatoFrom: 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
@@ -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
PATCH v4 4/16 fchroot01: test fchroot() with a directory fd
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Verify that fchroot() with a directory fd moves the process root to the directory referenced by the fd.
fchroot() was introduced in Linux v7.3, so the test is added to the staging runtest file.
--- runtest/staging | 2 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/Makefile | 7 ++++ testcases/kernel/syscalls/fchroot/fchroot01.c | 58 +++++++++++++++++++++++++++ 4 files changed, 68 insertions(+)
runtest/staging +2 -0
@@ -1 +1,3 @@ # Tests for features that are not yet in the stable kernel ABI + +fchroot01 fchroot01
testcases/kernel/syscalls/fchroot/.gitignore new file +1 -0
@@ -0,0 +1 @@ +fchroot01
testcases/kernel/syscalls/fchroot/Makefile new file +7 -0
@@ -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 +58 -0
58 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] syscalls: add v7.3 syscall numbers
Hi Andrea,
Quoted 1 line · Andrea Cervesato
syscalls: add v7.3 syscall numbers
--- [PATCH 4/16] ---
Quoted 1 line
+fchroot01 fchroot01
Medium: Linux 7.3 is stable, so this released syscall test belongs in the regular syscall runtest file rather than the staging-only suite.
testcases/kernel/syscalls/fchroot/fchroot01.c line 58
Quoted 7 lines
testcases/kernel/syscalls/fchroot/fchroot01.c new file +7
-0+static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root =1 , + .needs_tmpdir =1 , + .forks_child =1 , +};
Medium: Add .min_kver = "7.3". On older kernels the direct syscall returns ENOSYS and the test reports TFAIL instead of TCONF.
--- [PATCH 5/16] ---
Quoted 1 line
+fchroot02 fchroot02
Medium: Linux 7.3 is stable, so this entry belongs in the regular syscall runtest file rather than the staging-only suite.
testcases/kernel/syscalls/fchroot/fchroot01.c line 58
Quoted 7 lines
testcases/kernel/syscalls/fchroot/fchroot01.c new file +7
-0+static struct tst_test test = { + .test = run, + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir =1 , +};
Medium: Add .min_kver = "7.3" so older kernels skip instead of reporting TFAIL when the syscall returns ENOSYS.
--- [PATCH 6/16] ---
Quoted 1 line
+fchroot03 fchroot03
Medium: Linux 7.3 is stable, so this entry belongs in the regular syscall runtest file rather than the staging-only suite.
testcases/kernel/syscalls/fchroot/fchroot01.c line 58
Quoted 8 lines
testcases/kernel/syscalls/fchroot/fchroot01.c new file +8
-0+static struct tst_test test = { + .test = run, + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .needs_root =1 , + .needs_tmpdir =1 , + .forks_child =1 , +};
Medium: Add .min_kver = "7.3" so older kernels skip instead of reporting TFAIL when the syscall returns ENOSYS.
--- [PATCH 7/16] ---
Quoted 1 line
+fchroot04 fchroot04
Medium: Linux 7.3 is stable, so this entry belongs in the regular syscall runtest file rather than the staging-only suite.
testcases/kernel/syscalls/fchroot/fchroot01.c line 58
Quoted 6 lines
testcases/kernel/syscalls/fchroot/fchroot01.c new file +6
-0+static struct tst_test test = { + .test_all = run, + .needs_root =1 , + .needs_tmpdir =1 , + .forks_child =1 , +};
Medium: Add .min_kver = "7.3" so older kernels skip instead of reporting TFAIL when the syscall returns ENOSYS.
--- [PATCH 8/16] ---
Quoted 1 line
+fchroot05 fchroot05
Medium: Linux 7.3 is stable, so this entry belongs in the regular syscall runtest file rather than the staging-only suite.
testcases/kernel/syscalls/fchroot/fchroot01.c line 58
Quoted 5 lines
testcases/kernel/syscalls/fchroot/fchroot01.c new file +5
-0+static struct tst_test test = { + .test_all = run, + .needs_root =1 , + .forks_child =1 , +};
Medium: Add .min_kver = "7.3" so older kernels skip instead of reporting TFAIL when the syscall returns ENOSYS.
--- [PATCH 9/16] ---
Quoted 1 line
+fchroot06 fchroot06
Medium: Linux 7.3 is stable, so this entry belongs in the regular syscall runtest file rather than the staging-only suite.
testcases/kernel/syscalls/fchroot/fchroot01.c line 58
Quoted 7 lines
testcases/kernel/syscalls/fchroot/fchroot01.c new file +7
-0+static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root =1 , + .needs_tmpdir =1 , + .forks_child =1 , +};
Medium: Add .min_kver = "7.3" so older kernels skip instead of reporting TFAIL when the syscall returns ENOSYS.
--- [PATCH 10/16] ---
Quoted 1 line
+fchroot07 fchroot07
Medium: Linux 7.3 is stable, so this entry belongs in the regular syscall runtest file rather than the staging-only suite.
testcases/kernel/syscalls/fchroot/fchroot01.c line 58
Quoted 7 lines
testcases/kernel/syscalls/fchroot/fchroot01.c new file +7
-0+static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root =1 , + .forks_child =1 , + .child_needs_reinit =1 , +};
Medium: Add .min_kver = "7.3" so older kernels skip instead of reporting TFAIL when the syscall returns ENOSYS.
--- [PATCH 11/16] ---
Quoted 1 line
+fchroot08 fchroot08
Medium: Linux 7.3 is stable, so this entry belongs in the regular syscall runtest file rather than the staging-only suite.
testcases/kernel/syscalls/fchroot/fchroot01.c line 58
Quoted 7 lines
testcases/kernel/syscalls/fchroot/fchroot01.c new file +7
-0+static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_root =1 , + .forks_child =1 , + .needs_tmpdir =1 , +};
Medium: Add .min_kver = "7.3" so older kernels skip instead of reporting TFAIL when the syscall returns ENOSYS.
--- [PATCH 12/16] ---
Quoted 1 line
+fchroot09 fchroot09
Medium: Linux 7.3 is stable, so this entry belongs in the regular syscall runtest file rather than the staging-only suite.
Quoted 2 lines
+ * back out require ``CAP_SYS_CHROOT``. The remaining way out is a pre-opened
+ * mount namespace file descriptor: :manpage:setns(2)into it resets both the
Low: A pre-opened directory fd also permits a privileged process to escape with fchroot(), or with fchdir() followed by chroot("."). Describe setns() as one escape mechanism rather than the remaining one.
testcases/kernel/syscalls/fchroot/fchroot01.c line 58
Quoted 7 lines
testcases/kernel/syscalls/fchroot/fchroot01.c new file +7
-0+static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_root =1 , + .forks_child =1 , + .needs_tmpdir =1 , +};
Medium: Add .min_kver = "7.3" so older kernels skip instead of reporting TFAIL when the syscall returns ENOSYS.
--- [PATCH 13/16] ---
Quoted 1 line
+fchroot10 fchroot10
Medium: Linux 7.3 is stable, so this entry belongs in the regular syscall runtest file rather than the staging-only suite.
testcases/kernel/syscalls/fchroot/fchroot01.c line 58
Quoted 6 lines
testcases/kernel/syscalls/fchroot/fchroot01.c new file +6
-0+static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root =1 , + .forks_child =1 , +};
Medium: Add .min_kver = "7.3" so older kernels skip instead of reporting TFAIL when the syscall returns ENOSYS.
--- [PATCH 14/16] ---
Quoted 1 line
+fchroot11 fchroot11
Medium: Linux 7.3 is stable, so this entry belongs in the regular syscall runtest file rather than the staging-only suite.
Review
Quoted 2 lines
(quoted diff) +2
-0+ TST_EXP_FAIL(unshare(CLONE_NEWUSER), EPERM, + "user namespace creation blocked by the failfs root");
Medium: EPERM can also come from security_create_user_ns() or a policy that disables unprivileged user namespaces, producing a false pass. First verify in a separate child, before entering failfs, that this user can create a user namespace; skip if it cannot.
testcases/kernel/syscalls/fchroot/fchroot01.c line 58
Quoted 10 lines
testcases/kernel/syscalls/fchroot/fchroot01.c new file +10
-0+static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root =1 , + .forks_child =1 , + .needs_kconfigs = (const char *[]) { +"CONFIG_USER_NS=y" , +NULL , + } +};
Medium: Add .min_kver = "7.3" so older kernels skip instead of reporting TFAIL when the syscall returns ENOSYS.
--- [PATCH 15/16] ---
Quoted 1 line
+fchroot12 fchroot12
Medium: Linux 7.3 is stable, so this entry belongs in the regular syscall runtest file rather than the staging-only suite.
testcases/kernel/syscalls/fchroot/fchroot01.c line 58
Quoted 6 lines
testcases/kernel/syscalls/fchroot/fchroot01.c new file +6
-0+static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root =1 , + .forks_child =1 , +};
Medium: Add .min_kver = "7.3" so older kernels skip instead of reporting TFAIL when the syscall returns ENOSYS.
--- [PATCH 16/16] ---
Quoted 1 line
+fchroot13 fchroot13
Medium: Linux 7.3 is stable, so this entry belongs in the regular syscall runtest file rather than the staging-only suite.
testcases/kernel/syscalls/fchroot/fchroot01.c line 58
Quoted 7 lines
testcases/kernel/syscalls/fchroot/fchroot01.c new file +7
-0+static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root =1 , + .needs_tmpdir =1 , + .forks_child =1 , +};
Medium: Add .min_kver = "7.3" so older kernels skip instead of reporting TFAIL when the syscall returns ENOSYS.
Verdict - Needs revision
---
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
Re: [LTP] [PATCH STAGING v4 04/16] fchroot01: test fchroot() with a directory fd
In reply to Andrea CervesatoHi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 5/16 fchroot02: test fchroot() invalid arguments
In reply to Andrea CervesatoFrom: 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/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot02.c | 75 +++++++++++++++++++++++++++ 3 files changed, 77 insertions(+)
runtest/staging +1 -0
@@ -1,3 +1,4 @@ # Tests for features that are not yet in the stable kernel ABI fchroot01 fchroot01 +fchroot02 fchroot02
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
@@ -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
Re: [LTP] [PATCH STAGING v4 05/16] fchroot02: test fchroot() invalid arguments
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 6/16 fchroot03: test fchroot() permission checks
In reply to Andrea CervesatoFrom: 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/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot03.c | 72 +++++++++++++++++++++++++++ 3 files changed, 74 insertions(+)
runtest/staging +1 -0
@@ -2,3 +2,4 @@ fchroot01 fchroot01 fchroot02 fchroot02 +fchroot03 fchroot03
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
@@ -1,2 +1,3 @@ fchroot01 fchroot02 +fchroot03
testcases/kernel/syscalls/fchroot/fchroot03.c new file +72 -0
72 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH STAGING v4 06/16] fchroot03: test fchroot() permission checks
Hi!
Quoted 6 lines
testcases/kernel/syscalls/fchroot/fchroot03.c new file +6
-0+static void run (unsigned int i) +{ +struct tcase *tc = &tcases[i]; + +if (SAFE_FORK ()) +return ;
testcases/kernel/syscalls/fchroot/fchroot03.c line 50
Quoted 10 lines
testcases/kernel/syscalls/fchroot/fchroot03.c new file +10
-0+ +int dfd =SAFE_OPEN (tc->dir,O_PATH |O_DIRECTORY ); + +SAFE_SETRESUID (ltpuser->pw_uid, ltpuser->pw_uid, + ltpuser->pw_uid); + +TST_EXP_FAIL (tst_syscall (__NR_fchroot, dfd,0 ), + tc->exp_errno,"fchroot() with %s" , tc->desc); + +exit (0 );
The test library does exit(0); for any process that has been forked from the main test process. There is no need for the exit(0) here.
Otherwise:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 7/16 fchroot04: test fchroot() into failfs as root
In reply to Andrea CervesatoFrom: 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/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot04.c | 69 +++++++++++++++++++++++++++ 3 files changed, 71 insertions(+)
runtest/staging +1 -0
@@ -3,3 +3,4 @@ fchroot01 fchroot01 fchroot02 fchroot02 fchroot03 fchroot03 +fchroot04 fchroot04
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
@@ -1,3 +1,4 @@ fchroot01 fchroot02 fchroot03 +fchroot04
testcases/kernel/syscalls/fchroot/fchroot04.c new file +69 -0
69 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH STAGING v4 07/16] fchroot04: test fchroot() into failfs as root
Hi!
Quoted 17 lines
testcases/kernel/syscalls/fchroot/fchroot04.c new file +17
-0+static void run (void ) +{ +if (SAFE_FORK ()) +return ; + +char buf[PATH_MAX ]; + +TST_EXP_PASS (tst_syscall (__NR_fchroot,FD_FAILFS_ROOT ,0 ), +"fchroot() with the FD_FAILFS_ROOT sentinel" ); + +TST_EXP_FAIL2 (open ("/etc/passwd" ,O_RDONLY ),EOPNOTSUPP , +"absolute file open" ); + +TST_EXP_FAIL (mkdir ("/foo" ,0700 ),EOPNOTSUPP , +"absolute directory creation" ); + +/*
testcases/kernel/syscalls/fchroot/fchroot04.c line 61
Quoted 10 lines
testcases/kernel/syscalls/fchroot/fchroot04.c new file +10
-0+* The libc getcwd() wrapper rejects the "(unreachable)" +* prefix produced by the kernel, so call the raw syscall. +*/ +TEST (tst_syscall (__NR_getcwd, buf,sizeof (buf))); +if (TST_RET >0 ) +TST_EXP_EQ_STRN (buf,UNR_TAG ,sizeof (UNR_TAG ) -1 ); +else +tst_res (TFAIL |TTERRNO ,"getcwd() failed" ); + +exit (0 );
Here as well, no need to add the exit(0)
Otherwise:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 8/16 fchroot05: test failfs root can not be referenced
In reply to Andrea CervesatoFrom: 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/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot05.c | 75 +++++++++++++++++++++++++++ 3 files changed, 77 insertions(+)
runtest/staging +1 -0
@@ -4,3 +4,4 @@ fchroot01 fchroot01 fchroot02 fchroot02 fchroot03 fchroot03 fchroot04 fchroot04 +fchroot05 fchroot05
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
@@ -2,3 +2,4 @@ fchroot01 fchroot02 fchroot03 fchroot04 +fchroot05
testcases/kernel/syscalls/fchroot/fchroot05.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
Re: [LTP] [PATCH STAGING v4 08/16] fchroot05: test failfs root can not be referenced
Hi!
testcases/kernel/syscalls/fchroot/fchroot05.c line 68
Quoted 9 lines
testcases/kernel/syscalls/fchroot/fchroot05.c new file +9
-0+ len =readlinkat (procfd,"self/root" , buf,sizeof (buf) -1 ); +if (len <0 ) { +tst_res (TFAIL |TTERRNO ,"readlinkat() of /proc/self/root" ); + }else { + buf[len] ='\0' ; +TST_EXP_EQ_STR (buf,"failfs:/" ); + } + +exit (0 );
Here as well.
Otherwise:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 9/16 fchroot06: test path walks under failfs root
In reply to Andrea CervesatoFrom: 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/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot06.c | 126 ++++++++++++++++++++++++++ 3 files changed, 128 insertions(+)
runtest/staging +1 -0
@@ -5,3 +5,4 @@ fchroot02 fchroot02 fchroot03 fchroot03 fchroot04 fchroot04 fchroot05 fchroot05 +fchroot06 fchroot06
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
@@ -3,3 +3,4 @@ fchroot02 fchroot03 fchroot04 fchroot05 +fchroot06
testcases/kernel/syscalls/fchroot/fchroot06.c new file +126 -0
126 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH STAGING v4 09/16] fchroot06: test path walks under failfs root
Hi!
Quoted 112 lines
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.
Signed-off-by Andrea Cervesato <[email protected]>--- runtest/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot06.c | 126 ++++++++++++++++++++++++++ 3 files changed, 128 insertions(+)runtest/staging +1
-0@@ -5,3 +5,4 @@ fchroot02 fchroot02 fchroot03 fchroot03 fchroot04 fchroot04 fchroot05 fchroot05 +fchroot06 fchroot06testcases/kernel/syscalls/fchroot/.gitignore +1
-0@@ -3,3 +3,4 @@ fchroot02 fchroot03 fchroot04 fchroot05 +fchroot06testcases/kernel/syscalls/fchroot/fchroot06.c new file +75
-0@@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2026 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* Test path walks under the failfs root. +* +* Once :manpage:`fchroot(2)` moved the process root into failfs, only +* lookups anchored at a file descriptor keep working: +* +* - lookups relative to the working directory, which stays in the real +* filesystem, keep working +* - lookups anchored at a pre-opened directory fd keep working, including +* resolution of relative symlinks +* - absolute symlinks restart the walk at the failfs root and fail with +* ``EOPNOTSUPP`` +* - ".." walks clamp at the top of the mount tree, not at the failfs +* root, so walking up from the working directory lands on the real +* root +* +* Root is required because entering failfs with the ``FD_FAILFS_ROOT`` +* sentinel requires ``CAP_SYS_CHROOT``. +* +* The test runs in a forked child so the root of the parent process is +* left untouched. +*/ + +#define _GNU_SOURCE +#include <fcntl.h> +#include <sys/stat.h> +#include "tst_test.h" +#include "lapi/fcntl.h" +#include "lapi/syscalls.h" +#include "tst_safe_file_at.h" + +#define RELDIR "rel" +#define ABSDIR "abs" + +static char upwards[PATH_MAX ]; + +static void run (void ) +{ +if (SAFE_FORK ()) +return ; + +struct stat realroot, st; +int dfd, fd; + +SAFE_STAT ("/" , &realroot); + dfd =SAFE_OPEN ("." ,O_RDONLY |O_DIRECTORY ); + +TST_EXP_PASS (tst_syscall (__NR_fchroot,FD_FAILFS_ROOT ,0 ), +"fchroot() with the FD_FAILFS_ROOT sentinel" ); + + fd =TST_EXP_FD (openat (AT_FDCWD ,"." ,O_RDONLY |O_DIRECTORY )); +if (fd !=-1 ) +SAFE_CLOSE (fd); + + fd =TST_EXP_FD (openat (dfd,"canary" ,O_WRONLY |O_CREAT ,0600 )); +if (fd !=-1 ) { +SAFE_WRITE (SAFE_WRITE_ALL , fd,"x" ,1 ); +SAFE_CLOSE (fd); + } + + fd =TST_EXP_FD (openat (dfd,RELDIR ,O_RDONLY )); +if (fd !=-1 ) +SAFE_CLOSE (fd); + +TST_EXP_FAIL2 (openat (dfd,ABSDIR ,O_RDONLY ),EOPNOTSUPP , +"resolution of an absolute symlink" ); + + fd =TST_EXP_FD (openat (AT_FDCWD , upwards,O_PATH )); +if (fd !=-1 ) { +SAFE_FSTAT (fd, &st);
testcases/kernel/syscalls/fchroot/fchroot06.c line 85
Quoted 10 lines
testcases/kernel/syscalls/fchroot/fchroot06.c new file +10
-0+SAFE_CLOSE (fd); + +TST_EXP_EXPR (st.st_dev == realroot.st_dev && + st.st_ino == realroot.st_ino, +"'..' walk clamps at the top of the mount tree" ); + } + +SAFE_CLOSE (dfd); + +exit (0 );
Here as well, no need for the exit(0);
Quoted 13 lines
testcases/kernel/syscalls/fchroot/fchroot06.c new file +13
-0+} + +static void setup (void ) +{ +char *tmpdir; +char abs_path[PATH_MAX ]; +struct stat root_st, st; +int fd, off; + + tmpdir =tst_tmpdir_path (); +snprintf (abs_path,sizeof (abs_path),"%s/%s" , tmpdir,"target" ); + +SAFE_TOUCH ("target" ,0644 ,NULL );
testcases/kernel/syscalls/fchroot/fchroot06.c line 108
Quoted 10 lines
testcases/kernel/syscalls/fchroot/fchroot06.c new file +10
-0+SAFE_SYMLINK ("target" ,RELDIR ); +SAFE_SYMLINK (abs_path,ABSDIR ); + +SAFE_STAT ("/" , &root_st); + + off =snprintf (upwards,sizeof (upwards),".." ); +while (1 ) { + fd =SAFE_OPENAT (AT_FDCWD , upwards,O_PATH ); +SAFE_FSTAT (fd, &st); +SAFE_CLOSE (fd);
Why not just SAFE_FSTAT(upwards, &st) ?
testcases/kernel/syscalls/fchroot/fchroot06.c line 116
Quoted 7 lines
testcases/kernel/syscalls/fchroot/fchroot06.c new file +7
-0+if (st.st_dev == root_st.st_dev && st.st_ino == root_st.st_ino) +break ; + +if ((size_t )off +sizeof ("/.." ) >sizeof (upwards)) +tst_brk (TBROK ,"Path to root too long" ); + + off +=snprintf (upwards + off,sizeof (upwards) - off,"/.." );
This can probably be simplified to:
strcpy(upwards + off, "../"); off += 3;
The string is constant and we already checked that it fits, there is no need to use the big hammer (snprintf).
And the same for the initial snprintf(), just strcpy(upwards, ".."); off = 2;
Quoted 17 lines
testcases/kernel/syscalls/fchroot/fchroot06.c new file +10
-0+ } +} + +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root =1 , + .needs_tmpdir =1 , + .forks_child =1 , +};Signature · 6 lines
-- 2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 10/16 fchroot07: test execve blocked by failfs root
In reply to Andrea CervesatoFrom: 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/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 2 + testcases/kernel/syscalls/fchroot/fchroot07.c | 59 ++++++++++++++++++++++ .../kernel/syscalls/fchroot/fchroot07_child.c | 16 ++++++ 4 files changed, 78 insertions(+)
runtest/staging +1 -0
@@ -6,3 +6,4 @@ fchroot03 fchroot03 fchroot04 fchroot04 fchroot05 fchroot05 fchroot06 fchroot06 +fchroot07 fchroot07
testcases/kernel/syscalls/fchroot/.gitignore +2 -0
@@ -4,3 +4,5 @@ fchroot03 fchroot04 fchroot05 fchroot06 +fchroot07 +fchroot07_child
testcases/kernel/syscalls/fchroot/fchroot07.c new file +59 -0
59 lines not on this page · raw message
testcases/kernel/syscalls/fchroot/fchroot07_child.c new file +16 -0
@@ -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
Re: [LTP] [PATCH STAGING v4 10/16] fchroot07: test execve blocked by failfs root
Hi!
Quoted 6 lines
testcases/kernel/syscalls/fchroot/fchroot07.c new file +6
-0+static void run (void ) +{ +if (SAFE_FORK ()) +return ; + + TST_EXP_PASS(tst_syscall(__NR_fchroot, FD_FAILFS_ROOT, 0),
testcases/kernel/syscalls/fchroot/fchroot07.c line 44
Quoted 10 lines
testcases/kernel/syscalls/fchroot/fchroot07.c new file +10
-0+ "fchroot() with the FD_FAILFS_ROOT sentinel"); + +if (!SAFE_FORK ()) { +TST_EXP_FAIL (execl (child_path,CHILD_EXEC ,NULL ),EOPNOTSUPP , +"absolute exec blocked by the failfs root" ); +exit (0 ); + } + +SAFE_WAIT (NULL ); +exit (0 );
Again, no need to exit(0) here.
Otherwise:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 11/16 fchroot08: test failfs root fork inheritance
In reply to Andrea CervesatoFrom: 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/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot08.c | 69 +++++++++++++++++++++++++++ 3 files changed, 71 insertions(+)
runtest/staging +1 -0
@@ -7,3 +7,4 @@ fchroot04 fchroot04 fchroot05 fchroot05 fchroot06 fchroot06 fchroot07 fchroot07 +fchroot08 fchroot08
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
@@ -6,3 +6,4 @@ fchroot05 fchroot06 fchroot07 fchroot07_child +fchroot08
testcases/kernel/syscalls/fchroot/fchroot08.c new file +69 -0
69 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH STAGING v4 11/16] fchroot08: test failfs root fork inheritance
Hi!
Quoted 86 lines
Verify that the root moved into failfs by
fchroot()lives in thefs_structwhich is duplicated on fork, so a child of a process with the failfs root also fails every absolute path lookup with EOPNOTSUPP.Signed-off-by Andrea Cervesato <[email protected]>--- runtest/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot08.c | 69 +++++++++++++++++++++++++++ 3 files changed, 71 insertions(+)runtest/staging +1
-0@@ -7,3 +7,4 @@ fchroot04 fchroot04 fchroot05 fchroot05 fchroot06 fchroot06 fchroot07 fchroot07 +fchroot08 fchroot08testcases/kernel/syscalls/fchroot/.gitignore +1
-0@@ -6,3 +6,4 @@ fchroot05 fchroot06 fchroot07 fchroot07_child +fchroot08testcases/kernel/syscalls/fchroot/fchroot08.c new file +50
-0@@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2026 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* Test that the failfs root is inherited across :manpage:`fork(2)`. +* +* The root moved into failfs by :manpage:`fchroot(2)` lives in the +* fs_struct which is duplicated on :manpage:`fork(2)`, so a child of a process with the +* failfs root also fails every absolute path lookup with ``EOPNOTSUPP``. +* +* Root is required because entering failfs with the ``FD_FAILFS_ROOT`` +* sentinel requires ``CAP_SYS_CHROOT``. +* +* The test runs in a forked child so the root of the parent process is +* left untouched. +*/ + +#define _GNU_SOURCE +#include <fcntl.h> +#include <sys/wait.h> +#include "tst_test.h" +#include "lapi/fcntl.h" +#include "lapi/syscalls.h" + +#define ABSDIR "abs" + +static void run (void ) +{ +if (SAFE_FORK ()) +return ; + +pid_t pid; + +TST_EXP_PASS (tst_syscall (__NR_fchroot,FD_FAILFS_ROOT ,0 ), +"fchroot() with the FD_FAILFS_ROOT sentinel" ); + + pid =SAFE_FORK (); +if (!pid) { +TST_EXP_FAIL2 (open (ABSDIR ,O_PATH ),EOPNOTSUPP , +"absolute lookup in a forked child" ); +exit (0 ); + } + +SAFE_WAITPID (pid,NULL ,0 ); + +exit (0 ); +} +
testcases/kernel/syscalls/fchroot/fchroot08.c line 60
Quoted 10 lines
testcases/kernel/syscalls/fchroot/fchroot08.c new file +10
-0+static void setup (void ) +{ +char *tmpdir; +char abs_path[PATH_MAX ]; + + tmpdir =tst_tmpdir_path (); +snprintf (abs_path,sizeof (abs_path),"%s/%s" , tmpdir,"target" ); + +SAFE_TOUCH ("target" ,0644 ,NULL ); +SAFE_SYMLINK (abs_path,ABSDIR );
I do not understand why we do the symlink here?
Why don't we pass the abs_path to the syscall directly?
Quoted 16 lines
testcases/kernel/syscalls/fchroot/fchroot08.c new file +9
-0+} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_root =1 , + .forks_child =1 , + .needs_tmpdir =1 , +};Signature · 6 lines
-- 2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 12/16 fchroot09: test setns escape from failfs root
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Verify that entering failfs with fchroot() is hard to undo: a process inside counts as chrooted, so the remaining way out is a pre-opened mount namespace fd. setns() into it resets both the root and the working directory.
--- runtest/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot09.c | 86 +++++++++++++++++++++++++++ 3 files changed, 88 insertions(+)
runtest/staging +1 -0
@@ -8,3 +8,4 @@ fchroot05 fchroot05 fchroot06 fchroot06 fchroot07 fchroot07 fchroot08 fchroot08 +fchroot09 fchroot09
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
@@ -7,3 +7,4 @@ fchroot06 fchroot07 fchroot07_child fchroot08 +fchroot09
testcases/kernel/syscalls/fchroot/fchroot09.c new file +86 -0
86 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH STAGING v4 12/16] fchroot09: test setns escape from failfs root
Hi!
Quoted 91 lines
Verify that entering failfs with
fchroot()is hard to undo: a process inside counts as chrooted, so the remaining way out is a pre-opened mount namespace fd.setns()into it resets both the root and the working directory.Signed-off-by Andrea Cervesato <[email protected]>--- runtest/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot09.c | 86 +++++++++++++++++++++++++++ 3 files changed, 88 insertions(+)runtest/staging +1
-0@@ -8,3 +8,4 @@ fchroot05 fchroot05 fchroot06 fchroot06 fchroot07 fchroot07 fchroot08 fchroot08 +fchroot09 fchroot09testcases/kernel/syscalls/fchroot/.gitignore +1
-0@@ -7,3 +7,4 @@ fchroot06 fchroot07 fchroot07_child fchroot08 +fchroot09testcases/kernel/syscalls/fchroot/fchroot09.c new file +55
-0@@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2026 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* Test that :manpage:`setns(2)` escapes the failfs root. +* +* Entering failfs with :manpage:`fchroot(2)` is hard to undo: a process +* inside counts as chrooted, so :manpage:`chroot(2)` and :manpage:`fchroot(2)` +* back out require ``CAP_SYS_CHROOT``. The remaining way out is a pre-opened +* mount namespace file descriptor: :manpage:`setns(2)` into it resets both the +* root and the working directory. +* +* Root is required because entering failfs requires ``CAP_SYS_CHROOT`` and +* :manpage:`setns(2)` into the mount namespace requires ``CAP_SYS_ADMIN``. +* +* The test runs in a forked child so the root of the parent process is +* left untouched. +*/ + +#define _GNU_SOURCE +#include <fcntl.h> +#include <sys/stat.h> +#include "tst_test.h" +#include "lapi/fcntl.h" +#include "lapi/sched.h" +#include "lapi/setns.h" +#include "lapi/syscalls.h" + +#define ABSDIR "abs" + +static void run (void ) +{ +if (SAFE_FORK ()) +return ; + +struct stat realroot, st; +int nsfd; + +SAFE_STAT ("/" , &realroot); + nsfd =SAFE_OPEN ("/proc/self/ns/mnt" ,O_RDONLY ); + +TST_EXP_PASS (tst_syscall (__NR_fchroot,FD_FAILFS_ROOT ,0 ), +"fchroot() with the FD_FAILFS_ROOT sentinel" ); + +TST_EXP_FAIL2 (open (ABSDIR ,O_PATH ),EOPNOTSUPP , +"absolute lookup after entering failfs" ); + +TST_EXP_PASS (setns (nsfd,CLONE_NEWNS ), +"setns() back into the mount namespace" ); + +SAFE_CLOSE (nsfd); + +SAFE_STAT ("/" , &st);
testcases/kernel/syscalls/fchroot/fchroot09.c line 65
Quoted 10 lines
testcases/kernel/syscalls/fchroot/fchroot09.c new file +10
-0+TST_EXP_EXPR (st.st_dev == realroot.st_dev && + st.st_ino == realroot.st_ino, +"root restored after setns()" ); + +SAFE_STAT ("." , &st); +TST_EXP_EXPR (st.st_dev == realroot.st_dev && + st.st_ino == realroot.st_ino, +"working directory restored after setns()" ); + +exit (0 );
Here as well, no need for the exit.
testcases/kernel/syscalls/fchroot/fchroot09.c line 77
Quoted 12 lines
testcases/kernel/syscalls/fchroot/fchroot09.c new file +12
-0+} + +static void setup (void ) +{ +char *tmpdir; +char abs_path[PATH_MAX ]; + + tmpdir =tst_tmpdir_path (); +snprintf (abs_path,sizeof (abs_path),"%s/%s" , tmpdir,"target" ); + +SAFE_TOUCH ("target" ,0644 ,NULL ); +SAFE_SYMLINK (abs_path,ABSDIR );
Here as well, why are all the absolute directories symlinks? It makes sense to have a test symlink to absolute directory restarts the lookup and fails, but why don't we use just abs_path in most of the tests?
I suppose that we can even open just "/" with O_PATH to check if the failfs root is active or not...
Quoted 16 lines
testcases/kernel/syscalls/fchroot/fchroot09.c new file +9
-0+} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_root =1 , + .forks_child =1 , + .needs_tmpdir =1 , +};Signature · 6 lines
-- 2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 13/16 fchroot10: test failfs entry without no_new_privs
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Verify that unprivileged fchroot() into failfs is refused withoutno_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/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot10.c | 54 +++++++++++++++++++++++++++ 3 files changed, 56 insertions(+)
runtest/staging +1 -0
@@ -9,3 +9,4 @@ fchroot06 fchroot06 fchroot07 fchroot07 fchroot08 fchroot08 fchroot09 fchroot09 +fchroot10 fchroot10
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
@@ -8,3 +8,4 @@ fchroot07 fchroot07_child fchroot08 fchroot09 +fchroot10
testcases/kernel/syscalls/fchroot/fchroot10.c new file +54 -0
54 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH STAGING v4 13/16] fchroot10: test failfs entry without no_new_privs
Hi!
testcases/kernel/syscalls/fchroot/fchroot10.c line 38
Quoted 12 lines
testcases/kernel/syscalls/fchroot/fchroot10.c new file +12
-0+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 );
Here as well, no need for the exit(0)
Otherwise:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 14/16 fchroot11: test failfs entry with no_new_privs
In reply to Andrea CervesatoFrom: 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/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot11.c | 70 +++++++++++++++++++++++++++ 3 files changed, 72 insertions(+)
runtest/staging +1 -0
@@ -10,3 +10,4 @@ fchroot07 fchroot07 fchroot08 fchroot08 fchroot09 fchroot09 fchroot10 fchroot10 +fchroot11 fchroot11
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
@@ -9,3 +9,4 @@ fchroot07_child fchroot08 fchroot09 fchroot10 +fchroot11
testcases/kernel/syscalls/fchroot/fchroot11.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
Re: [LTP] [PATCH STAGING v4 14/16] fchroot11: test failfs entry with no_new_privs
Hi!
Quoted 75 lines
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 withunshare()to regainCAP_SYS_CHROOT.Signed-off-by Andrea Cervesato <[email protected]>--- runtest/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot11.c | 70 +++++++++++++++++++++++++++ 3 files changed, 72 insertions(+)runtest/staging +1
-0@@ -10,3 +10,4 @@ fchroot07 fchroot07 fchroot08 fchroot08 fchroot09 fchroot09 fchroot10 fchroot10 +fchroot11 fchroot11testcases/kernel/syscalls/fchroot/.gitignore +1
-0@@ -9,3 +9,4 @@ fchroot07_child fchroot08 fchroot09 fchroot10 +fchroot11testcases/kernel/syscalls/fchroot/fchroot11.c new file +38
-0@@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2026 SUSE LLC Andrea Cervesato <[email protected]> +*/ + +/*\ +* Test unprivileged :manpage:`fchroot(2)` into failfs with no_new_privs +* set. +* +* 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 +* :manpage:`unshare(2)` to regain ``CAP_SYS_CHROOT``. +* +* The user namespace check requires ``CONFIG_USER_NS``, which is enforced +* with ``.needs_kconfigs``. +* +* Root is required to drop to an unprivileged user in the forked child. +*/ + +#define _GNU_SOURCE +#include <fcntl.h> +#include <pwd.h> +#include <sched.h> +#include "tst_test.h" +#include "lapi/fcntl.h" +#include "lapi/prctl.h" +#include "lapi/sched.h" +#include "lapi/syscalls.h" + +static struct passwd *ltpuser; + +static void run (void ) +{ +if (SAFE_FORK ()) +return ; +
testcases/kernel/syscalls/fchroot/fchroot11.c line 48
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 ); + +TST_EXP_PASS (tst_syscall (__NR_fchroot,FD_FAILFS_ROOT ,0 ), +"unprivileged fchroot() with no_new_privs" ); + +TST_EXP_FAIL2 (open ("/etc/passwd" ,O_RDONLY ),EOPNOTSUPP , +"absolute lookup after entering failfs" );
AFAIK there is no /etc/passwd on Android. Maybe we should use /dev/zero instead?
testcases/kernel/syscalls/fchroot/fchroot11.c line 53
Quoted 4 lines
testcases/kernel/syscalls/fchroot/fchroot11.c new file +4
-0+TST_EXP_FAIL (unshare (CLONE_NEWUSER ),EPERM , +"user namespace creation blocked by the failfs root" ); + +exit (0 );
Here as well, no need for the exit(0).
Quoted 24 lines
testcases/kernel/syscalls/fchroot/fchroot11.c new file +17
-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 , + .needs_kconfigs = (const char *[]) { +"CONFIG_USER_NS=y" , +NULL , + } +};Signature · 6 lines
-- 2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 15/16 fchroot12: test failfs entry with shared fs_struct
In reply to Andrea CervesatoFrom: 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/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot12.c | 85 +++++++++++++++++++++++++++ 3 files changed, 87 insertions(+)
runtest/staging +1 -0
@@ -11,3 +11,4 @@ fchroot08 fchroot08 fchroot09 fchroot09 fchroot10 fchroot10 fchroot11 fchroot11 +fchroot12 fchroot12
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
@@ -10,3 +10,4 @@ fchroot08 fchroot09 fchroot10 fchroot11 +fchroot12
testcases/kernel/syscalls/fchroot/fchroot12.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
Re: [LTP] [PATCH STAGING v4 15/16] fchroot12: test failfs entry with shared fs_struct
Hi!
testcases/kernel/syscalls/fchroot/fchroot12.c line 70
Quoted 7 lines
testcases/kernel/syscalls/fchroot/fchroot12.c new file +7
-0+TST_EXP_FAIL (tst_syscall (__NR_fchroot,FD_FAILFS_ROOT ,0 ), +EINVAL ,"fchroot() with a shared fs_struct" ); + +SAFE_KILL (sib,SIGKILL ); +SAFE_WAITPID (sib,NULL ,0 ); + +exit (0 );
Here as well, no need for the exit(0), otherwise:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 16/16 fchroot13: test failfs entry when chrooted
In reply to Andrea CervesatoFrom: 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/staging | 1 + testcases/kernel/syscalls/fchroot/.gitignore | 1 + testcases/kernel/syscalls/fchroot/fchroot13.c | 63 +++++++++++++++++++++++++++ 3 files changed, 65 insertions(+)
runtest/staging +1 -0
@@ -12,3 +12,4 @@ fchroot09 fchroot09 fchroot10 fchroot10 fchroot11 fchroot11 fchroot12 fchroot12 +fchroot13 fchroot13
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
@@ -11,3 +11,4 @@ fchroot09 fchroot10 fchroot11 fchroot12 +fchroot13
testcases/kernel/syscalls/fchroot/fchroot13.c new file +63 -0
63 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp