You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Yang Chung Fan <so...@gmail.com> on 2020/02/28 06:01:15 UTC
Possibility of nested signals.
Hi,
I noticed that both the armv7m and x86 port of nuttx's signal sending
procedure cannot handle nested signals.
I am wondering that in the up_sigdeliver functions.
A task A, being signaled, is possibile to be switch-out because of
1. calling syslog via sinfo
2. interrupts
A newly switched in task might send a second signal to the task A.
In such case, the saved instruction pointer value in the TCB might get
overwritten, causing a consecutive incorrect execution path when
returning tho the previous signal.
Am I correct or did I missed something here?
--
Yang Chung Fan (楊宗凡) (ヤン ゾン ファン)
Member of Softlab, Tsukuba University , Japan
Email: sonic.tw.tp@gmail.com
Re: Possibility of nested signals.
Posted by Yang Chung Fan <so...@gmail.com>.
Hi Greg,
>
> Where do you see a problem in this?
>
I found that 2 tasks can race calling up_schedule_sigaction to set the
sigdeliver in TCB.
In up_schedule_sigaction , a critical section should prevent this from
happening.
However, If the calling task suspends voluntary, e.g. by calling
syslog, another task can enter the critical section and race with the
other task.
The first task moves the RIP in register profile to the TCB and set
the RIP in register profile as sigdeliver.
The second task moves the RIP in register profile (which is sigdeliver
now) to the TCB and set the RIP in register profile as again
sigdeliver.
The original RIP saved in TCB is overwritten and destroyed.
Currently, by removing any possibility voluntary schedule point in the
critical section, this problem no longer exists.
--
Yang Chung Fan (楊宗凡) (ヤン ゾン ファン)
Member of Softlab, Tsukuba University , Japan
Email: sonic.tw.tp@gmail.com
Re: Possibility of nested signals.
Posted by Gregory Nutt <sp...@gmail.com>.
Hi,
> I noticed that both the armv7m and x86 port of nuttx's signal sending
> procedure cannot handle nested signals.
>
> I am wondering that in the up_sigdeliver functions.
> A task A, being signaled, is possibile to be switch-out because of
> 1. calling syslog via sinfo
> 2. interrupts
>
> A newly switched in task might send a second signal to the task A.
> In such case, the saved instruction pointer value in the TCB might get
> overwritten, causing a consecutive incorrect execution path when
> returning tho the previous signal.
>
> Am I correct or did I missed something here?
Nest edsignals should not be possible even if the task is suspended.
Signal delivery is managed by sched/signal/sig_deliver.c. An overview
would be like:
Line 77:
/* Loop while there are signals to be delivered */
for (; ; )
{
/* Test if this task is already handling a signal (we don't
permit
* nested signals on the same thread).
*/
flags = enter_critical_section();
if ((stcb->flags & TCB_FLAG_SIGNAL_ACTION) != 0)
{
/* Yes.. then we must wait for the signal handler to
return */
leave_critical_section(flags);
break;
}
Line 105:
/* Indicate that a signal is being delivered */
stcb->flags |= TCB_FLAG_SIGNAL_ACTION;
The the signal is processed outside of the critical section. If the
signal handler is suspended while processing, then
TCB_FLAG_SIGNAL_ACTION will be set and if nxsig_deliver is called again
to deliver a signal to this same task, it will return with doing anything.
When the signal handler returns, we will be back within the critical
section and cannot be suspended. Then at line 193:
stcb->flags &= ~TCB_FLAG_SIGNAL_ACTION;
Then it loops to try the next signal.
Where do you see a problem in this?
Greg