Skip to contentSkip to conversation

Confirming EPERM is returned when CAP_SYS_ADMIN is removed from clone3. Signed-off-by: Stephen Bertram <[email protected]>

PATCH In review Stephen Bertram via ltp 2 participants 4 messages Nov 11, 2025 – Nov 12, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Confirming EPERM is returned when CAP_SYS_ADMIN is removed from clone3. Signed-off-by: Stephen Bertram <[email protected]>

---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/clone3/.gitignore |  1 +
 testcases/kernel/syscalls/clone3/clone304.c | 63 +++++++++++++++++++++
 3 files changed, 65 insertions(+)
 create mode 100644 testcases/kernel/syscalls/clone3/clone304.c
runtest/syscalls +1 -0
index 54d94c0ca..b2c4f338e 100644
@@ -128,6 +128,7 @@ clone10 clone10
 clone301 clone301
 clone302 clone302
 clone303 clone303
++clone304 clone304
 
 close01 close01
 close02 close02
testcases/kernel/syscalls/clone3/.gitignore +1 -0
index 10369954b..e9b5312f4 100644
@@ -1,3 +1,4 @@
 clone301
 clone302
 clone303
+clone304
testcases/kernel/syscalls/clone3/clone304.c new file +63 -0

63 lines not on this page · raw message

Signature · 5 lines
2.49.0


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

Hi!
First of all the patch description shouldn't be on a single line since the first line ends up in the email subject. There should be newlines between the subject, patch description and the signed-off-by.

Quoted 12 lines
---
 runtest/syscalls                            |  1 +
 testcases/kernel/syscalls/clone3/.gitignore |  1 +
 testcases/kernel/syscalls/clone3/clone304.c | 63 +++++++++++++++++++++
 3 files changed, 65 insertions(+)
 create mode 100644 testcases/kernel/syscalls/clone3/clone304.c
runtest/syscalls +0 -0
index 54d94c0ca..b2c4f338e 100644

runtest/syscalls clone10 clone10 · line 131

Quoted 4 lines
runtest/syscalls +1 -0
@@ -128,6 +128,7 @@ clone10 clone10
 clone301 clone301
 clone302 clone302
 clone303 clone303
++clone304 clone304

^
This + shouldn't be there I suppose.

Quoted 22 lines
runtest/syscalls +0 -0
 close01 close01
 close02 close02
testcases/kernel/syscalls/clone3/.gitignore +1 -0
index 10369954b..e9b5312f4 100644
@@ -1,3 +1,4 @@
 clone301
 clone302
 clone303
+clone304
testcases/kernel/syscalls/clone3/clone304.c new file +5 -0
new file mode 100644
index 000000000..8d0d85bd4
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Stephen Bertram <[email protected]>
+ */
+

testcases/kernel/syscalls/clone3/clone304.c line 15

Quoted 10 lines
testcases/kernel/syscalls/clone3/clone304.c new file +10 -0
+/*\
+ * This test verifies that clone3() fals with EPERM when CAP_SYS_ADMIN
+ * has been dropped and ``clone_args.set_tid_size`` is greater than zero.
+ */
+
+#define _GNU_SOURCE
+#include "tst_test.h"
+#include "lapi/sched.h"
+
+struct clone_args args = {0};

Ideally this should be allocated via the guarded buffers:

	struct clone_args *args;

	struct tst_test test = {
		...
		.bufs = (struct tst_buffers []) {
			{&args, size = sizeof(*args)},
			{}
		}
		...
	}

https://linux-test-project.readthedocs.io/en/latest/developers/api_c_tests.html#guarded-buffers

Quoted 11 lines
testcases/kernel/syscalls/clone3/clone304.c new file +11 -0
+static struct tcase {
+	uint64_t flags;
+	char *sflags;
+} tcases[] = {
+	{CLONE_NEWPID, "CLONE_NEWPID"},
+	{CLONE_NEWCGROUP, "CLONE_NEWCGROUP"},
+	{CLONE_NEWIPC, "CLONE_NEWIPC"},
+	{CLONE_NEWNET, "CLONE_NEWNET"},
+	{CLONE_NEWNS, "CLONE_NEWNS"},
+	{CLONE_NEWUTS, "CLONE_NEWUTS"},
+};

testcases/kernel/syscalls/clone3/clone304.c line 37

Quoted 10 lines
testcases/kernel/syscalls/clone3/clone304.c new file +10 -0
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	pid_t tid_array[4] = {0, 0, 0, 0};
+
+	args.flags = tc->flags;
+	args.set_tid = (uint64_t)(uintptr_t)tid_array;
+
+	TST_EXP_FAIL(clone3(&args, sizeof(args)), EPERM, "clone3(%s) should fail with EPERM",tc->sflags);
                                                                                             ^
											     missing space

testcases/kernel/syscalls/clone3/clone304.c line 50

Quoted 13 lines
testcases/kernel/syscalls/clone3/clone304.c new file +13 -0
+}
+
+static void setup(void)
+{
+	clone3_supported_by_kernel();
+
+	args.pidfd = 0;
+	args.child_tid = 0;
+	args.parent_tid = 0;
+	args.exit_signal = 0;
+	args.stack = 0;
+	args.stack_size = 0;
+	args.tls = 0;

memset(args, 0, sizeof(*args) is probably safer.

testcases/kernel/syscalls/clone3/clone304.c line 61

Quoted 11 lines
testcases/kernel/syscalls/clone3/clone304.c new file +11 -0
+	args.set_tid_size = 4;  // Greater than zero - requires CAP_SYS_ADMIN
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.test = run,
+	.needs_root = 1,
+	.caps = (struct tst_cap []) {
+				TST_CAP(TST_CAP_DROP, CAP_SYS_ADMIN),
+				{}

^
Just single tab here.

Quoted 8 lines
testcases/kernel/syscalls/clone3/clone304.c new file +2 -0
+	},
+};
Signature · 5 lines
2.49.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
#2 lore raw
In reply to Stephen Bertram via ltp

Hi Stephen,

According to the clone3() manual page:

"EPERM CLONE_NEWCGROUP, CLONE_NEWIPC, CLONE_NEWNET, CLONE_NEWNS,
CLONE_NEWPID, or CLONE_NEWUTS was specified by an unprivileged process (process without CAP_SYS_ADMIN).

EPERM (clone3() only)
set_tid_size was greater than zero, and the caller lacks the
CAP_SYS_ADMIN capability in one or more of the user namespaces that own the corresponding PID namespaces."

Shouldn't we separately test both? In your test, we don't know the EPERM comes from "set_tid_size>0" (or CLONE_NEW*) with no CAP_SYS_ADMIN.

Signature · 5 lines
Regards,
Li Wang

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

Hi Li,

Quoted 8 lines · Li Wang

Hi Stephen,

According to the clone3() manual page:

"EPERM CLONE_NEWCGROUP, CLONE_NEWIPC, CLONE_NEWNET, CLONE_NEWNS,
CLONE_NEWPID, or CLONE_NEWUTS was specified by an unprivileged process (process without CAP_SYS_ADMIN).

I mis-interpreted this and thought it is only for clone3, will add a test for clone as well.

Quoted 9 lines

EPERM (clone3() only)
set_tid_size was greater than zero, and the caller lacks the
CAP_SYS_ADMIN capability in one or more of the user namespaces that own the corresponding PID namespaces."

Shouldn't we separately test both? In your test, we don't know the EPERM

See setup
args.set_tid_size = 4; // Greater than zero - requires CAP_SYS_ADMIN

Quoted 2 lines

comes from "set_tid_size>0" (or CLONE_NEW*) with no CAP_SYS_ADMIN.

That is exactly what this test does.
See run results:

Quoted 7 lines

[root@localhost clone3]# ./clone304
tst_test.c:2025: TINFO: LTP version: 20250930 tst_test.c:2028: TINFO: Tested kernel: 6.12.0-xxx.xxx.aarch64 #1 SMP PREEMPT_RT Mon Nov 10 10:56:27 EST 2025 aarch64 tst_kconfig.c:88: TINFO: Parsing kernel config '/proc/config.gz' tst_test.c:1846: TINFO: Overall timeout per run is 0h 00m 30s

Quoted 12 lines

*tst_capability.c:29: TINFO: Dropping CAP_SYS_ADMIN(21)*clone304.c:37:
TPASS: clone3(CLONE_NEWPID) should fail with EPERM : EPERM (1) clone304.c:37: TPASS: clone3(CLONE_NEWCGROUP) should fail with EPERM :
EPERM (1)
clone304.c:37: TPASS: clone3(CLONE_NEWIPC) should fail with EPERM : EPERM
(1)
clone304.c:37: TPASS: clone3(CLONE_NEWNET) should fail with EPERM : EPERM
(1)
clone304.c:37: TPASS: clone3(CLONE_NEWNS) should fail with EPERM : EPERM
(1)
clone304.c:37: TPASS: clone3(CLONE_NEWUTS) should fail with EPERM : EPERM
(1)

Summary:

Quoted 5 lines
passed   6
failed   0
broken   0
skipped  0

warnings 0

Let me know if I missed anything.

Hi Cyril and Andrea,

I received your input and I will make updates accordingly.

Thank you all,

stephen

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