mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
selftests/namespaces: Fix waitpid race in listns_efault_test cleanup
The efault tests spawn two categories of child processes: namespace children (each in its own mount namespace, for concurrent destruction) and an iterator child that calls listns() in a tight loop. The cleanup loop used waitpid(-1), which reaps any child in any order. If the iterator child exits early (e.g. because listns() returned ENOSYS) before all namespace children have been reaped, waitpid(-1) may consume it instead. The subsequent targeted waitpid(iter_pid) would then block indefinitely. Track the PIDs of the namespace children explicitly and use targeted waitpid() calls in the cleanup loop so the iterator child cannot be inadvertently reaped during namespace cleanup. Signed-off-by: Ricardo B. Marlière <rbm@suse.com> Link: https://patch.msgid.link/20260407-selftests-namespaces_fixes-v1-2-59109909d88b@suse.com Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
fdb48976b6
commit
f36ddf9317
|
|
@ -38,7 +38,7 @@ TEST(listns_partial_fault_with_ns_cleanup)
|
|||
__u64 *ns_ids;
|
||||
ssize_t ret;
|
||||
long page_size;
|
||||
pid_t pid, iter_pid;
|
||||
pid_t pid, iter_pid, ns_pids[5];
|
||||
int pidfds[5];
|
||||
int sv[5][2];
|
||||
int iter_pidfd;
|
||||
|
|
@ -114,6 +114,7 @@ TEST(listns_partial_fault_with_ns_cleanup)
|
|||
|
||||
pid = create_child(&pidfds[i], CLONE_NEWNS);
|
||||
ASSERT_NE(pid, -1);
|
||||
ns_pids[i] = pid;
|
||||
|
||||
if (pid == 0) {
|
||||
close(sv[i][0]); /* Close parent end */
|
||||
|
|
@ -164,7 +165,7 @@ TEST(listns_partial_fault_with_ns_cleanup)
|
|||
|
||||
/* Wait for all mount namespace children to exit and cleanup */
|
||||
for (i = 0; i < 5; i++) {
|
||||
waitpid(-1, NULL, 0);
|
||||
waitpid(ns_pids[i], NULL, 0);
|
||||
close(sv[i][0]);
|
||||
close(pidfds[i]);
|
||||
}
|
||||
|
|
@ -250,7 +251,7 @@ TEST(listns_late_fault_with_ns_cleanup)
|
|||
__u64 *ns_ids;
|
||||
ssize_t ret;
|
||||
long page_size;
|
||||
pid_t pid, iter_pid;
|
||||
pid_t pid, iter_pid, ns_pids[10];
|
||||
int pidfds[10];
|
||||
int sv[10][2];
|
||||
int iter_pidfd;
|
||||
|
|
@ -320,6 +321,7 @@ TEST(listns_late_fault_with_ns_cleanup)
|
|||
|
||||
pid = create_child(&pidfds[i], CLONE_NEWNS);
|
||||
ASSERT_NE(pid, -1);
|
||||
ns_pids[i] = pid;
|
||||
|
||||
if (pid == 0) {
|
||||
close(sv[i][0]); /* Close parent end */
|
||||
|
|
@ -373,7 +375,7 @@ TEST(listns_late_fault_with_ns_cleanup)
|
|||
|
||||
/* Wait for all children and cleanup */
|
||||
for (i = 0; i < 10; i++) {
|
||||
waitpid(-1, NULL, 0);
|
||||
waitpid(ns_pids[i], NULL, 0);
|
||||
close(sv[i][0]);
|
||||
close(pidfds[i]);
|
||||
}
|
||||
|
|
@ -402,7 +404,7 @@ TEST(listns_mnt_ns_cleanup_on_fault)
|
|||
__u64 *ns_ids;
|
||||
ssize_t ret;
|
||||
long page_size;
|
||||
pid_t pid, iter_pid;
|
||||
pid_t pid, iter_pid, ns_pids[8];
|
||||
int pidfds[8];
|
||||
int sv[8][2];
|
||||
int iter_pidfd;
|
||||
|
|
@ -462,6 +464,7 @@ TEST(listns_mnt_ns_cleanup_on_fault)
|
|||
|
||||
pid = create_child(&pidfds[i], CLONE_NEWNS);
|
||||
ASSERT_NE(pid, -1);
|
||||
ns_pids[i] = pid;
|
||||
|
||||
if (pid == 0) {
|
||||
close(sv[i][0]); /* Close parent end */
|
||||
|
|
@ -508,7 +511,7 @@ TEST(listns_mnt_ns_cleanup_on_fault)
|
|||
|
||||
/* Wait for children and cleanup */
|
||||
for (i = 0; i < 8; i++) {
|
||||
waitpid(-1, NULL, 0);
|
||||
waitpid(ns_pids[i], NULL, 0);
|
||||
close(sv[i][0]);
|
||||
close(pidfds[i]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user