Commit-ID: c876eeab6432687846d4cd5fe1e43dbc348de134 Gitweb: http://git.kernel.org/tip/c876eeab6432687846d4cd5fe1e43dbc348de134 Author: Andy Lutomirski <l...@kernel.org> AuthorDate: Tue, 3 May 2016 10:31:49 -0700 Committer: Ingo Molnar <mi...@kernel.org> CommitDate: Wed, 4 May 2016 08:34:13 +0200
signals/sigaltstack: If SS_AUTODISARM, bypass on_sig_stack() If a signal stack is set up with SS_AUTODISARM, then the kernel inherently avoids incorrectly resetting the signal stack if signals recurse: the signal stack will be reset on the first signal delivery. This means that we don't need check the stack pointer when delivering signals if SS_AUTODISARM is set. This will make segmented x86 programs more robust: currently there's a hole that could be triggered if ESP/RSP appears to point to the signal stack but actually doesn't due to a nonzero SS base. Signed-off-by: Andy Lutomirski <l...@kernel.org> Cc: Al Viro <v...@zeniv.linux.org.uk> Cc: Aleksa Sarai <cyp...@cyphar.com> Cc: Amanieu d'Antras <aman...@gmail.com> Cc: Andrea Arcangeli <aarca...@redhat.com> Cc: Andrew Morton <a...@linux-foundation.org> Cc: Andy Lutomirski <l...@amacapital.net> Cc: Borislav Petkov <b...@alien8.de> Cc: Brian Gerst <brge...@gmail.com> Cc: Denys Vlasenko <dvlas...@redhat.com> Cc: Eric W. Biederman <ebied...@xmission.com> Cc: Frederic Weisbecker <fweis...@gmail.com> Cc: H. Peter Anvin <h...@zytor.com> Cc: Heinrich Schuchardt <xypron.g...@gmx.de> Cc: Jason Low <jason.l...@hp.com> Cc: Josh Triplett <j...@joshtriplett.org> Cc: Konstantin Khlebnikov <khlebni...@yandex-team.ru> Cc: Linus Torvalds <torva...@linux-foundation.org> Cc: Oleg Nesterov <o...@redhat.com> Cc: Palmer Dabbelt <pal...@dabbelt.com> Cc: Paul Moore <pmo...@redhat.com> Cc: Pavel Emelyanov <xe...@parallels.com> Cc: Peter Zijlstra <pet...@infradead.org> Cc: Richard Weinberger <rich...@nod.at> Cc: Sasha Levin <sasha.le...@oracle.com> Cc: Shuah Khan <shua...@osg.samsung.com> Cc: Stas Sergeev <s...@list.ru> Cc: Tejun Heo <t...@kernel.org> Cc: Thomas Gleixner <t...@linutronix.de> Cc: Vladimir Davydov <vdavy...@parallels.com> Cc: linux-...@vger.kernel.org Link: http://lkml.kernel.org/r/c46bee4654ca9e68c498462fd11746e2bd0d98c8.1462296606.git.l...@kernel.org Signed-off-by: Ingo Molnar <mi...@kernel.org> --- include/linux/sched.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index 2950c5c..77fd49f 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2576,6 +2576,18 @@ static inline int kill_cad_pid(int sig, int priv) */ static inline int on_sig_stack(unsigned long sp) { + /* + * If the signal stack is SS_AUTODISARM then, by construction, we + * can't be on the signal stack unless user code deliberately set + * SS_AUTODISARM when we were already on it. + * + * This improves reliability: if user state gets corrupted such that + * the stack pointer points very close to the end of the signal stack, + * then this check will enable the signal to be handled anyway. + */ + if (current->sas_ss_flags & SS_AUTODISARM) + return 0; + #ifdef CONFIG_STACK_GROWSUP return sp >= current->sas_ss_sp && sp - current->sas_ss_sp < current->sas_ss_size;