sh: sanitize the flags on sigreturn
authorAl Viro <viro@zeniv.linux.org.uk>
Mon, 6 Mar 2023 01:20:30 +0000 (01:20 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 30 Mar 2023 10:47:54 +0000 (12:47 +0200)
[ Upstream commit 573b22ccb7ce9ab7f0539a2e11a9d3609a8783f5 ]

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 <viro@zeniv.linux.org.uk>
Cc: Rich Felker <dalias@libc.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/sh/include/asm/processor_32.h
arch/sh/kernel/signal_32.c

index aa92cc933889df791ee756400d348412cc070415..6c7966e627758890b173d440642f369f85fdd7be 100644 (file)
@@ -50,6 +50,7 @@
 #define SR_FD          0x00008000
 #define SR_MD          0x40000000
 
+#define SR_USER_MASK   0x00000303      // M, Q, S, T bits
 /*
  * DSP structure and data
  */
index dd3092911efad74200882e1192aa89fd9fe97bdd..dc13702003f0f31fa709f75d27ac8e847377b1b3 100644 (file)
@@ -115,6 +115,7 @@ static int
 restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, int *r0_p)
 {
        unsigned int err = 0;
+       unsigned int sr = regs->sr & ~SR_USER_MASK;
 
 #define COPY(x)                err |= __get_user(regs->x, &sc->sc_##x)
                        COPY(regs[1]);
@@ -130,6 +131,8 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, int *r0_p
        COPY(sr);       COPY(pc);
 #undef COPY
 
+       regs->sr = (regs->sr & SR_USER_MASK) | sr;
+
 #ifdef CONFIG_SH_FPU
        if (boot_cpu_data.flags & CPU_HAS_FPU) {
                int owned_fp;