Skip to contentSkip to conversation

dirtyc0w_shmem: set child_needs_reinit

PATCH New Li Wang via ltp 2 participants 5 messages May 14, 2025 Library code

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 dirtyc0w_shmem: set child_needs_reinit

---
 testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem.c | 1 +
 1 file changed, 1 insertion(+)
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem.c +1 -0
index 64b187b35..2c7ad00f2 100644
@@ -104,6 +104,7 @@ static void cleanup(void)
 
 static struct tst_test test = {
 	.needs_checkpoints = 1,
+	.child_needs_reinit =1,
 	.forks_child = 1,
 	.needs_root = 1,
 	.runtime = 120,
Signature · 5 lines
2.49.0


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

PATCH v2 2/2 lib: initialize results area to zero in the setup_ipc

To resolve several problems:

1. failure from tst_needs_cmd02 in github CI.

2. tst_run_shell.c segement fault

3. commit b987b8ac5 introduced an issue that incorrectly identified TCONF as TFAIL. This caused quite a few test cases (TCONF from old API) to be reported as failures.

4. https://github.com/linux-test-project/ltp/issues/1240

CI-Job: https://github.com/wangli5665/ltp/actions/runs/15012129791
Follow-up-fix: commit b987b8ac5 ("lib: child process exit with error due to uninitialized lib_pid")

---
 lib/tst_test.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
lib/tst_test.c +7 -7
index b666715b9..03ebdc157 100644
@@ -59,7 +59,6 @@ static const char *tid;
 static int iterations = 1;
 static float duration = -1;
 static float timeout_mul = -1;
-static pid_t lib_pid;
 static int mntpoint_mounted;
 static int ovl_mounted;
 static struct timespec tst_start_time; /* valid only for test pid */
@@ -143,7 +142,8 @@ static void setup_ipc(void)
 		tst_futexes = (char *)results + sizeof(struct results);
 		tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
 	}
-	results->lib_pid = lib_pid;
+
+	memset(results, 0 , size);
 }
 
 static void cleanup_ipc(void)
@@ -394,7 +394,7 @@ void tst_vbrk_(const char *file, const int lineno, int ttype, const char *fmt,
 	 * If tst_brk() is called from some of the C helpers even before the
 	 * library was initialized, just exit.
 	 */
-	if (!results->lib_pid)
+	if (!results || !results->lib_pid)
 		exit(TTYPE_RESULT(ttype));
 
 	update_results(TTYPE_RESULT(ttype));
@@ -1334,6 +1334,8 @@ static void do_setup(int argc, char *argv[])
 		tst_test->forks_child = 1;
 	}
 
+	setup_ipc();
+
 	if (tst_test->needs_kconfigs && tst_kconfig_check(tst_test->needs_kconfigs))
 		tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
 
@@ -1393,8 +1395,6 @@ static void do_setup(int argc, char *argv[])
 	if (tst_test->hugepages.number)
 		tst_reserve_hugepages(&tst_test->hugepages);
 
-	setup_ipc();
-
 	if (tst_test->bufs)
 		tst_buffers_alloc(tst_test->bufs);
 
@@ -1929,10 +1929,11 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 	unsigned int test_variants = 1;
 	struct utsname uval;
 
-	lib_pid = getpid();
 	tst_test = self;
 
 	do_setup(argc, argv);
+
+	results->lib_pid = getpid();
 	tst_enable_oom_protection(results->lib_pid);
 
 	SAFE_SIGNAL(SIGALRM, alarm_handler);
@@ -1940,7 +1941,6 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 
 	tst_res(TINFO, "LTP version: "LTP_VERSION);
 
-
 	uname(&uval);
 	tst_res(TINFO, "Tested kernel: %s %s %s", uval.release, uval.version, uval.machine);
 
Signature · 5 lines
2.49.0


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

PATCH v3 1/1 lib: set results->lib_pid in the setup_ipc

To resolve several problems:

1. failure from tst_needs_cmd02 in github CI.

2. tst_run_shell.c segement fault

3. commit b987b8ac5 introduced an issue that incorrectly identified TCONF as TFAIL. This caused quite a few test cases (TCONF from old API) to be reported as failures.

4. https://github.com/linux-test-project/ltp/issues/1240

CI-Job: https://github.com/wangli5665/ltp/actions/runs/15012129791
Follow-up-fix: commit b987b8ac5 ("lib: child process exit with error due to uninitialized lib_pid")

---

Notes:
v2 -> v3
* set the lib pid in setup_ipc as Cyril suggested

 lib/tst_test.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
lib/tst_test.c +6 -7
index b666715b9..923ecf7be 100644
@@ -59,7 +59,6 @@ static const char *tid;
 static int iterations = 1;
 static float duration = -1;
 static float timeout_mul = -1;
-static pid_t lib_pid;
 static int mntpoint_mounted;
 static int ovl_mounted;
 static struct timespec tst_start_time; /* valid only for test pid */
@@ -143,7 +142,9 @@ static void setup_ipc(void)
 		tst_futexes = (char *)results + sizeof(struct results);
 		tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
 	}
-	results->lib_pid = lib_pid;
+
+	memset(results, 0 , size);
+	results->lib_pid = getpid();
 }
 
 static void cleanup_ipc(void)
@@ -394,7 +395,7 @@ void tst_vbrk_(const char *file, const int lineno, int ttype, const char *fmt,
 	 * If tst_brk() is called from some of the C helpers even before the
 	 * library was initialized, just exit.
 	 */
-	if (!results->lib_pid)
+	if (!results || !results->lib_pid)
 		exit(TTYPE_RESULT(ttype));
 
 	update_results(TTYPE_RESULT(ttype));
@@ -1334,6 +1335,8 @@ static void do_setup(int argc, char *argv[])
 		tst_test->forks_child = 1;
 	}
 
+	setup_ipc();
+
 	if (tst_test->needs_kconfigs && tst_kconfig_check(tst_test->needs_kconfigs))
 		tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
 
@@ -1393,8 +1396,6 @@ static void do_setup(int argc, char *argv[])
 	if (tst_test->hugepages.number)
 		tst_reserve_hugepages(&tst_test->hugepages);
 
-	setup_ipc();
-
 	if (tst_test->bufs)
 		tst_buffers_alloc(tst_test->bufs);
 
@@ -1929,7 +1930,6 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 	unsigned int test_variants = 1;
 	struct utsname uval;
 
-	lib_pid = getpid();
 	tst_test = self;
 
 	do_setup(argc, argv);
@@ -1940,7 +1940,6 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
 
 	tst_res(TINFO, "LTP version: "LTP_VERSION);
 
-
 	uname(&uval);
 	tst_res(TINFO, "Tested kernel: %s %s %s", uval.release, uval.version, uval.machine);
 
Signature · 5 lines
2.49.0


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

Re: [LTP] [PATCH v3] lib: set results->lib_pid in the setup_ipc

Quoted 1 line

Thanks, patchset fix pushed.

Signature · 6 lines
Regards,
Li Wang


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