Commit 6a3713f0 authored by Brian Gerst's avatar Brian Gerst Committed by Ingo Molnar

x86/signal: Remove pax argument from restore_sigcontext

The 'pax' argument is unnecesary.  Instead, store the RAX value
directly in regs.

This pattern goes all the way back to 2.1.106pre1, when restore_sigcontext()
was changed to return an error code instead of EAX directly:

  https://git.kernel.org/cgit/linux/kernel/git/history/history.git/diff/arch/i386/kernel/signal.c?id=9a8f8b7ca3f319bd668298d447bdf32730e51174

In 2007 sigaltstack syscall support was added, where the return
value of restore_sigcontext() was changed to carry the memory-copying
failure code.

But instead of putting 'ax' into regs->ax directly, it was carried
in via a pointer and then returned, where the generic syscall return
code copied it to regs->ax.

So there was never any deeper reason for this suboptimal pattern, it
was simply never noticed after being introduced.
Signed-off-by: default avatarBrian Gerst <brgerst@gmail.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1428152303-17154-1-git-send-email-brgerst@gmail.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent dbe4058a
...@@ -161,8 +161,7 @@ int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from) ...@@ -161,8 +161,7 @@ int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
} }
static int ia32_restore_sigcontext(struct pt_regs *regs, static int ia32_restore_sigcontext(struct pt_regs *regs,
struct sigcontext_ia32 __user *sc, struct sigcontext_ia32 __user *sc)
unsigned int *pax)
{ {
unsigned int tmpflags, err = 0; unsigned int tmpflags, err = 0;
void __user *buf; void __user *buf;
...@@ -184,7 +183,7 @@ static int ia32_restore_sigcontext(struct pt_regs *regs, ...@@ -184,7 +183,7 @@ static int ia32_restore_sigcontext(struct pt_regs *regs,
RELOAD_SEG(es); RELOAD_SEG(es);
COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx); COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
COPY(dx); COPY(cx); COPY(ip); COPY(dx); COPY(cx); COPY(ip); COPY(ax);
/* Don't touch extended registers */ /* Don't touch extended registers */
COPY_SEG_CPL3(cs); COPY_SEG_CPL3(cs);
...@@ -197,8 +196,6 @@ static int ia32_restore_sigcontext(struct pt_regs *regs, ...@@ -197,8 +196,6 @@ static int ia32_restore_sigcontext(struct pt_regs *regs,
get_user_ex(tmp, &sc->fpstate); get_user_ex(tmp, &sc->fpstate);
buf = compat_ptr(tmp); buf = compat_ptr(tmp);
get_user_ex(*pax, &sc->ax);
} get_user_catch(err); } get_user_catch(err);
err |= restore_xstate_sig(buf, 1); err |= restore_xstate_sig(buf, 1);
...@@ -213,7 +210,6 @@ asmlinkage long sys32_sigreturn(void) ...@@ -213,7 +210,6 @@ asmlinkage long sys32_sigreturn(void)
struct pt_regs *regs = current_pt_regs(); struct pt_regs *regs = current_pt_regs();
struct sigframe_ia32 __user *frame = (struct sigframe_ia32 __user *)(regs->sp-8); struct sigframe_ia32 __user *frame = (struct sigframe_ia32 __user *)(regs->sp-8);
sigset_t set; sigset_t set;
unsigned int ax;
if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
goto badframe; goto badframe;
...@@ -226,9 +222,9 @@ asmlinkage long sys32_sigreturn(void) ...@@ -226,9 +222,9 @@ asmlinkage long sys32_sigreturn(void)
set_current_blocked(&set); set_current_blocked(&set);
if (ia32_restore_sigcontext(regs, &frame->sc, &ax)) if (ia32_restore_sigcontext(regs, &frame->sc))
goto badframe; goto badframe;
return ax; return regs->ax;
badframe: badframe:
signal_fault(regs, frame, "32bit sigreturn"); signal_fault(regs, frame, "32bit sigreturn");
...@@ -240,7 +236,6 @@ asmlinkage long sys32_rt_sigreturn(void) ...@@ -240,7 +236,6 @@ asmlinkage long sys32_rt_sigreturn(void)
struct pt_regs *regs = current_pt_regs(); struct pt_regs *regs = current_pt_regs();
struct rt_sigframe_ia32 __user *frame; struct rt_sigframe_ia32 __user *frame;
sigset_t set; sigset_t set;
unsigned int ax;
frame = (struct rt_sigframe_ia32 __user *)(regs->sp - 4); frame = (struct rt_sigframe_ia32 __user *)(regs->sp - 4);
...@@ -251,13 +246,13 @@ asmlinkage long sys32_rt_sigreturn(void) ...@@ -251,13 +246,13 @@ asmlinkage long sys32_rt_sigreturn(void)
set_current_blocked(&set); set_current_blocked(&set);
if (ia32_restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) if (ia32_restore_sigcontext(regs, &frame->uc.uc_mcontext))
goto badframe; goto badframe;
if (compat_restore_altstack(&frame->uc.uc_stack)) if (compat_restore_altstack(&frame->uc.uc_stack))
goto badframe; goto badframe;
return ax; return regs->ax;
badframe: badframe:
signal_fault(regs, frame, "32bit rt sigreturn"); signal_fault(regs, frame, "32bit rt sigreturn");
......
...@@ -13,9 +13,7 @@ ...@@ -13,9 +13,7 @@
X86_EFLAGS_CF | X86_EFLAGS_RF) X86_EFLAGS_CF | X86_EFLAGS_RF)
void signal_fault(struct pt_regs *regs, void __user *frame, char *where); void signal_fault(struct pt_regs *regs, void __user *frame, char *where);
int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc);
int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
unsigned long *pax);
int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate, int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
struct pt_regs *regs, unsigned long mask); struct pt_regs *regs, unsigned long mask);
......
...@@ -61,8 +61,7 @@ ...@@ -61,8 +61,7 @@
regs->seg = GET_SEG(seg) | 3; \ regs->seg = GET_SEG(seg) | 3; \
} while (0) } while (0)
int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
unsigned long *pax)
{ {
void __user *buf; void __user *buf;
unsigned int tmpflags; unsigned int tmpflags;
...@@ -81,7 +80,7 @@ int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, ...@@ -81,7 +80,7 @@ int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
#endif /* CONFIG_X86_32 */ #endif /* CONFIG_X86_32 */
COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx); COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
COPY(dx); COPY(cx); COPY(ip); COPY(dx); COPY(cx); COPY(ip); COPY(ax);
#ifdef CONFIG_X86_64 #ifdef CONFIG_X86_64
COPY(r8); COPY(r8);
...@@ -102,8 +101,6 @@ int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, ...@@ -102,8 +101,6 @@ int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
regs->orig_ax = -1; /* disable syscall checks */ regs->orig_ax = -1; /* disable syscall checks */
get_user_ex(buf, &sc->fpstate); get_user_ex(buf, &sc->fpstate);
get_user_ex(*pax, &sc->ax);
} get_user_catch(err); } get_user_catch(err);
err |= restore_xstate_sig(buf, config_enabled(CONFIG_X86_32)); err |= restore_xstate_sig(buf, config_enabled(CONFIG_X86_32));
...@@ -545,7 +542,6 @@ asmlinkage unsigned long sys_sigreturn(void) ...@@ -545,7 +542,6 @@ asmlinkage unsigned long sys_sigreturn(void)
{ {
struct pt_regs *regs = current_pt_regs(); struct pt_regs *regs = current_pt_regs();
struct sigframe __user *frame; struct sigframe __user *frame;
unsigned long ax;
sigset_t set; sigset_t set;
frame = (struct sigframe __user *)(regs->sp - 8); frame = (struct sigframe __user *)(regs->sp - 8);
...@@ -559,9 +555,9 @@ asmlinkage unsigned long sys_sigreturn(void) ...@@ -559,9 +555,9 @@ asmlinkage unsigned long sys_sigreturn(void)
set_current_blocked(&set); set_current_blocked(&set);
if (restore_sigcontext(regs, &frame->sc, &ax)) if (restore_sigcontext(regs, &frame->sc))
goto badframe; goto badframe;
return ax; return regs->ax;
badframe: badframe:
signal_fault(regs, frame, "sigreturn"); signal_fault(regs, frame, "sigreturn");
...@@ -574,7 +570,6 @@ asmlinkage long sys_rt_sigreturn(void) ...@@ -574,7 +570,6 @@ asmlinkage long sys_rt_sigreturn(void)
{ {
struct pt_regs *regs = current_pt_regs(); struct pt_regs *regs = current_pt_regs();
struct rt_sigframe __user *frame; struct rt_sigframe __user *frame;
unsigned long ax;
sigset_t set; sigset_t set;
frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long)); frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
...@@ -585,13 +580,13 @@ asmlinkage long sys_rt_sigreturn(void) ...@@ -585,13 +580,13 @@ asmlinkage long sys_rt_sigreturn(void)
set_current_blocked(&set); set_current_blocked(&set);
if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
goto badframe; goto badframe;
if (restore_altstack(&frame->uc.uc_stack)) if (restore_altstack(&frame->uc.uc_stack))
goto badframe; goto badframe;
return ax; return regs->ax;
badframe: badframe:
signal_fault(regs, frame, "rt_sigreturn"); signal_fault(regs, frame, "rt_sigreturn");
...@@ -786,7 +781,6 @@ asmlinkage long sys32_x32_rt_sigreturn(void) ...@@ -786,7 +781,6 @@ asmlinkage long sys32_x32_rt_sigreturn(void)
struct pt_regs *regs = current_pt_regs(); struct pt_regs *regs = current_pt_regs();
struct rt_sigframe_x32 __user *frame; struct rt_sigframe_x32 __user *frame;
sigset_t set; sigset_t set;
unsigned long ax;
frame = (struct rt_sigframe_x32 __user *)(regs->sp - 8); frame = (struct rt_sigframe_x32 __user *)(regs->sp - 8);
...@@ -797,13 +791,13 @@ asmlinkage long sys32_x32_rt_sigreturn(void) ...@@ -797,13 +791,13 @@ asmlinkage long sys32_x32_rt_sigreturn(void)
set_current_blocked(&set); set_current_blocked(&set);
if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
goto badframe; goto badframe;
if (compat_restore_altstack(&frame->uc.uc_stack)) if (compat_restore_altstack(&frame->uc.uc_stack))
goto badframe; goto badframe;
return ax; return regs->ax;
badframe: badframe:
signal_fault(regs, frame, "x32 rt_sigreturn"); signal_fault(regs, frame, "x32 rt_sigreturn");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment