Bug 2177235

Summary: glibc: system() erroneously block SIGCHLD forever when called concurrently
Product: Red Hat Enterprise Linux 9 Reporter: Arjun Shankar <ashankar>
Component: glibcAssignee: Florian Weimer <fweimer>
Status: VERIFIED --- QA Contact: Sergey Kolosov <skolosov>
Severity: unspecified Docs Contact: Jacob Taylor Valdez <jvaldez>
Priority: unspecified    
Version: 9.2CC: ashankar, ayi, codonell, cperl, dj, fweimer, glibc-bugzilla, jvaldez, markobri, pfrankli, qe-baseos-tools-bugs, sipoyare, skolosov
Target Milestone: rcKeywords: Bugfix, Patch, Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: glibc-2.34-67.el9 Doc Type: Bug Fix
Doc Text:
.The `glibc` `system()` function now restores the previous signal mask unconditionally Previously, if the `glibc` `system()` function was called concurrently from multiple threads, the signal mask for the `SIGCHLD` signal might not be restored correctly. As a consequence, the `SIGCHLD` signal remained blocked after the return from the `glibc` `system()` function on some threads. With this update, the `glibc` `system()` function now restores the previous signal mask unconditionally, even when parallel `system()` function calls are running. As a result, the `SIGCHLD` signal is no longer incorrectly blocked if the `glibc` `system()` function is called concurrently from multiple threads.
Story Points: ---
Clone Of: 2176707 Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2176707, 2188641    

Description Arjun Shankar 2023-03-10 14:17:32 UTC
+++ This bug was initially created as a clone of Bug #2176707 +++

We backported a buggy commit (5fb7fc96350575c9adb1316833e48ca11553be49) in bug 2065588 that landed in glibc-2.28-211.

Specifically, in the following scenario with two threads in the same process:

1. Thread A calls system but hasn't returned yet
2. Thread B calls another system but returns

I observed that SIGCHLD would be blocked forever in thread B after its system() returns, even after the system() in thread A returns (though I believe it should unblock it after system() in thread B returns). This was not the case before this patch.

I've attached a simple C reproduction program to this bug. It doesn't print anything on previously but prints "SIGCHLD is erroneously blocked" with glibc-2.28-211.

I filed this bug upstream (sourceware bug 30163) and this is fixed in upstream in 436a604b7dc741fc76b5a6704c6cd8bb178518e7. Can we backport the fix as well?

Comment 2 Florian Weimer 2023-04-28 11:19:48 UTC
Upstream fix:

commit 436a604b7dc741fc76b5a6704c6cd8bb178518e7
Author: Adam Yi <ayi>
Date:   Tue Mar 7 07:30:02 2023 -0500

    posix: Fix system blocks SIGCHLD erroneously [BZ #30163]
    
    Fix bug that SIGCHLD is erroneously blocked forever in the following
    scenario:
    
    1. Thread A calls system but hasn't returned yet
    2. Thread B calls another system but returns
    
    SIGCHLD would be blocked forever in thread B after its system() returns,
    even after the system() in thread A returns.
    
    Although POSIX does not require, glibc system implementation aims to be
    thread and cancellation safe. This bug was introduced in
    5fb7fc96350575c9adb1316833e48ca11553be49 when we moved reverting signal
    mask to happen when the last concurrently running system returns,
    despite that signal mask is per thread. This commit reverts this logic
    and adds a test.
    
    Signed-off-by: Adam Yi <ayi>
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella>

Comment 8 Jacob Taylor Valdez 2023-08-01 10:11:56 UTC
setting r_d_t