Skip to contentSkip to conversation

fchroot: add fchroot() testing suite

PATCH Superseded Andrea Cervesato 3 participants 19 messages Aug 19 – Aug 20

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

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.

---
Andrea Cervesato (16):
syscalls: add v7.3 syscall numbers
syscalls: update outdated syscall entries
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  | 13 ++++
 testcases/kernel/syscalls/fchroot/Makefile    |  7 +++
 testcases/kernel/syscalls/fchroot/fchroot01.c | 57 +++++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot02.c | 80 ++++++++++++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot03.c | 77 +++++++++++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot04.c | 66 ++++++++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot05.c | 75 ++++++++++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot06.c | 90 +++++++++++++++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot07.c | 71 +++++++++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot08.c | 52 ++++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot09.c | 70 +++++++++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot10.c | 49 +++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot11.c | 74 ++++++++++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot12.c | 82 ++++++++++++++++++++++++
 testcases/kernel/syscalls/fchroot/fchroot13.c | 62 ++++++++++++++++++
 34 files changed, 1006 insertions(+), 19 deletions(-)

---
base-commit: 567528e2f809c1309802433703c083bd15ab81a8
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 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
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 2/16 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

PATCH 3/16 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
#4 lore raw

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

Hi Andrea,

Quoted 1 line · Andrea Cervesato

syscalls: add v7.3 syscall numbers

--- [PATCH 3/16] ---

Quoted 3 lines

/* Roots of kernel internal pseudo filesystems, usable as fd sentinels */ #ifndef FD_PIDFS_ROOT

# define FD_PIDFS_ROOT		-10002

Could these new public macros use kernel-doc comments? Public macros added under include/lapi must be documented in syntax recognized by linuxdoc.

--- [PATCH 4/16] ---

Quoted 1 line

fchroot01: test fchroot() with a directory fd

Could the subject carry the "[STAGING]" prefix? Linux 7.2 is the latest stable release, while this test targets fchroot() from the 7.3 development cycle and is placed in runtest/staging.

--- [PATCH 5/16] ---

Quoted 1 line

fchroot02: test fchroot() invalid arguments

Could the subject carry the "[STAGING]" prefix? Linux 7.2 is the latest stable release, while this test targets fchroot() from the 7.3 development cycle and is placed in runtest/staging.

--- [PATCH 6/16] ---

Quoted 1 line

fchroot03: test fchroot() permission checks

Could the subject carry the "[STAGING]" prefix? Linux 7.2 is the latest stable release, while this test targets fchroot() from the 7.3 development cycle and is placed in runtest/staging.

--- [PATCH 7/16] ---

Quoted 1 line

fchroot04: test fchroot() into failfs as root

Could the subject carry the "[STAGING]" prefix? Linux 7.2 is the latest stable release, while this test targets fchroot() and failfs from the 7.3 development cycle and is placed in runtest/staging.

--- [PATCH 8/16] ---

Quoted 1 line

fchroot05: test failfs root can not be referenced

Could the subject carry the "[STAGING]" prefix? Linux 7.2 is the latest stable release, while this test targets fchroot() and failfs from the 7.3 development cycle and is placed in runtest/staging.

--- [PATCH 9/16] ---

Quoted 1 line

fchroot06: test path walks under failfs root

Could the subject carry the "[STAGING]" prefix? Linux 7.2 is the latest stable release, while this test targets fchroot() and failfs from the 7.3 development cycle and is placed in runtest/staging.

Quoted 1 line

#define UPWARDS "../../../../../../../../../.."

Could this walk continue until the inode stops changing instead? LTP accepts any absolute TMPDIR, so a path more than ten components deep leaves this lookup at an intermediate directory and fails the root inode comparison on a correct kernel.

--- [PATCH 10/16] ---

Quoted 1 line

fchroot07: test execve blocked by failfs root

Could the subject carry the "[STAGING]" prefix? Linux 7.2 is the latest stable release, while this test targets fchroot() and failfs from the 7.3 development cycle and is placed in runtest/staging.

--- [PATCH 11/16] ---

Quoted 1 line

fchroot08: test failfs root fork inheritance

Could the subject carry the "[STAGING]" prefix? Linux 7.2 is the latest stable release, while this test targets fchroot() and failfs from the 7.3 development cycle and is placed in runtest/staging.

--- [PATCH 12/16] ---

Quoted 1 line

fchroot09: test setns escape from failfs root

Could the subject carry the "[STAGING]" prefix? Linux 7.2 is the latest stable release, while this test targets fchroot() and failfs from the 7.3 development cycle and is placed in runtest/staging.

Quoted 3 lines
		SAFE_STAT(".", &st);
		TST_EXP_EXPR(st.st_dev == realcwd.st_dev &&
			st.st_ino == realcwd.st_ino,

Should this compare "." with realroot instead? mntns_install() resolves the target namespace's "/" and assigns it to both fs->root and fs->pwd; it does not restore the previous working directory. Unless the test starts in "/", this comparison fails on a correct kernel.

--- [PATCH 13/16] ---

Quoted 1 line

fchroot10: test failfs entry without no_new_privs

Could the subject carry the "[STAGING]" prefix? Linux 7.2 is the latest stable release, while this test targets fchroot() and failfs from the 7.3 development cycle and is placed in runtest/staging.

Quoted 4 lines

static void setup(void)

{
	ltpuser = SAFE_GETPWNAM("nobody");
}

Could setup query PR_GET_NO_NEW_PRIVS and return TCONF when it is already set? The bit is inherited and cannot be cleared, so such a launcher makes this test exercise the allowed-entry path and report a kernel failure.

--- [PATCH 14/16] ---

Quoted 1 line

fchroot11: test failfs entry with no_new_privs

Could the subject carry the "[STAGING]" prefix? Linux 7.2 is the latest stable release, while this test targets fchroot() and failfs from the 7.3 development cycle and is placed in runtest/staging.

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

Could a separate unprivileged child first prove that user-namespace creation works, with TCONF when the environment blocks it? Runtime policy, seccomp, or an LSM can return EPERM even with CONFIG_USER_NS=y, making this assertion pass without testing the failfs restriction.

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

Quoted 1 line

fchroot12: test failfs entry with shared fs_struct

Could the subject carry the "[STAGING]" prefix? Linux 7.2 is the latest stable release, while this test targets fchroot() and failfs from the 7.3 development cycle and is placed in runtest/staging.

--- [PATCH 16/16] ---

Quoted 1 line

fchroot13: test failfs entry when chrooted

Could the subject carry the "[STAGING]" prefix? Linux 7.2 is the latest stable release, while this test targets fchroot() and failfs from the 7.3 development cycle and is placed in runtest/staging.

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

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

Quoted 6 lines
Quoted 3 lines

/* Roots of kernel internal pseudo filesystems, usable as fd sentinels */ #ifndef FD_PIDFS_ROOT

# define FD_PIDFS_ROOT		-10002

Could these new public macros use kernel-doc comments? Public macros added under include/lapi must be documented in syntax recognized by linuxdoc.

Not needed.

Quoted 8 lines

--- [PATCH 4/16] ---

Quoted 1 line

fchroot01: test fchroot() with a directory fd

Could the subject carry the "[STAGING]" prefix? Linux 7.2 is the latest stable release, while this test targets fchroot() from the 7.3 development cycle and is placed in runtest/staging.

This is correct for all the patches.

Quoted 6 lines
Quoted 1 line

#define UPWARDS "../../../../../../../../../.."

Could this walk continue until the inode stops changing instead? LTP accepts any absolute TMPDIR, so a path more than ten components deep leaves this lookup at an intermediate directory and fails the root inode comparison on a correct kernel.

Hard to happen but correct.

Quoted 8 lines
Quoted 3 lines
		SAFE_STAT(".", &st);
		TST_EXP_EXPR(st.st_dev == realcwd.st_dev &&
			st.st_ino == realcwd.st_ino,

Should this compare "." with realroot instead? mntns_install() resolves the target namespace's "/" and assigns it to both fs->root and fs->pwd; it does not restore the previous working directory. Unless the test starts in "/", this comparison fails on a correct kernel.

I need to verify.

Quoted 8 lines
Quoted 4 lines

static void setup(void)

{
	ltpuser = SAFE_GETPWNAM("nobody");
}

Could setup query PR_GET_NO_NEW_PRIVS and return TCONF when it is already set? The bit is inherited and cannot be cleared, so such a launcher makes this test exercise the allowed-entry path and report a kernel failure.

Need to verify.

Quoted 9 lines

--- [PATCH 14/16] ---

Quoted 1 line

fchroot11: test failfs entry with no_new_privs

Could the subject carry the "[STAGING]" prefix? Linux 7.2 is the latest stable release, while this test targets fchroot() and failfs from the 7.3 development cycle and is placed in runtest/staging.

Quoted 7 lines
Quoted 2 lines
	TST_EXP_FAIL(unshare(CLONE_NEWUSER), EPERM,
		"user namespace creation blocked by the failfs root");

Could a separate unprivileged child first prove that user-namespace creation works, with TCONF when the environment blocks it? Runtime policy, seccomp, or an LSM can return EPERM even with CONFIG_USER_NS=y, making this assertion pass without testing the failfs restriction.

Will try.

Will send a v2.

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

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

PATCH 4/16 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 | 57 +++++++++++++++++++++++++++
 4 files changed, 67 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 +57 -0

57 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 5/16 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 | 80 +++++++++++++++++++++++++++
 3 files changed, 82 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 +80 -0

80 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 6/16 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 | 77 +++++++++++++++++++++++++++
 3 files changed, 79 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 +77 -0

77 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 7/16 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 | 66 +++++++++++++++++++++++++++
 3 files changed, 68 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 +66 -0

66 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 8/16 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
#11 lore raw

PATCH 9/16 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 | 90 +++++++++++++++++++++++++++
 3 files changed, 92 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 +90 -0

90 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 10/16 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                               |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot07.c | 71 +++++++++++++++++++++++++++
 3 files changed, 73 insertions(+)
runtest/staging +1 -0
index 8b6b1ecd9..b8954bb5a 100644
@@ -6,3 +6,4 @@ fchroot03 fchroot03
 fchroot04 fchroot04
 fchroot05 fchroot05
 fchroot06 fchroot06
+fchroot07 fchroot07
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
index 12151270a..b68069d9a 100644
@@ -4,3 +4,4 @@ fchroot03
 fchroot04
 fchroot05
 fchroot06
+fchroot07
testcases/kernel/syscalls/fchroot/fchroot07.c new file +71 -0

71 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 11/16 fchroot08: test failfs root fork inheritance

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

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

---
 runtest/staging                               |  1 +
 testcases/kernel/syscalls/fchroot/.gitignore  |  1 +
 testcases/kernel/syscalls/fchroot/fchroot08.c | 52 +++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)
runtest/staging +1 -0
index b8954bb5a..8dfe95c4a 100644
@@ -7,3 +7,4 @@ fchroot04 fchroot04
 fchroot05 fchroot05
 fchroot06 fchroot06
 fchroot07 fchroot07
+fchroot08 fchroot08
testcases/kernel/syscalls/fchroot/.gitignore +1 -0
index b68069d9a..c099b4b3a 100644
@@ -5,3 +5,4 @@ fchroot04
 fchroot05
 fchroot06
 fchroot07
+fchroot08
testcases/kernel/syscalls/fchroot/fchroot08.c new file +52 -0

52 lines not on this page · raw message

Signature · 5 lines
2.51.0


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

PATCH 12/16 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 | 70 +++++++++++++++++++++++++++
 3 files changed, 72 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 c099b4b3a..e803fa2b7 100644
@@ -6,3 +6,4 @@ fchroot05
 fchroot06
 fchroot07
 fchroot08
+fchroot09
testcases/kernel/syscalls/fchroot/fchroot09.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 13/16 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 | 49 +++++++++++++++++++++++++++
 3 files changed, 51 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 e803fa2b7..570da2b98 100644
@@ -7,3 +7,4 @@ fchroot06
 fchroot07
 fchroot08
 fchroot09
+fchroot10
testcases/kernel/syscalls/fchroot/fchroot10.c new file +49 -0

49 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 14/16 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 | 74 +++++++++++++++++++++++++++
 3 files changed, 76 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 570da2b98..0eca20548 100644
@@ -8,3 +8,4 @@ fchroot07
 fchroot08
 fchroot09
 fchroot10
+fchroot11
testcases/kernel/syscalls/fchroot/fchroot11.c new file +74 -0

74 lines not on this page · raw message

Signature · 5 lines
2.51.0


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

PATCH 15/16 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 | 82 +++++++++++++++++++++++++++
 3 files changed, 84 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 0eca20548..de8ca0688 100644
@@ -9,3 +9,4 @@ fchroot08
 fchroot09
 fchroot10
 fchroot11
+fchroot12
testcases/kernel/syscalls/fchroot/fchroot12.c new file +82 -0

82 lines not on this page · raw message

Signature · 5 lines
2.51.0


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

PATCH 16/16 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 | 62 +++++++++++++++++++++++++++
 3 files changed, 64 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 de8ca0688..0c4461611 100644
@@ -10,3 +10,4 @@ fchroot09
 fchroot10
 fchroot11
 fchroot12
+fchroot13
testcases/kernel/syscalls/fchroot/fchroot13.c new file +62 -0

62 lines not on this page · raw message

Signature · 5 lines
2.51.0


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