Skip to contentSkip to conversation

fchroot: add fchroot() testing suite

PATCH Superseded Andrea Cervesato 2 participants 17 messages Aug 28

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 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 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 (15):
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] 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      |  70 ++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot05.c      |  75 ++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot06.c      | 126 +++++++++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot07.c      |  56 +++++++++
 .../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      |  50 ++++++++
 testcases/kernel/syscalls/fchroot/fchroot11.c      |  70 ++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot12.c      |  85 ++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot13.c      |  63 +++++++++++
 35 files changed, 1073 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
#1 lore raw

PATCH v3 1/15 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
index 0f0fbef6b..96b14c1b9 100644
@@ -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
index d0238dec5..c4058e8de 100644
@@ -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
index c76930e20..26a61e830 100644
@@ -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
index 38ea71fb2..21d5da053 100644
@@ -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
index a1dfce79e..88e77ef8a 100644
@@ -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
index 436d5c681..3c19066b8 100644
@@ -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
index 860a19c8b..0c539bd62 100644
@@ -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
index 5e53e46ce..ecbe4d4b9 100644
@@ -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
index 238756694..e84c3b344 100644
@@ -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
index 6911f9af9..9354dbe2b 100644
@@ -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
index 98190ba26..e4bef6838 100644
@@ -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
index a6cb85da8..4a11871b6 100644
@@ -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
index 31f3ec553..055a039fb 100644
@@ -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
index ac281acf8..29cd8f8df 100644
@@ -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
index ffc0d9f7a..ea2bfc9c1 100644
@@ -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
index 992bd307d..692652c3b 100644
@@ -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
index e9c0d0599..7d3d8163c 100644
@@ -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
#2 lore raw

PATCH v3 2/15 syscalls: update outdated syscall entries

In reply to Andrea Cervesato

From: 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
index c4058e8de..158350976 100644
@@ -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
index 21d5da053..ee229b567 100644
@@ -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
index 3c19066b8..d1087e049 100644
@@ -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
index 0c539bd62..2a3883198 100644
@@ -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
index ecbe4d4b9..0d682d072 100644
@@ -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
index e84c3b344..71d40f7b2 100644
@@ -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
index 9354dbe2b..85d7aec9a 100644
@@ -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
index e4bef6838..def01478d 100644
@@ -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
index 4a11871b6..5024313a5 100644
@@ -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
index 055a039fb..357b04ceb 100644
@@ -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
index 29cd8f8df..584d36a4e 100644
@@ -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
index ea2bfc9c1..a48c5b365 100644
@@ -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
index 692652c3b..9f3e825a9 100644
@@ -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
index 7d3d8163c..1996c26b8 100644
@@ -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
#3 lore raw

Re: [LTP] syscalls: add v7.3 syscall numbers

Hi Andrea,

Quoted 1 line · Andrea Cervesato

syscalls: add v7.3 syscall numbers

--- [PATCH 4/15] ---

Quoted 1 line

fchroot01: test fchroot() with a directory fd

Since 7.2 is the latest stable kernel and this test targets a 7.3 feature, could the subject start with "[STAGING]" as required for unreleased kernel features?

--- [PATCH 5/15] ---

Quoted 1 line

fchroot02: test fchroot() invalid arguments

Since 7.2 is the latest stable kernel and this test targets a 7.3 feature, could the subject start with "[STAGING]" as required for unreleased kernel features?

--- [PATCH 6/15] ---

Quoted 1 line

fchroot03: test fchroot() permission checks

Since 7.2 is the latest stable kernel and this test targets a 7.3 feature, could the subject start with "[STAGING]" as required for unreleased kernel features?

--- [PATCH 7/15] ---

Quoted 1 line

fchroot04: test fchroot() into failfs as root

Since 7.2 is the latest stable kernel and this test targets a 7.3 feature, could the subject start with "[STAGING]" as required for unreleased kernel features?

--- [PATCH 8/15] ---

Quoted 1 line

fchroot05: test failfs root can not be referenced

Since 7.2 is the latest stable kernel and this test targets a 7.3 feature, could the subject start with "[STAGING]" as required for unreleased kernel features?

--- [PATCH 9/15] ---

Quoted 1 line

fchroot06: test path walks under failfs root

Since 7.2 is the latest stable kernel and this test targets a 7.3 feature, could the subject start with "[STAGING]" as required for unreleased kernel features?

--- [PATCH 10/15] ---

Quoted 1 line

fchroot07: test execve blocked by failfs root

Since 7.2 is the latest stable kernel and these tests target a 7.3 feature, could the subject start with "[STAGING]" as required for unreleased kernel features?

Review

Quoted 2 lines
(quoted diff) +2 -0
+fchroot07 fchroot07
+fchroot08 fchroot08

The subject and body describe only the fchroot07 exec test. Could fchroot08, which tests inheritance across fork(), be split into its own patch or documented in a subject and body that cover both tests?

Quoted 3 lines

The exec runs in a
grandchild so a wrongly successful exec is still detected through the exit code.

Could this explanation be corrected to match the implementation? fchroot07_child reports TFAIL and returns 0, while SAFE_WAIT(NULL) does not inspect an exit status. The failure is propagated through the reinitialized LTP result channel rather than through the exit code.

--- [PATCH 11/15] ---

Quoted 1 line

fchroot09: test setns escape from failfs root

Since 7.2 is the latest stable kernel and this test targets a 7.3 feature, could the subject start with "[STAGING]" as required for unreleased kernel features?

Quoted 4 lines

* Entering failfs with :manpage:fchroot(2) is hard to undo: a process
* inside counts as chrooted, so :manpage:chroot(2) and fchroot() back
* out require ``CAP_SYS_CHROOT``. The remaining way out is a pre-opened mount
* namespace file descriptor: setns() into it resets both the root and the

Could the raw fchroot() and setns() references use :manpage:fchroot(2) and :manpage:setns(2)? Test documentation requires the man-page role for raw syscall references.

--- [PATCH 12/15] ---

Quoted 1 line

fchroot10: test failfs entry without no_new_privs

Since 7.2 is the latest stable kernel and this test targets a 7.3 feature, could the subject start with "[STAGING]" as required for unreleased kernel features?

Review

Quoted 5 lines
(quoted diff) +5 -0
+	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");

Could setup first verify that PR_GET_NO_NEW_PRIVS is zero and report TCONF when it is already set? The bit is inherited and cannot be cleared. If LTP is launched under a no-new-privileges policy, this child retains the bit, the kernel permits this fchroot() case, and the test reports a false failure without exercising the documented precondition.

--- [PATCH 13/15] ---

Quoted 1 line

fchroot11: test failfs entry with no_new_privs

Since 7.2 is the latest stable kernel and this test targets a 7.3 feature, could the subject start with "[STAGING]" as required for unreleased kernel features?

Review

Quoted 2 lines
(quoted diff) +2 -0
+	TST_EXP_FAIL(unshare(CLONE_NEWUSER), EPERM,
+		"user namespace creation blocked by the failfs root");

Could a separate unprivileged child establish that user namespace creation succeeds before entering failfs? CONFIG_USER_NS=y only proves kernel support. Runtime policy such as kernel.unprivileged_userns_clone=0, an LSM, or seccomp can already return EPERM for nobody. In that case this assertion reports TPASS without exercising the claimed chroot restriction.

--- [PATCH 14/15] ---

Quoted 1 line

fchroot12: test failfs entry with shared fs_struct

Since 7.2 is the latest stable kernel and this test targets a 7.3 feature, could the subject start with "[STAGING]" as required for unreleased kernel features?

--- [PATCH 15/15] ---

Quoted 1 line

fchroot13: test failfs entry when chrooted

Since 7.2 is the latest stable kernel and this test targets a 7.3 feature, could the subject start with "[STAGING]" as required for unreleased kernel features?

Quoted 2 lines

* 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

Could the raw openat() reference use :manpage:openat(2) and describe the arguments separately? Test documentation requires the man-page role for raw syscall references.

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
#4 lore raw

PATCH v3 3/15 lapi: fallback fchroot() parameters

In reply to Andrea Cervesato

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
#5 lore raw

PATCH v3 4/15 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.

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
index ef1cdea15..733d5609a 100644
@@ -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
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 +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
#6 lore raw

PATCH v3 5/15 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/staging                               |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot02.c | 75 +++++++++++++++++++++++++++
 3 files changed, 77 insertions(+)
runtest/staging +1 -0
index 733d5609a..e12230218 100644
@@ -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
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 v3 6/15 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/staging                               |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot03.c | 72 +++++++++++++++++++++++++++
 3 files changed, 74 insertions(+)
runtest/staging +1 -0
index e12230218..13635037b 100644
@@ -2,3 +2,4 @@
 
 fchroot01 fchroot01
 fchroot02 fchroot02
+fchroot03 fchroot03
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 +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
#8 lore raw

PATCH v3 7/15 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/staging                               |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot04.c | 70 +++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
runtest/staging +1 -0
index 13635037b..91dfdba08 100644
@@ -3,3 +3,4 @@
 fchroot01 fchroot01
 fchroot02 fchroot02
 fchroot03 fchroot03
+fchroot04 fchroot04
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 +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
#9 lore raw

PATCH v3 8/15 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/staging                               |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot05.c | 75 +++++++++++++++++++++++++++
 3 files changed, 77 insertions(+)
runtest/staging +1 -0
index 91dfdba08..49f51d637 100644
@@ -4,3 +4,4 @@ fchroot01 fchroot01
 fchroot02 fchroot02
 fchroot03 fchroot03
 fchroot04 fchroot04
+fchroot05 fchroot05
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 +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
#10 lore raw

PATCH v3 9/15 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/staging                               |   1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |   1 +
 testcases/kernel/syscalls/fchroot/fchroot06.c | 126 ++++++++++++++++++++++++++
 3 files changed, 128 insertions(+)
runtest/staging +1 -0
index 49f51d637..8b6b1ecd9 100644
@@ -5,3 +5,4 @@ fchroot02 fchroot02
 fchroot03 fchroot03
 fchroot04 fchroot04
 fchroot05 fchroot05
+fchroot06 fchroot06
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 +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
#11 lore raw

PATCH v3 10/15 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/staging                                    |  2 +
 testcases/kernel/syscalls/fchroot/.gitignore       |  3 +
 testcases/kernel/syscalls/fchroot/fchroot07.c      | 56 ++++++++++++++++++
 .../kernel/syscalls/fchroot/fchroot07_child.c      | 16 +++++
 testcases/kernel/syscalls/fchroot/fchroot08.c      | 69 ++++++++++++++++++++++
 5 files changed, 146 insertions(+)
runtest/staging +2 -0
index 8b6b1ecd9..8dfe95c4a 100644
@@ -6,3 +6,5 @@ fchroot03 fchroot03
 fchroot04 fchroot04
 fchroot05 fchroot05
 fchroot06 fchroot06
+fchroot07 fchroot07
+fchroot08 fchroot08
testcases/kernel/syscalls/fchroot/.gitignore +3 -0
index 12151270a..0a2510d8a 100644
@@ -4,3 +4,6 @@ fchroot03
 fchroot04
 fchroot05
 fchroot06
+fchroot07
+fchroot07_child
+fchroot08
testcases/kernel/syscalls/fchroot/fchroot07.c new file +56 -0

56 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;
+}
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
#12 lore raw

PATCH v3 11/15 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, 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
index 8dfe95c4a..23f6c6a20 100644
@@ -8,3 +8,4 @@ fchroot05 fchroot05
 fchroot06 fchroot06
 fchroot07 fchroot07
 fchroot08 fchroot08
+fchroot09 fchroot09
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 +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
#13 lore raw

PATCH v3 12/15 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/staging                               |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot10.c | 50 +++++++++++++++++++++++++++
 3 files changed, 52 insertions(+)
runtest/staging +1 -0
index 23f6c6a20..9ec2a7897 100644
@@ -9,3 +9,4 @@ fchroot06 fchroot06
 fchroot07 fchroot07
 fchroot08 fchroot08
 fchroot09 fchroot09
+fchroot10 fchroot10
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 +50 -0

50 lines not on this page · raw message

Signature · 5 lines
2.51.0


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

PATCH v3 13/15 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/staging                               |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot11.c | 70 +++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
runtest/staging +1 -0
index 9ec2a7897..137e3f99a 100644
@@ -10,3 +10,4 @@ fchroot07 fchroot07
 fchroot08 fchroot08
 fchroot09 fchroot09
 fchroot10 fchroot10
+fchroot11 fchroot11
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 +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
#15 lore raw

PATCH v3 14/15 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/staging                               |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot12.c | 85 +++++++++++++++++++++++++++
 3 files changed, 87 insertions(+)
runtest/staging +1 -0
index 137e3f99a..1655b6813 100644
@@ -11,3 +11,4 @@ fchroot08 fchroot08
 fchroot09 fchroot09
 fchroot10 fchroot10
 fchroot11 fchroot11
+fchroot12 fchroot12
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 +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
#16 lore raw

PATCH v3 15/15 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/staging                               |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot13.c | 63 +++++++++++++++++++++++++++
 3 files changed, 65 insertions(+)
runtest/staging +1 -0
index 1655b6813..95e777ffb 100644
@@ -12,3 +12,4 @@ fchroot09 fchroot09
 fchroot10 fchroot10
 fchroot11 fchroot11
 fchroot12 fchroot12
+fchroot13 fchroot13
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 +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