diff options
author | Sebastian Andrzej Siewior <sebastian@breakpoint.cc> | 2009-10-25 10:37:58 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2009-11-04 12:19:12 -0500 |
commit | 2a855dd01bc1539111adb7233f587c5c468732ac (patch) | |
tree | 4ceb2f997ab5ef2830eb91ee8414110bf70cb20b /include/linux/sched.h | |
parent | 51bb296b09a83ee1aae025778db38f9d2cc7bb1a (diff) |
signal: Fix alternate signal stack check
All architectures in the kernel increment/decrement the stack pointer
before storing values on the stack.
On architectures which have the stack grow down sas_ss_sp == sp is not
on the alternate signal stack while sas_ss_sp + sas_ss_size == sp is
on the alternate signal stack.
On architectures which have the stack grow up sas_ss_sp == sp is on
the alternate signal stack while sas_ss_sp + sas_ss_size == sp is not
on the alternate signal stack.
The current implementation fails for architectures which have the
stack grow down on the corner case where sas_ss_sp == sp.This was
reported as Debian bug #544905 on AMD64.
Simplified test case: http://download.breakpoint.cc/tc-sig-stack.c
The test case creates the following stack scenario:
0xn0300 stack top
0xn0200 alt stack pointer top (when switching to alt stack)
0xn01ff alt stack end
0xn0100 alt stack start == stack pointer
If the signal is sent the stack pointer is pointing to the base
address of the alt stack and the kernel erroneously decides that it
has already switched to the alternate stack because of the current
check for "sp - sas_ss_sp < sas_ss_size"
On parisc (stack grows up) the scenario would be:
0xn0200 stack pointer
0xn01ff alt stack end
0xn0100 alt stack start = alt stack pointer base
(when switching to alt stack)
0xn0000 stack base
This is handled correctly by the current implementation.
[ tglx: Modified for archs which have the stack grow up (parisc) which
would fail with the correct implementation for stack grows
down. Added a check for sp >= current->sas_ss_sp which is
strictly not necessary but makes the code symetric for both
variants ]
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Roland McGrath <roland@redhat.com>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Cc: stable@kernel.org
LKML-Reference: <20091025143758.GA6653@Chamillionaire.breakpoint.cc>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'include/linux/sched.h')
-rw-r--r-- | include/linux/sched.h | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h index 75e6e60bf583..0f67914a43c9 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -2086,11 +2086,18 @@ static inline int is_si_special(const struct siginfo *info) | |||
2086 | return info <= SEND_SIG_FORCED; | 2086 | return info <= SEND_SIG_FORCED; |
2087 | } | 2087 | } |
2088 | 2088 | ||
2089 | /* True if we are on the alternate signal stack. */ | 2089 | /* |
2090 | 2090 | * True if we are on the alternate signal stack. | |
2091 | */ | ||
2091 | static inline int on_sig_stack(unsigned long sp) | 2092 | static inline int on_sig_stack(unsigned long sp) |
2092 | { | 2093 | { |
2093 | return (sp - current->sas_ss_sp < current->sas_ss_size); | 2094 | #ifdef CONFIG_STACK_GROWSUP |
2095 | return sp >= current->sas_ss_sp && | ||
2096 | sp - current->sas_ss_sp < current->sas_ss_size; | ||
2097 | #else | ||
2098 | return sp > current->sas_ss_sp && | ||
2099 | sp - current->sas_ss_sp <= current->sas_ss_size; | ||
2100 | #endif | ||
2094 | } | 2101 | } |
2095 | 2102 | ||
2096 | static inline int sas_ss_flags(unsigned long sp) | 2103 | static inline int sas_ss_flags(unsigned long sp) |