From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stas Sergeev Subject: Re: [PATCH 4/4] sigaltstack: allow disabling and re-enabling sas within sighandler Date: Mon, 1 Feb 2016 22:46:12 +0300 Message-ID: <56AFB604.4010008@list.ru> References: <56AE3369.2090709@list.ru> <56AE3626.7080706@list.ru> <20160201160625.GA18276@redhat.com> <20160201170958.GA20735@redhat.com> <56AF955D.7060601@list.ru> <20160201180443.GA21064@redhat.com> <56AFA0E2.1030302@list.ru> <20160201185223.GA21136@redhat.com> <56AFAB9D.4070007@list.ru> <20160201192936.GA21214@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: In-Reply-To: <20160201192936.GA21214-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> Sender: linux-api-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Oleg Nesterov Cc: Linux kernel , linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Andy Lutomirski , Ingo Molnar , Peter Zijlstra , Andrew Morton , Amanieu d'Antras , Richard Weinberger , Tejun Heo , "Kirill A. Shutemov" , Jason Low , Heinrich Schuchardt , Andrea Arcangeli , Konstantin Khlebnikov , Josh Triplett , "Eric W. Biederman" , Aleksa Sarai , Paul Moore , Palmer Dabbelt , Vladimir Davydov List-Id: linux-api@vger.kernel.org 01.02.2016 22:29, Oleg Nesterov =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > On 02/01, Stas Sergeev wrote: >> 01.02.2016 21:52, Oleg Nesterov =D0=BF=D0=B8=D1=88=D0=B5=D1=82: >>> Stas, I probably missed something, but I don't understand your conc= erns, >>> >>> On 02/01, Stas Sergeev wrote: >>>> 01.02.2016 21:04, Oleg Nesterov =D0=BF=D0=B8=D1=88=D0=B5=D1=82: >>>>> Yes, and SS_FORCE means "I know what I do", looks very simple. >>>> But to me its not because I don't know what to do with >>>> uc_stack after SS_FORCE is applied. >>> Nothing? restore_sigaltstack() should work as expected? >> That's likely the reason for EPERM: restore_sigaltstack() >> does the job, so manual modifications are disallowed. >> Allowing them will bring in the surprises where the changes >> done by the user are ignored. > Unlikely. Suppose you do sigalstack() and then a non SA_ONSTACK signa= l handler > runs and calls sigaltstack() again. This won't fail, but restore_siga= ltstack() > will restore the old alt stack after return. OK. > I too do not know why uc_stack exists, in fact I do not know about it= until > today when I read your patch ;) But it is here, and I do not think SS= _FORCE > can add more confusion than we already have. OK. >>> Yes, or >>> >>> sigaltstack({ DISABLE | FORCE}, &old_ss); >>> swapcontext(); >>> sigaltstack(&old_ss, NULL); >>> rt_sigreturn(); >>> >>> and if you are going to return from sighandler you do not even need= the 2nd >>> sigaltstack(), you can rely on sigreturn. >> Yes, that's what I do in my app already. >> But its only there when SA_SIGINFO is used. > Hmm. how this connects to SA_SIGINFO ? AFAIK without SA_SIGINFO you get sigreturn instead of rt_sigreturn, which doesn't seem to do restore_altstack(). Or am I wrong? Hmm: /* Set up the stack frame */ if (is_ia32_frame()) { if (ksig->ka.sa.sa_flags & SA_SIGINFO) return ia32_setup_rt_frame(usig, ksig, cset, r= egs); else return ia32_setup_frame(usig, ksig, cset, regs= ); } else if (is_x32_frame()) { return x32_setup_rt_frame(ksig, cset, regs); } else { return __setup_rt_frame(ksig->sig, ksig, set, regs); } >>>> What's at the end? Do we want a surprise for the user >>>> that he's new_sas got ignored? >>> Can't understand.... do you mean "set up new_sas" will be ignored b= ecause >>> rt_sigreturn() does restore_sigaltstack() ? I see no problem here..= =2E >> Allowing the modifications that were previously EPERMed >> but will now be silently ignored, may be seen as a problem. >> But if it isn't - fine, lets code that. > Still can't understand. The 2nd sigaltstack() is no longer EPERMed be= cause > application used SS_FORCED before that and disabled altstack. > > And it is not ignored, it actually changes alt stack. Until we return= from > handler. Before we return, the signals are usually blocked. So whatever is after return is most important. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932096AbcBATqf (ORCPT ); Mon, 1 Feb 2016 14:46:35 -0500 Received: from smtp45.i.mail.ru ([94.100.177.105]:42598 "EHLO smtp45.i.mail.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753294AbcBATqd (ORCPT ); Mon, 1 Feb 2016 14:46:33 -0500 Subject: Re: [PATCH 4/4] sigaltstack: allow disabling and re-enabling sas within sighandler To: Oleg Nesterov References: <56AE3369.2090709@list.ru> <56AE3626.7080706@list.ru> <20160201160625.GA18276@redhat.com> <20160201170958.GA20735@redhat.com> <56AF955D.7060601@list.ru> <20160201180443.GA21064@redhat.com> <56AFA0E2.1030302@list.ru> <20160201185223.GA21136@redhat.com> <56AFAB9D.4070007@list.ru> <20160201192936.GA21214@redhat.com> Cc: Linux kernel , linux-api@vger.kernel.org, Andy Lutomirski , Ingo Molnar , Peter Zijlstra , Andrew Morton , "Amanieu d'Antras" , Richard Weinberger , Tejun Heo , "Kirill A. Shutemov" , Jason Low , Heinrich Schuchardt , Andrea Arcangeli , Konstantin Khlebnikov , Josh Triplett , "Eric W. Biederman" , Aleksa Sarai , Paul Moore , Palmer Dabbelt , Vladimir Davydov From: Stas Sergeev Message-ID: <56AFB604.4010008@list.ru> Date: Mon, 1 Feb 2016 22:46:12 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: <20160201192936.GA21214@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Mras: Ok Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 01.02.2016 22:29, Oleg Nesterov пишет: > On 02/01, Stas Sergeev wrote: >> 01.02.2016 21:52, Oleg Nesterov пишет: >>> Stas, I probably missed something, but I don't understand your concerns, >>> >>> On 02/01, Stas Sergeev wrote: >>>> 01.02.2016 21:04, Oleg Nesterov пишет: >>>>> Yes, and SS_FORCE means "I know what I do", looks very simple. >>>> But to me its not because I don't know what to do with >>>> uc_stack after SS_FORCE is applied. >>> Nothing? restore_sigaltstack() should work as expected? >> That's likely the reason for EPERM: restore_sigaltstack() >> does the job, so manual modifications are disallowed. >> Allowing them will bring in the surprises where the changes >> done by the user are ignored. > Unlikely. Suppose you do sigalstack() and then a non SA_ONSTACK signal handler > runs and calls sigaltstack() again. This won't fail, but restore_sigaltstack() > will restore the old alt stack after return. OK. > I too do not know why uc_stack exists, in fact I do not know about it until > today when I read your patch ;) But it is here, and I do not think SS_FORCE > can add more confusion than we already have. OK. >>> Yes, or >>> >>> sigaltstack({ DISABLE | FORCE}, &old_ss); >>> swapcontext(); >>> sigaltstack(&old_ss, NULL); >>> rt_sigreturn(); >>> >>> and if you are going to return from sighandler you do not even need the 2nd >>> sigaltstack(), you can rely on sigreturn. >> Yes, that's what I do in my app already. >> But its only there when SA_SIGINFO is used. > Hmm. how this connects to SA_SIGINFO ? AFAIK without SA_SIGINFO you get sigreturn instead of rt_sigreturn, which doesn't seem to do restore_altstack(). Or am I wrong? Hmm: /* Set up the stack frame */ if (is_ia32_frame()) { if (ksig->ka.sa.sa_flags & SA_SIGINFO) return ia32_setup_rt_frame(usig, ksig, cset, regs); else return ia32_setup_frame(usig, ksig, cset, regs); } else if (is_x32_frame()) { return x32_setup_rt_frame(ksig, cset, regs); } else { return __setup_rt_frame(ksig->sig, ksig, set, regs); } >>>> What's at the end? Do we want a surprise for the user >>>> that he's new_sas got ignored? >>> Can't understand.... do you mean "set up new_sas" will be ignored because >>> rt_sigreturn() does restore_sigaltstack() ? I see no problem here... >> Allowing the modifications that were previously EPERMed >> but will now be silently ignored, may be seen as a problem. >> But if it isn't - fine, lets code that. > Still can't understand. The 2nd sigaltstack() is no longer EPERMed because > application used SS_FORCED before that and disabled altstack. > > And it is not ignored, it actually changes alt stack. Until we return from > handler. Before we return, the signals are usually blocked. So whatever is after return is most important.