Re: [PATCH -mm 0/1] signal: simplify set_user_sigmask/restore_user_sigmask

From: Oleg Nesterov
Date: Thu Jun 06 2019 - 06:26:30 EST


On 06/05, Linus Torvalds wrote:
>
> On Wed, Jun 5, 2019 at 8:58 AM Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
> >
> > To simplify the review, please see the code with this patch applied.
> > I am using epoll_pwait() as an example because it looks very simple.
>
> I like it.
>
> However.
>
> I think I'd like it even more if we just said "we don't need
> restore_saved_sigmask AT ALL".
^^^^^^^^^^^^^^^^^^^^^

Did you mean restore_saved_sigmask_unless() introduced by this patch?

If yes:

> Which would be fairly easy to do with something like the attached...

I don't think so,

> --- a/arch/x86/entry/common.c
> +++ b/arch/x86/entry/common.c
> @@ -160,7 +160,7 @@ static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags)
> klp_update_patch_state(current);
>
> /* deal with pending signal delivery */
> - if (cached_flags & _TIF_SIGPENDING)
> + if (cached_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
> do_signal(regs);

...

> --- a/kernel/signal.c
> +++ b/kernel/signal.c
> @@ -2877,6 +2877,7 @@ int set_user_sigmask(const sigset_t __user *usigmask, sigset_t *set,
>
> *oldset = current->blocked;
> set_current_blocked(set);
> + set_thread_flag(TIF_RESTORE_SIGMASK);

This will re-introduce the problem fixed by the previous patch.

Yes, do_signal() does restore_saved_sigmask() at the end, but only if
get_signal() returns false.

This means that restore_saved_sigmask()->set_current_blocked(saved_mask) should
restore ->blocked (and may be clear TIF_SIGPENDING) before ret-from-syscall.

Or I misunderstood?

Oleg.