MIPS: Sanitize restart logics
Put the original syscall number into ->regs[0] when we leave syscall with error. Use it in restart logics. Everything else will have it 0 since we pass through SAVE_SOME on all the ways in. Note that in places like bad_stack and inllegal_syscall we leave it 0 - it's not restartable. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Cc: linux-kernel@vger.kernel.org Cc: linux-arch@vger.kernel.org Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/1698/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
This commit is contained in:
parent
e5b377a8fb
commit
8f5a00eb42
|
@ -40,7 +40,6 @@ int __compute_return_epc(struct pt_regs *regs)
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
regs->regs[0] = 0;
|
|
||||||
switch (insn.i_format.opcode) {
|
switch (insn.i_format.opcode) {
|
||||||
/*
|
/*
|
||||||
* jr and jalr are in r_format format.
|
* jr and jalr are in r_format format.
|
||||||
|
|
|
@ -63,9 +63,9 @@ stack_done:
|
||||||
sw t0, PT_R7(sp) # set error flag
|
sw t0, PT_R7(sp) # set error flag
|
||||||
beqz t0, 1f
|
beqz t0, 1f
|
||||||
|
|
||||||
|
lw t1, PT_R2(sp) # syscall number
|
||||||
negu v0 # error
|
negu v0 # error
|
||||||
sw v0, PT_R0(sp) # set flag for syscall
|
sw t1, PT_R0(sp) # save it for syscall restarting
|
||||||
# restarting
|
|
||||||
1: sw v0, PT_R2(sp) # result
|
1: sw v0, PT_R2(sp) # result
|
||||||
|
|
||||||
o32_syscall_exit:
|
o32_syscall_exit:
|
||||||
|
@ -104,9 +104,9 @@ syscall_trace_entry:
|
||||||
sw t0, PT_R7(sp) # set error flag
|
sw t0, PT_R7(sp) # set error flag
|
||||||
beqz t0, 1f
|
beqz t0, 1f
|
||||||
|
|
||||||
|
lw t1, PT_R2(sp) # syscall number
|
||||||
negu v0 # error
|
negu v0 # error
|
||||||
sw v0, PT_R0(sp) # set flag for syscall
|
sw t1, PT_R0(sp) # save it for syscall restarting
|
||||||
# restarting
|
|
||||||
1: sw v0, PT_R2(sp) # result
|
1: sw v0, PT_R2(sp) # result
|
||||||
|
|
||||||
j syscall_exit
|
j syscall_exit
|
||||||
|
@ -170,7 +170,6 @@ stackargs:
|
||||||
*/
|
*/
|
||||||
bad_stack:
|
bad_stack:
|
||||||
negu v0 # error
|
negu v0 # error
|
||||||
sw v0, PT_R0(sp)
|
|
||||||
sw v0, PT_R2(sp)
|
sw v0, PT_R2(sp)
|
||||||
li t0, 1 # set error flag
|
li t0, 1 # set error flag
|
||||||
sw t0, PT_R7(sp)
|
sw t0, PT_R7(sp)
|
||||||
|
|
|
@ -66,9 +66,9 @@ NESTED(handle_sys64, PT_SIZE, sp)
|
||||||
sd t0, PT_R7(sp) # set error flag
|
sd t0, PT_R7(sp) # set error flag
|
||||||
beqz t0, 1f
|
beqz t0, 1f
|
||||||
|
|
||||||
|
ld t1, PT_R2(sp) # syscall number
|
||||||
dnegu v0 # error
|
dnegu v0 # error
|
||||||
sd v0, PT_R0(sp) # set flag for syscall
|
sd t1, PT_R0(sp) # save it for syscall restarting
|
||||||
# restarting
|
|
||||||
1: sd v0, PT_R2(sp) # result
|
1: sd v0, PT_R2(sp) # result
|
||||||
|
|
||||||
n64_syscall_exit:
|
n64_syscall_exit:
|
||||||
|
@ -109,8 +109,9 @@ syscall_trace_entry:
|
||||||
sd t0, PT_R7(sp) # set error flag
|
sd t0, PT_R7(sp) # set error flag
|
||||||
beqz t0, 1f
|
beqz t0, 1f
|
||||||
|
|
||||||
|
ld t1, PT_R2(sp) # syscall number
|
||||||
dnegu v0 # error
|
dnegu v0 # error
|
||||||
sd v0, PT_R0(sp) # set flag for syscall restarting
|
sd t1, PT_R0(sp) # save it for syscall restarting
|
||||||
1: sd v0, PT_R2(sp) # result
|
1: sd v0, PT_R2(sp) # result
|
||||||
|
|
||||||
j syscall_exit
|
j syscall_exit
|
||||||
|
|
|
@ -65,8 +65,9 @@ NESTED(handle_sysn32, PT_SIZE, sp)
|
||||||
sd t0, PT_R7(sp) # set error flag
|
sd t0, PT_R7(sp) # set error flag
|
||||||
beqz t0, 1f
|
beqz t0, 1f
|
||||||
|
|
||||||
|
ld t1, PT_R2(sp) # syscall number
|
||||||
dnegu v0 # error
|
dnegu v0 # error
|
||||||
sd v0, PT_R0(sp) # set flag for syscall restarting
|
sd t1, PT_R0(sp) # save it for syscall restarting
|
||||||
1: sd v0, PT_R2(sp) # result
|
1: sd v0, PT_R2(sp) # result
|
||||||
|
|
||||||
local_irq_disable # make sure need_resched and
|
local_irq_disable # make sure need_resched and
|
||||||
|
@ -106,8 +107,9 @@ n32_syscall_trace_entry:
|
||||||
sd t0, PT_R7(sp) # set error flag
|
sd t0, PT_R7(sp) # set error flag
|
||||||
beqz t0, 1f
|
beqz t0, 1f
|
||||||
|
|
||||||
|
ld t1, PT_R2(sp) # syscall number
|
||||||
dnegu v0 # error
|
dnegu v0 # error
|
||||||
sd v0, PT_R0(sp) # set flag for syscall restarting
|
sd t1, PT_R0(sp) # save it for syscall restarting
|
||||||
1: sd v0, PT_R2(sp) # result
|
1: sd v0, PT_R2(sp) # result
|
||||||
|
|
||||||
j syscall_exit
|
j syscall_exit
|
||||||
|
|
|
@ -93,8 +93,9 @@ NESTED(handle_sys, PT_SIZE, sp)
|
||||||
sd t0, PT_R7(sp) # set error flag
|
sd t0, PT_R7(sp) # set error flag
|
||||||
beqz t0, 1f
|
beqz t0, 1f
|
||||||
|
|
||||||
|
ld t1, PT_R2(sp) # syscall number
|
||||||
dnegu v0 # error
|
dnegu v0 # error
|
||||||
sd v0, PT_R0(sp) # flag for syscall restarting
|
sd t1, PT_R0(sp) # save it for syscall restarting
|
||||||
1: sd v0, PT_R2(sp) # result
|
1: sd v0, PT_R2(sp) # result
|
||||||
|
|
||||||
o32_syscall_exit:
|
o32_syscall_exit:
|
||||||
|
@ -142,8 +143,9 @@ trace_a_syscall:
|
||||||
sd t0, PT_R7(sp) # set error flag
|
sd t0, PT_R7(sp) # set error flag
|
||||||
beqz t0, 1f
|
beqz t0, 1f
|
||||||
|
|
||||||
|
ld t1, PT_R2(sp) # syscall number
|
||||||
dnegu v0 # error
|
dnegu v0 # error
|
||||||
sd v0, PT_R0(sp) # set flag for syscall restarting
|
sd t1, PT_R0(sp) # save it for syscall restarting
|
||||||
1: sd v0, PT_R2(sp) # result
|
1: sd v0, PT_R2(sp) # result
|
||||||
|
|
||||||
j syscall_exit
|
j syscall_exit
|
||||||
|
@ -155,7 +157,6 @@ trace_a_syscall:
|
||||||
*/
|
*/
|
||||||
bad_stack:
|
bad_stack:
|
||||||
dnegu v0 # error
|
dnegu v0 # error
|
||||||
sd v0, PT_R0(sp)
|
|
||||||
sd v0, PT_R2(sp)
|
sd v0, PT_R2(sp)
|
||||||
li t0, 1 # set error flag
|
li t0, 1 # set error flag
|
||||||
sd t0, PT_R7(sp)
|
sd t0, PT_R7(sp)
|
||||||
|
|
|
@ -550,7 +550,8 @@ static int handle_signal(unsigned long sig, siginfo_t *info,
|
||||||
struct mips_abi *abi = current->thread.abi;
|
struct mips_abi *abi = current->thread.abi;
|
||||||
void *vdso = current->mm->context.vdso;
|
void *vdso = current->mm->context.vdso;
|
||||||
|
|
||||||
switch(regs->regs[0]) {
|
if (regs->regs[0]) {
|
||||||
|
switch(regs->regs[2]) {
|
||||||
case ERESTART_RESTARTBLOCK:
|
case ERESTART_RESTARTBLOCK:
|
||||||
case ERESTARTNOHAND:
|
case ERESTARTNOHAND:
|
||||||
regs->regs[2] = EINTR;
|
regs->regs[2] = EINTR;
|
||||||
|
@ -561,12 +562,14 @@ static int handle_signal(unsigned long sig, siginfo_t *info,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
case ERESTARTNOINTR: /* Userland will reload $v0. */
|
case ERESTARTNOINTR:
|
||||||
regs->regs[7] = regs->regs[26];
|
regs->regs[7] = regs->regs[26];
|
||||||
regs->cp0_epc -= 8;
|
regs->regs[2] = regs->regs[0];
|
||||||
|
regs->cp0_epc -= 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
regs->regs[0] = 0; /* Don't deal with this again. */
|
regs->regs[0] = 0; /* Don't deal with this again. */
|
||||||
|
}
|
||||||
|
|
||||||
if (sig_uses_siginfo(ka))
|
if (sig_uses_siginfo(ka))
|
||||||
ret = abi->setup_rt_frame(vdso + abi->rt_signal_return_offset,
|
ret = abi->setup_rt_frame(vdso + abi->rt_signal_return_offset,
|
||||||
|
@ -625,17 +628,13 @@ static void do_signal(struct pt_regs *regs)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Who's code doesn't conform to the restartable syscall convention
|
|
||||||
* dies here!!! The li instruction, a single machine instruction,
|
|
||||||
* must directly be followed by the syscall instruction.
|
|
||||||
*/
|
|
||||||
if (regs->regs[0]) {
|
if (regs->regs[0]) {
|
||||||
if (regs->regs[2] == ERESTARTNOHAND ||
|
if (regs->regs[2] == ERESTARTNOHAND ||
|
||||||
regs->regs[2] == ERESTARTSYS ||
|
regs->regs[2] == ERESTARTSYS ||
|
||||||
regs->regs[2] == ERESTARTNOINTR) {
|
regs->regs[2] == ERESTARTNOINTR) {
|
||||||
|
regs->regs[2] = regs->regs[0];
|
||||||
regs->regs[7] = regs->regs[26];
|
regs->regs[7] = regs->regs[26];
|
||||||
regs->cp0_epc -= 8;
|
regs->cp0_epc -= 4;
|
||||||
}
|
}
|
||||||
if (regs->regs[2] == ERESTART_RESTARTBLOCK) {
|
if (regs->regs[2] == ERESTART_RESTARTBLOCK) {
|
||||||
regs->regs[2] = current->thread.abi->restart;
|
regs->regs[2] = current->thread.abi->restart;
|
||||||
|
|
|
@ -109,8 +109,6 @@ static void emulate_load_store_insn(struct pt_regs *regs,
|
||||||
unsigned long value;
|
unsigned long value;
|
||||||
unsigned int res;
|
unsigned int res;
|
||||||
|
|
||||||
regs->regs[0] = 0;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This load never faults.
|
* This load never faults.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue