[PATCH v2] clone11: skip CLONE_NEWCGROUP on kernels < 4.6

Andrea Cervesato <[email protected]>
Newsgroups gmane.linux.ltp
Message-ID <[email protected]>
From: Andrea Cervesato <andrea.cervesato-IBi9RG/[email protected]>

CLONE_NEWCGROUP was added in kernel v4.6. On older kernels such as
v4.4, the flag is unknown and clone() returns EINVAL instead of the
expected EPERM, causing a spurious test failure.

Add a per-test-case minimum kernel version check so that the
CLONE_NEWCGROUP case reports TCONF on kernels older than 4.6.

Reviewed-by: Avinesh Kumar <avinesh.kumar-IBi9RG/[email protected]>
Reviewed-by: Wei Gao <wegao-IBi9RG/[email protected]>
Signed-off-by: Andrea Cervesato <andrea.cervesato-IBi9RG/[email protected]>
---
Changes in v2:
- follow madvise02 pattern to recognize if test needs to be skipped
- Link to v1: https://lore.kernel.org/r/20260611-fix_clone11_min_kver-v1-1-264fba2b01b4-IBi9RG/[email protected]
---
 testcases/kernel/syscalls/clone/clone11.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/testcases/kernel/syscalls/clone/clone11.c b/testcases/kernel/syscalls/clone/clone11.c
index 028da778158de6867a71ac3974f9c2263481d3a3..98b36c8ec2ea51d9333fcd899cb1908e2839d851 100644
--- a/testcases/kernel/syscalls/clone/clone11.c
+++ b/testcases/kernel/syscalls/clone/clone11.c
@@ -21,6 +21,7 @@ static int *child_pid;
 static struct tcase {
 	uint64_t flags;
 	const char *sflags;
+	int skip;
 } tcases[] = {
 	{ DESC(CLONE_NEWPID) },
 	{ DESC(CLONE_NEWCGROUP) },
@@ -36,10 +37,33 @@ static int child_fn(void *arg LTP_ATTRIBUTE_UNUSED)
 	_exit(0);
 }
 
+static void tcases_filter(void)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(tcases); i++) {
+		struct tcase *tc = &tcases[i];
+
+		switch (tc->flags) {
+		case CLONE_NEWCGROUP:
+			if (tst_kvercmp(4, 6, 0) < 0)
+				tc->skip = 1;
+			break;
+		default:
+			break;
+		}
+	}
+}
+
 static void run(unsigned int n)
 {
 	struct tcase *tc = &tcases[n];
 
+	if (tc->skip) {
+		tst_res(TCONF, "%s is not supported", tc->sflags);
+		return;
+	}
+
 	TST_EXP_FAIL(ltp_clone(tc->flags, child_fn, NULL, CHILD_STACK_SIZE, child_stack),
 		EPERM, "clone(%s) should fail with EPERM",
 		tc->sflags);
@@ -51,6 +75,8 @@ static void setup(void)
 			PROT_READ | PROT_WRITE,
 			MAP_SHARED | MAP_ANONYMOUS,
 			-1, 0);
+
+	tcases_filter();
 }
 
 static void cleanup(void)

---
base-commit: a3fda1dc1ce7da882a592a4877da7f214e468650
change-id: 20260611-fix_clone11_min_kver-394cf499c2c7

Best regards,
-- 
Andrea Cervesato <andrea.cervesato-IBi9RG/[email protected]>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.