From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 31C883858D35; Mon, 22 Nov 2021 14:26:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 31C883858D35 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: sigproc: Fix potential race issue regarding exit_state. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 68faeef4be712df60443c6bb5764b1e9ddad20e2 X-Git-Newrev: a496c9cdf8735a878a646c69602bce1682340454 Message-Id: <20211122142621.31C883858D35@sourceware.org> Date: Mon, 22 Nov 2021 14:26:21 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Nov 2021 14:26:21 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=a496c9cdf8735a878a646c69602bce1682340454 commit a496c9cdf8735a878a646c69602bce1682340454 Author: Takashi Yano Date: Sat Nov 20 03:24:18 2021 +0900 Cygwin: sigproc: Fix potential race issue regarding exit_state. - If sig_send() is called while another thread is processing exit(), race issue regarding exit_state may occur. This patch fixes the issue. Diff: --- winsup/cygwin/sigproc.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 2441efc92..4d7d273ae 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -603,11 +603,6 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls) its_me = false; } - /* Do not send signal to myself if exiting, which will be - ignored in wait_sig thread. */ - if (its_me && exit_state > ES_EXIT_STARTING && si.si_signo > 0) - goto out; - if (its_me) sendsig = my_sendsig; else @@ -1352,7 +1347,7 @@ wait_sig (VOID *) sigq.retry = false; /* Don't process signals when we start exiting */ if (exit_state > ES_EXIT_STARTING && pack.si.si_signo > 0) - continue; + goto skip_process_signal; sigset_t dummy_mask; threadlist_t *tl_entry; @@ -1364,8 +1359,10 @@ wait_sig (VOID *) pack.mask = &dummy_mask; } - sigpacket *q = &sigq.start; - bool clearwait = false; + sigpacket *q; + q = &sigq.start; + bool clearwait; + clearwait = false; switch (pack.si.si_signo) { case __SIGCOMMUNE: @@ -1462,6 +1459,7 @@ wait_sig (VOID *) } if (clearwait && !have_execed) proc_subproc (PROC_CLEARWAIT, 0); +skip_process_signal: if (pack.wakeup) { sigproc_printf ("signalling pack.wakeup %p", pack.wakeup);