Message ID | 87ldze7ji1.fsf@oldenburg.str.redhat.com |
---|---|
State | New |
Headers | show |
Series | Linux: Block signals around _Fork (bug 32215) | expand |
On 26/09/24 08:16, Florian Weimer wrote: > This hides the inconsistent TCB state (missing robust mutx list) from > signal handlers. > > Tested on i686-linux-gnu and x86_64-linux-gnu. LGTM, thanks. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> > > --- > sysdeps/nptl/_Fork.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/sysdeps/nptl/_Fork.c b/sysdeps/nptl/_Fork.c > index ef199ddbc3..fd2cfc7840 100644 > --- a/sysdeps/nptl/_Fork.c > +++ b/sysdeps/nptl/_Fork.c > @@ -22,6 +22,11 @@ > pid_t > _Fork (void) > { > + /* Block all signals to avoid revealing the inconsistent TCB state > + to a signal handler after fork. */ > + internal_sigset_t original_sigmask; > + internal_signal_block_all (&original_sigmask); > + > pid_t pid = arch_fork (&THREAD_SELF->tid); > if (pid == 0) > { > @@ -44,6 +49,8 @@ _Fork (void) > INTERNAL_SYSCALL_CALL (set_robust_list, &self->robust_head, > sizeof (struct robust_list_head)); > } > + > + internal_signal_restore_set (&original_sigmask); > return pid; > } > libc_hidden_def (_Fork) > > base-commit: cc84cd389c7329ceb38228f931044e8c84ca7245 >
diff --git a/sysdeps/nptl/_Fork.c b/sysdeps/nptl/_Fork.c index ef199ddbc3..fd2cfc7840 100644 --- a/sysdeps/nptl/_Fork.c +++ b/sysdeps/nptl/_Fork.c @@ -22,6 +22,11 @@ pid_t _Fork (void) { + /* Block all signals to avoid revealing the inconsistent TCB state + to a signal handler after fork. */ + internal_sigset_t original_sigmask; + internal_signal_block_all (&original_sigmask); + pid_t pid = arch_fork (&THREAD_SELF->tid); if (pid == 0) { @@ -44,6 +49,8 @@ _Fork (void) INTERNAL_SYSCALL_CALL (set_robust_list, &self->robust_head, sizeof (struct robust_list_head)); } + + internal_signal_restore_set (&original_sigmask); return pid; } libc_hidden_def (_Fork)