Skip to content

Commit 573b22c

Browse files
Al Virotorvalds
authored andcommitted
sh: sanitize the flags on sigreturn
We fetch %SR value from sigframe; it might have been modified by signal handler, so we can't trust it with any bits that are not modifiable in user mode. Signed-off-by: Al Viro <[email protected]> Cc: Rich Felker <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 6a98c9c commit 573b22c

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

arch/sh/include/asm/processor_32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#define SR_FD 0x00008000
5151
#define SR_MD 0x40000000
5252

53+
#define SR_USER_MASK 0x00000303 // M, Q, S, T bits
5354
/*
5455
* DSP structure and data
5556
*/

arch/sh/kernel/signal_32.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ static int
115115
restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, int *r0_p)
116116
{
117117
unsigned int err = 0;
118+
unsigned int sr = regs->sr & ~SR_USER_MASK;
118119

119120
#define COPY(x) err |= __get_user(regs->x, &sc->sc_##x)
120121
COPY(regs[1]);
@@ -130,6 +131,8 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, int *r0_p
130131
COPY(sr); COPY(pc);
131132
#undef COPY
132133

134+
regs->sr = (regs->sr & SR_USER_MASK) | sr;
135+
133136
#ifdef CONFIG_SH_FPU
134137
if (boot_cpu_data.flags & CPU_HAS_FPU) {
135138
int owned_fp;

0 commit comments

Comments
 (0)