提交 d09042da 编写于 作者: L Laurent MEYER 提交者: Linus Torvalds

[PATCH] fix incorrect SA_ONSTACK behaviour for 64-bit processes

- When setting a sighandler using sigaction() call, if the flag
  SA_ONSTACK is set and no alternate stack is provided via sigaltstack(),
  the kernel still try to install the alternate stack.  This behavior is
  the opposite of the one which is documented in Single Unix Specifications
  V3.

- Also when setting an alternate stack using sigaltstack() with the flag
  SS_DISABLE, the kernel try to install the alternate stack on signal
  delivery.

These two use cases makes the process crash at signal delivery.
Signed-off-by: NLaurent Meyer <meyerlau@fr.ibm.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: David Howells <dhowells@redhat.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Roman Zippel <zippel@linux-m68k.org>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Cc: Paul Mundt <lethal@linux-sh.org>
Cc: Kazumoto Kojima <kkojima@rr.iij4u.or.jp>
Cc: Chris Zankel <chris@zankel.net>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 785d5570
...@@ -375,7 +375,7 @@ do_rt_sigreturn(struct rt_sigframe __user *frame, struct pt_regs *regs, ...@@ -375,7 +375,7 @@ do_rt_sigreturn(struct rt_sigframe __user *frame, struct pt_regs *regs,
static inline void __user * static inline void __user *
get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size) get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
{ {
if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! on_sig_stack(sp)) if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! sas_ss_flags(sp))
sp = current->sas_ss_sp + current->sas_ss_size; sp = current->sas_ss_sp + current->sas_ss_size;
return (void __user *)((sp - frame_size) & -32ul); return (void __user *)((sp - frame_size) & -32ul);
......
...@@ -233,7 +233,7 @@ static inline void __user *get_sigframe(struct k_sigaction *ka, ...@@ -233,7 +233,7 @@ static inline void __user *get_sigframe(struct k_sigaction *ka,
/* This is the X/Open sanctioned signal stack switching. */ /* This is the X/Open sanctioned signal stack switching. */
if (ka->sa.sa_flags & SA_ONSTACK) { if (ka->sa.sa_flags & SA_ONSTACK) {
if (! on_sig_stack(sp)) if (! sas_ss_flags(sp))
sp = current->sas_ss_sp + current->sas_ss_size; sp = current->sas_ss_sp + current->sas_ss_size;
} }
......
...@@ -307,7 +307,7 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size) ...@@ -307,7 +307,7 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size)
/* This is the X/Open sanctioned signal stack switching. */ /* This is the X/Open sanctioned signal stack switching. */
if (ka->sa.sa_flags & SA_ONSTACK) { if (ka->sa.sa_flags & SA_ONSTACK) {
if (!on_sig_stack(usp)) if (!sas_ss_flags(usp))
usp = current->sas_ss_sp + current->sas_ss_size; usp = current->sas_ss_sp + current->sas_ss_size;
} }
return (void *)((usp - frame_size) & -8UL); return (void *)((usp - frame_size) & -8UL);
......
...@@ -763,7 +763,7 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size) ...@@ -763,7 +763,7 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size)
/* This is the X/Open sanctioned signal stack switching. */ /* This is the X/Open sanctioned signal stack switching. */
if (ka->sa.sa_flags & SA_ONSTACK) { if (ka->sa.sa_flags & SA_ONSTACK) {
if (!on_sig_stack(usp)) if (!sas_ss_flags(usp))
usp = current->sas_ss_sp + current->sas_ss_size; usp = current->sas_ss_sp + current->sas_ss_size;
} }
return (void __user *)((usp - frame_size) & -8UL); return (void __user *)((usp - frame_size) & -8UL);
......
...@@ -553,7 +553,7 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size) ...@@ -553,7 +553,7 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size)
/* This is the X/Open sanctioned signal stack switching. */ /* This is the X/Open sanctioned signal stack switching. */
if (ka->sa.sa_flags & SA_ONSTACK) { if (ka->sa.sa_flags & SA_ONSTACK) {
if (!on_sig_stack(usp)) if (!sas_ss_flags(usp))
usp = current->sas_ss_sp + current->sas_ss_size; usp = current->sas_ss_sp + current->sas_ss_size;
} }
return (void *)((usp - frame_size) & -8UL); return (void *)((usp - frame_size) & -8UL);
......
...@@ -248,7 +248,7 @@ get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size) ...@@ -248,7 +248,7 @@ get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
DBG(1,"get_sigframe: ka = %#lx, sp = %#lx, frame_size = %#lx\n", DBG(1,"get_sigframe: ka = %#lx, sp = %#lx, frame_size = %#lx\n",
(unsigned long)ka, sp, frame_size); (unsigned long)ka, sp, frame_size);
if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! on_sig_stack(sp)) if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! sas_ss_flags(sp))
sp = current->sas_ss_sp; /* Stacks grow up! */ sp = current->sas_ss_sp; /* Stacks grow up! */
DBG(1,"get_sigframe: Returning sp = %#lx\n", (unsigned long)sp); DBG(1,"get_sigframe: Returning sp = %#lx\n", (unsigned long)sp);
......
...@@ -407,7 +407,7 @@ setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, ...@@ -407,7 +407,7 @@ setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
static inline void __user * static inline void __user *
get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size) get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
{ {
if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! on_sig_stack(sp)) if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! sas_ss_flags(sp))
sp = current->sas_ss_sp + current->sas_ss_size; sp = current->sas_ss_sp + current->sas_ss_size;
return (void __user *)((sp - frame_size) & -8ul); return (void __user *)((sp - frame_size) & -8ul);
......
...@@ -274,7 +274,7 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size) ...@@ -274,7 +274,7 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size)
/* Default to using normal stack */ /* Default to using normal stack */
unsigned long sp = regs->gpr[GPR_SP]; unsigned long sp = regs->gpr[GPR_SP];
if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! on_sig_stack(sp)) if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! sas_ss_flags(sp))
sp = current->sas_ss_sp + current->sas_ss_size; sp = current->sas_ss_sp + current->sas_ss_size;
return (void *)((sp - frame_size) & -8UL); return (void *)((sp - frame_size) & -8UL);
......
...@@ -433,7 +433,7 @@ asmlinkage int sys_rt_sigreturn(struct pt_regs *regs) ...@@ -433,7 +433,7 @@ asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)
static inline void * static inline void *
get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size) get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
{ {
if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! on_sig_stack(sp)) if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! sas_ss_flags(sp))
sp = current->sas_ss_sp + current->sas_ss_size; sp = current->sas_ss_sp + current->sas_ss_size;
return (void *)((sp - frame_size) & -16ul); return (void *)((sp - frame_size) & -16ul);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册