aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland McGrath <roland@redhat.com>2009-09-22 23:12:07 -0400
committerRoland McGrath <roland@redhat.com>2009-09-23 01:49:24 -0400
commit8cb3ed13935b9b523c2de7afc8f68473fe1d4531 (patch)
tree8c9d53ac4e9facc5750cc6bd7bd07260845b9797
parent08ff18e299b1a1c91f4911fe9f35c4550218c73f (diff)
x86: ptrace: set TS_COMPAT when 32-bit ptrace sets orig_eax>=0
The 32-bit ptrace syscall on a 64-bit kernel (32-bit debugger on 32-bit task) behaves differently than a native 32-bit kernel. When setting a register state of orig_eax>=0 and eax=-ERESTART* when the debugged task is NOT on its way out of a 32-bit syscall, the task will fail to do the syscall restart logic that it should do. Test case available at http://sources.redhat.com/cgi-bin/cvsweb.cgi/~checkout~/tests/ptrace-tests/tests/erestartsys-trap.c?cvsroot=systemtap This happens because the 32-bit ptrace syscall sets eax=0xffffffff when it sets orig_eax>=0. The resuming task will not sign-extend this for the -ERESTART* check because TS_COMPAT is not set. (So the task thinks it is restarting after a 64-bit syscall, not a 32-bit one.) The fix is to have 32-bit ptrace calls set TS_COMPAT when setting orig_eax>=0. This ensures that the 32-bit syscall restart logic will apply when the child resumes. Signed-off-by: Roland McGrath <roland@redhat.com>
-rw-r--r--arch/x86/kernel/ptrace.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
index 52222fab99f4..7b058a2dc66a 100644
--- a/arch/x86/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace.c
@@ -1111,10 +1111,22 @@ static int putreg32(struct task_struct *child, unsigned regno, u32 value)
1111 R32(esi, si); 1111 R32(esi, si);
1112 R32(ebp, bp); 1112 R32(ebp, bp);
1113 R32(eax, ax); 1113 R32(eax, ax);
1114 R32(orig_eax, orig_ax);
1115 R32(eip, ip); 1114 R32(eip, ip);
1116 R32(esp, sp); 1115 R32(esp, sp);
1117 1116
1117 case offsetof(struct user32, regs.orig_eax):
1118 /*
1119 * A 32-bit debugger setting orig_eax means to restore
1120 * the state of the task restarting a 32-bit syscall.
1121 * Make sure we interpret the -ERESTART* codes correctly
1122 * in case the task is not actually still sitting at the
1123 * exit from a 32-bit syscall with TS_COMPAT still set.
1124 */
1125 regs->orig_ax = value;
1126 if (syscall_get_nr(child, regs) >= 0)
1127 task_thread_info(child)->status |= TS_COMPAT;
1128 break;
1129
1118 case offsetof(struct user32, regs.eflags): 1130 case offsetof(struct user32, regs.eflags):
1119 return set_flags(child, value); 1131 return set_flags(child, value);
1120 1132