Skip to content

Commit 0000b3c

Browse files
committed
Block SIGCHLD before booting LKL
Before all kernel threads are created, we have to block SIGCHLD and let all childs inherit the blocked mask. Without this, SIGCHLD (from the supervised child process exiting) may be delivered to an LKL thread where the default ignore action silently discards it, causing the signalfd in the supervisor poll loop to never become readable. Change-Id: Ib3256f044c5b8ce9c34c223beb294c207a1f47ab
1 parent 26de02c commit 0000b3c

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/lkl-wrap.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* SPDX-License-Identifier: MIT */
22

3+
#include <pthread.h>
4+
#include <signal.h>
35
#include <stdio.h>
46
#include <string.h>
57

@@ -21,6 +23,14 @@ int kbox_boot_kernel(const char *cmdline)
2123
const char *effective = cmdline;
2224
char buf[512];
2325
int ret;
26+
sigset_t mask;
27+
28+
/* Block SIGCHLD before booting LKL so that all kernel threads created
29+
* by lkl_start_kernel inherit the blocked mask.
30+
*/
31+
sigemptyset(&mask);
32+
sigaddset(&mask, SIGCHLD);
33+
pthread_sigmask(SIG_BLOCK, &mask, NULL);
2434

2535
if (!cmdline || !*cmdline) {
2636
effective = "console=null";

src/seccomp-supervisor.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -492,16 +492,12 @@ int kbox_run_supervisor(const struct kbox_sysnrs *sysnrs,
492492
if (socketpair_create(sp) < 0)
493493
return -1;
494494

495-
/* Block SIGCHLD before fork so the parent cannot lose the signal
496-
* in the window between fork and signalfd creation. Save the
497-
* caller's mask so both parent and child can restore it later.
495+
/* Save the caller's mask so both parent and child can
496+
* restore it later.
498497
*/
499498
{
500-
sigset_t chld_mask;
501-
sigemptyset(&chld_mask);
502-
sigaddset(&chld_mask, SIGCHLD);
503-
if (sigprocmask(SIG_BLOCK, &chld_mask, &old_mask) < 0) {
504-
fprintf(stderr, "sigprocmask(SIG_BLOCK): %s\n", strerror(errno));
499+
if (sigprocmask(SIG_SETMASK, NULL, &old_mask) < 0) {
500+
fprintf(stderr, "sigprocmask(SIG_SETMASK): %s\n", strerror(errno));
505501
close(sp[0]);
506502
close(sp[1]);
507503
return -1;

0 commit comments

Comments
 (0)