aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
authorRoland McGrath <roland@redhat.com>2008-02-28 22:57:07 -0500
committerIngo Molnar <mingo@elte.hu>2008-03-11 12:11:54 -0400
commit40f0933d51f4cba26a5c009a26bb230f4514c1b6 (patch)
tree29a55b7ae8ca7488a9d84fb9de234cff9f8f80b4 /arch/x86
parent9a46d7e5b63903a70cd96c2c1391a7a26a8dbec9 (diff)
x86: ia32 syscall restart fix
The code to restart syscalls after signals depends on checking for a negative orig_ax, and for particular negative -ERESTART* values in ax. These fields are 64 bits and for a 32-bit task they get zero-extended. The syscall restart behavior is lost, a regression from a native 32-bit kernel and from 64-bit tasks' behavior. This patch fixes the problem by doing sign-extension where it matters. For orig_ax, the only time the value should be -1 but winds up as 0x0ffffffff is via a 32-bit ptrace call. So the patch changes ptrace to sign-extend the 32-bit orig_eax value when it's stored; it doesn't change the checks on orig_ax, though it uses the new current_syscall() inline to better document the subtle importance of the used of signedness there. The ax value is stored a lot of ways and it seems hard to get them all sign-extended at their origins. So for that, we use the current_syscall_ret() to sign-extend it only for 32-bit tasks at the time of the -ERESTART* comparisons. Signed-off-by: Roland McGrath <roland@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/kernel/ptrace.c9
-rw-r--r--arch/x86/kernel/signal_64.c38
2 files changed, 41 insertions, 6 deletions
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
index 8f64abe699fd..d5904eef1d31 100644
--- a/arch/x86/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace.c
@@ -1055,10 +1055,17 @@ static int putreg32(struct task_struct *child, unsigned regno, u32 value)
1055 R32(esi, si); 1055 R32(esi, si);
1056 R32(ebp, bp); 1056 R32(ebp, bp);
1057 R32(eax, ax); 1057 R32(eax, ax);
1058 R32(orig_eax, orig_ax);
1059 R32(eip, ip); 1058 R32(eip, ip);
1060 R32(esp, sp); 1059 R32(esp, sp);
1061 1060
1061 case offsetof(struct user32, regs.orig_eax):
1062 /*
1063 * Sign-extend the value so that orig_eax = -1
1064 * causes (long)orig_ax < 0 tests to fire correctly.
1065 */
1066 regs->orig_ax = (long) (s32) value;
1067 break;
1068
1062 case offsetof(struct user32, regs.eflags): 1069 case offsetof(struct user32, regs.eflags):
1063 return set_flags(child, value); 1070 return set_flags(child, value);
1064 1071
diff --git a/arch/x86/kernel/signal_64.c b/arch/x86/kernel/signal_64.c
index 56b72fb67f9b..1c83e5124c65 100644
--- a/arch/x86/kernel/signal_64.c
+++ b/arch/x86/kernel/signal_64.c
@@ -311,6 +311,35 @@ give_sigsegv:
311} 311}
312 312
313/* 313/*
314 * Return -1L or the syscall number that @regs is executing.
315 */
316static long current_syscall(struct pt_regs *regs)
317{
318 /*
319 * We always sign-extend a -1 value being set here,
320 * so this is always either -1L or a syscall number.
321 */
322 return regs->orig_ax;
323}
324
325/*
326 * Return a value that is -EFOO if the system call in @regs->orig_ax
327 * returned an error. This only works for @regs from @current.
328 */
329static long current_syscall_ret(struct pt_regs *regs)
330{
331#ifdef CONFIG_IA32_EMULATION
332 if (test_thread_flag(TIF_IA32))
333 /*
334 * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
335 * and will match correctly in comparisons.
336 */
337 return (int) regs->ax;
338#endif
339 return regs->ax;
340}
341
342/*
314 * OK, we're invoking a handler 343 * OK, we're invoking a handler
315 */ 344 */
316 345
@@ -327,9 +356,9 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
327#endif 356#endif
328 357
329 /* Are we from a system call? */ 358 /* Are we from a system call? */
330 if ((long)regs->orig_ax >= 0) { 359 if (current_syscall(regs) >= 0) {
331 /* If so, check system call restarting.. */ 360 /* If so, check system call restarting.. */
332 switch (regs->ax) { 361 switch (current_syscall_ret(regs)) {
333 case -ERESTART_RESTARTBLOCK: 362 case -ERESTART_RESTARTBLOCK:
334 case -ERESTARTNOHAND: 363 case -ERESTARTNOHAND:
335 regs->ax = -EINTR; 364 regs->ax = -EINTR;
@@ -426,10 +455,9 @@ static void do_signal(struct pt_regs *regs)
426 } 455 }
427 456
428 /* Did we come from a system call? */ 457 /* Did we come from a system call? */
429 if ((long)regs->orig_ax >= 0) { 458 if (current_syscall(regs) >= 0) {
430 /* Restart the system call - no handlers present */ 459 /* Restart the system call - no handlers present */
431 long res = regs->ax; 460 switch (current_syscall_ret(regs)) {
432 switch (res) {
433 case -ERESTARTNOHAND: 461 case -ERESTARTNOHAND:
434 case -ERESTARTSYS: 462 case -ERESTARTSYS:
435 case -ERESTARTNOINTR: 463 case -ERESTARTNOINTR: