bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Possible race condition in bash


From: Nikolay Borisov
Subject: Re: Possible race condition in bash
Date: Sat, 21 Nov 2020 21:29:24 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0


On 21.11.20 г. 20:50 ч., Chet Ramey wrote:
> On 11/21/20 1:35 PM, Nikolay Borisov wrote:
> 
>> I can see setting of SIGTERM handler for both 2 subshells _after_ receiving 
>> the signal. What exactly should I be looking at?
> 
> That's your race condition.
> 

So the kernel initializes the signal struct of the child in copy_sighand which 
does: 


memcpy(sig->action, current->sighand->action, sizeof(sig->action));

At this point the child has the same handlers as the ones in the parent. 
As per the posix deifnition of how the environment is initialized those signals 
shall be restored to SIG_DFL. HOwever I can see that the signals are being 
delivered 
to the children _before_ they reset signals to SIG_DFL: 

12394 --- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=12392, si_uid=0} 
---
12393 --- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=12392, si_uid=0} 
---

 <ommitted for brevity>
12394 rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], 
sa_flags=SA_RESTORER, sa_restorer=0x7f8c881fdfd0},             <unfinished ...>
12393 rt_sigprocmask(SIG_SETMASK, [],  <unfinished ...>                         
12394 <... rt_sigaction resumed> {sa_handler=SIG_DFL, sa_mask=[], 
sa_flags=SA_RESTORER, sa_restorer=0x7f8c881fdfd0}, 8) = 0
12393 <... rt_sigprocmask resumed> NULL, 8) = 0                                 
12394 rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], 
sa_flags=SA_RESTORER, sa_restorer=0x7f8c881fdfd0},             <unfinished ...>
12393 rt_sigaction(SIGTSTP, {sa_handler=SIG_DFL, sa_mask=[], 
sa_flags=SA_RESTORER, sa_restorer=0x7f8c881fdfd0},             <unfinished ...>
12394 <... rt_sigaction resumed> {sa_handler=SIG_DFL, sa_mask=[], 
sa_flags=SA_RESTORER, sa_restorer=0x7f8c881fdfd0}, 8) = 0
12393 <... rt_sigaction resumed> {sa_handler=SIG_DFL, sa_mask=[], 
sa_flags=SA_RESTORER, sa_restorer=0x7f8c881fdfd0}, 8) = 0
12394 rt_sigaction(SIGTTOU, {sa_handler=SIG_DFL, sa_mask=[], 
sa_flags=SA_RESTORER, sa_restorer=0x7f8c881fdfd0},             <unfinished ...>
12393 rt_sigaction(SIGTTIN, {sa_handler=SIG_DFL, sa_mask=[], 
sa_flags=SA_RESTORER, sa_restorer=0x7f8c881fdfd0},             <unfinished ...>
12394 <... rt_sigaction resumed> {sa_handler=SIG_DFL, sa_mask=[], 
sa_flags=SA_RESTORER, sa_restorer=0x7f8c881fdfd0}, 8) = 0
12393 <... rt_sigaction resumed> {sa_handler=SIG_DFL, sa_mask=[], 
sa_flags=SA_RESTORER, sa_restorer=0x7f8c881fdfd0}, 8) = 0
12394 rt_sigaction(SIGHUP, {sa_handler=0x55b5e4479d80, sa_mask=[], 
sa_flags=SA_RESTORER, sa_restorer=0x7f8c881fdfd0},       <unfinished ...>
12393 rt_sigaction(SIGTTOU, {sa_handler=SIG_DFL, sa_mask=[], 
sa_flags=SA_RESTORER, sa_restorer=0x7f8c881fdfd0},             <unfinished ...>
12394 <... rt_sigaction resumed> {sa_handler=0x55b5e4476400, sa_mask=[], 
sa_flags=SA_RESTORER, sa_restorer=0x7f8c881fdfd0}, 8) = 0
12393 <... rt_sigaction resumed> {sa_handler=SIG_DFL, sa_mask=[], 
sa_flags=SA_RESTORER, sa_restorer=0x7f8c881fdfd0}, 8) = 0
12394 rt_sigaction(SIGINT, {sa_handler=SIG_DFL, sa_mask=[], 
sa_flags=SA_RESTORER, sa_restorer=0x7f8c881fdfd0},              
{sa_handler=0x55b5e4476400, sa_mask=[], sa_flags=SA_RESTORER, 
sa_restorer=0x7f8c881fdfd0}, 8) = 0
12394 rt_sigaction(SIGQUIT, {sa_handler=SIG_DFL, sa_mask=[], 
sa_flags=SA_RESTORER, sa_restorer=0x7f8c881fdfd0},             <unfinished ...>
<ommitted for brevity>


So shouldn't the child execute the trap of the parent in this case?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]