Skip to contentSkip to conversation

syscalls/clone301: Fix race between parent and child

PATCH New Cyril Hrubis 2 participants 2 messages Mar 31, 2020 – Apr 1, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 syscalls/clone301: Fix race between parent and child

The signal handler has to be set up before we clone() the child, otherwise the signal may be lost if the child manages to call exit() before parent is able to continue.

---
 testcases/kernel/syscalls/clone3/clone301.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/clone3/clone301.c +3 -3
index f6d5c5dda..456291b67 100644
@@ -103,12 +103,12 @@ static void run(unsigned int n)
 		return;
 	}
 
-	if (!pid)
-		do_child(clone_pidfd, n);
-
 	parent_received_signal = 0;
 	SAFE_SIGACTION(tc->exit_signal, &psig_action, NULL);
 
+	if (!pid)
+		do_child(clone_pidfd, n);
+
 	/* Need to send signal to child process */
 	if (clone_pidfd) {
 		TST_CHECKPOINT_WAIT(0);
Signature · 1 line
2.24.1
#1 lore raw

PATCH 1/1 syscalls/clone301: Fix race between parent and child

Hello,

Quoted 20 lines · Cyril Hrubis

The signal handler has to be set up before we clone() the child, otherwise the signal may be lost if the child manages to call exit() before parent is able to continue.

---
 testcases/kernel/syscalls/clone3/clone301.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/clone3/clone301.c +0 -2
index f6d5c5dda..456291b67 100644
@@ -103,12 +103,12 @@ static void run(unsigned int n)
 		return;
 	}
 
-	if (!pid)
-		do_child(clone_pidfd, n);

testcases/kernel/syscalls/clone3/clone301.c static void run(unsigned int n) · line 114

Quoted 10 lines
testcases/kernel/syscalls/clone3/clone301.c +3 -1
-
 	parent_received_signal = 0;
 	SAFE_SIGACTION(tc->exit_signal, &psig_action, NULL);
 
+	if (!pid)
+		do_child(clone_pidfd, n);
+
 	/* Need to send signal to child process */
 	if (clone_pidfd) {
 		TST_CHECKPOINT_WAIT(0);

LGTM

Signature · 2 lines
Thank you,
Richard.