public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] clone10.c: avoid using the libc thread memory model in touch_tls_in_child()
@ 2026-02-26 10:35 Changwei Zou via ltp
  2026-02-26 11:11 ` Li Wang via ltp
  2026-03-04  5:59 ` Li Wang via ltp
  0 siblings, 2 replies; 4+ messages in thread
From: Changwei Zou via ltp @ 2026-02-26 10:35 UTC (permalink / raw)
  To: ltp; +Cc: changwei.zou

The thread touch_tls_in_child(), which is created using clone(),
is not fully initialized as a standard libc-managed thread.
Consequently, it is not in a proper state to invoke many libc functions safely.

Signed-off-by: Changwei Zou <changwei.zou@canonical.com>
---
 testcases/kernel/syscalls/clone/clone10.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/testcases/kernel/syscalls/clone/clone10.c b/testcases/kernel/syscalls/clone/clone10.c
index 9ffb49c37..96de811ad 100644
--- a/testcases/kernel/syscalls/clone/clone10.c
+++ b/testcases/kernel/syscalls/clone/clone10.c
@@ -20,6 +20,7 @@
 #include "tst_test.h"
 #include "clone_platform.h"
 #include "lapi/syscalls.h"
+#include "tst_atomic.h"
 #include "lapi/tls.h"
 
 #define TLS_EXP 100
@@ -34,21 +35,15 @@ struct user_desc *tls_desc;
 static __thread int tls_var;
 
 static char *child_stack;
-static volatile int child_done;
+static tst_atomic_t child_done;
 
 static int flags = CLONE_THREAD |  CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_SETTLS;
 
 static int touch_tls_in_child(void *arg LTP_ATTRIBUTE_UNUSED)
 {
-#if defined(__x86_64__)
-	if (syscall(SYS_arch_prctl, ARCH_SET_FS, tls_ptr) == -1)
-		exit(EXIT_FAILURE);
-#endif
 	tls_var = TLS_EXP + 1;
-	tst_res(TINFO, "Child (PID: %d, TID: %d): TLS value set to: %d", getpid(), (pid_t)syscall(SYS_gettid), tls_var);
+	tst_atomic_store(1, &child_done);
 
-	TST_CHECKPOINT_WAKE(0);
-	free_tls();
 	tst_syscall(__NR_exit, 0);
 	return 0;
 }
@@ -56,13 +51,16 @@ static int touch_tls_in_child(void *arg LTP_ATTRIBUTE_UNUSED)
 static void verify_tls(void)
 {
 	tls_var = TLS_EXP;
+	tst_atomic_store(0, &child_done);
 
 	TEST(ltp_clone7(flags, touch_tls_in_child, NULL, CHILD_STACK_SIZE, child_stack, NULL, tls_ptr, NULL));
 
 	if (TST_RET == -1)
 		tst_brk(TBROK | TTERRNO, "clone() failed");
 
-	TST_CHECKPOINT_WAIT(0);
+	while (tst_atomic_load(&child_done) == 0) {
+		usleep(10);
+	}
 
 	if (tls_var == TLS_EXP) {
 		tst_res(TPASS,
@@ -84,6 +82,7 @@ static void setup(void)
 static void cleanup(void)
 {
 	free(child_stack);
+	free_tls();
 }
 
 static struct tst_test test = {
-- 
2.43.0


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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-04  6:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-26 10:35 [LTP] [PATCH] clone10.c: avoid using the libc thread memory model in touch_tls_in_child() Changwei Zou via ltp
2026-02-26 11:11 ` Li Wang via ltp
2026-03-04  5:59 ` Li Wang via ltp
2026-03-04  6:13   ` Changwei Zou via ltp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox