Skip to contentSkip to conversation

ARM: prevent multiple syscall restarts

PATCH In review Russell King 2 participants 2 messages Sep 17, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: prevent multiple syscall restarts

Al Viro reports that calling "sys_sigsuspend(-ERESTARTNOHAND, 0, 0)" with two signals coming and being handled in kernel space results in the syscall restart being done twice.

Avoid this by clearing the 'why' flag when we call the signal handling code to prevent further syscall restarts after the first.

---
 arch/arm/kernel/entry-common.S |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/arm/kernel/entry-common.S +2 -0
index f05a35a..4a560d3 100644
@@ -48,6 +48,8 @@ work_pending:
 	beq	no_work_pending
 	mov	r0, sp				@ 'regs'
 	mov	r2, why				@ 'syscall'
+	tst	r1, #_TIF_SIGPENDING		@ delivering a signal?
+	movne	why, #0				@ prevent further restarts
 	bl	do_notify_resume
 	b	ret_slow_syscall		@ Check work again
 
Signature · 7 lines
1.6.2.5


-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:
#1 lore raw
Quoted 6 lines · Russell King

Al Viro reports that calling "sys_sigsuspend(-ERESTARTNOHAND, 0, 0)" with two signals coming and being handled in kernel space results in the syscall restart being done twice.

Avoid this by clearing the 'why' flag when we call the signal handling code to prevent further syscall restarts after the first.

I'd like to add that while sigsuspend example is, certainly, cheating (the first two arguments of sigsuspend(2) on arm are ignored for historical reasons, and libc is not going to end up with that in the first argument), the issue is real - existing code on arm relied on the following assertion:

no syscall called with -ERESTART... in the first argument will
ever return -ERESTART...

It happens to be true for most of the syscalls, since that value will lead to -EBADF if the argument is a file descriptor and -EFAULT if it's a userland pointer. Ones that expect a syscall-specific enum will probably also just fail with -EINVAL. So most of the potential victims are actually OK. However, it's certainly better to have a straightforward prevention of that kind of crap than keep relying on fairly subtle properties of code in core kernel that has no idea about arch/arm relying on it - in undocumented way, at that.