diff options
author | Mickaël Salaün <mic@digikod.net> | 2015-12-29 15:35:44 -0500 |
---|---|---|
committer | Richard Weinberger <richard@nod.at> | 2016-01-10 15:49:48 -0500 |
commit | e04c989eb785af61d2895d76d38c09166296f9c5 (patch) | |
tree | a4698bceed0851ec151539c275e5d615da506d36 | |
parent | a7df4716d19594b7b3f106f0bc0ca1c548e508e6 (diff) |
um: Fix ptrace GETREGS/SETREGS bugs
This fix two related bugs:
* PTRACE_GETREGS doesn't get the right orig_ax (syscall) value
* PTRACE_SETREGS can't set the orig_ax value (erased by initial value)
Get rid of the now useless and error-prone get_syscall().
Fix inconsistent behavior in the ptrace implementation for i386 when
updating orig_eax automatically update the syscall number as well. This
is now updated in handle_syscall().
Signed-off-by: Mickaël Salaün <mic@digikod.net>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Kees Cook <keescook@chromium.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Will Drewry <wad@chromium.org>
Cc: Thomas Meyer <thomas@m3y3r.de>
Cc: Nicolas Iooss <nicolas.iooss_linux@m4x.org>
Cc: Anton Ivanov <aivanov@brocade.com>
Cc: Meredydd Luff <meredydd@senatehouse.org>
Cc: David Drysdale <drysdale@google.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
Acked-by: Kees Cook <keescook@chromium.org>
-rw-r--r-- | arch/um/include/shared/os.h | 1 | ||||
-rw-r--r-- | arch/um/kernel/skas/syscall.c | 26 | ||||
-rw-r--r-- | arch/um/os-Linux/skas/process.c | 7 | ||||
-rw-r--r-- | arch/x86/um/ptrace_32.c | 8 |
4 files changed, 17 insertions, 25 deletions
diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index 7a04ddd85334..de5d572225f3 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h | |||
@@ -284,7 +284,6 @@ extern void initial_thread_cb_skas(void (*proc)(void *), | |||
284 | void *arg); | 284 | void *arg); |
285 | extern void halt_skas(void); | 285 | extern void halt_skas(void); |
286 | extern void reboot_skas(void); | 286 | extern void reboot_skas(void); |
287 | extern int get_syscall(struct uml_pt_regs *regs); | ||
288 | 287 | ||
289 | /* irq.c */ | 288 | /* irq.c */ |
290 | extern int os_waiting_for_events(struct irq_fd *active_fds); | 289 | extern int os_waiting_for_events(struct irq_fd *active_fds); |
diff --git a/arch/um/kernel/skas/syscall.c b/arch/um/kernel/skas/syscall.c index 1683b8efdfda..6cadce761bcf 100644 --- a/arch/um/kernel/skas/syscall.c +++ b/arch/um/kernel/skas/syscall.c | |||
@@ -7,29 +7,31 @@ | |||
7 | #include <linux/ptrace.h> | 7 | #include <linux/ptrace.h> |
8 | #include <kern_util.h> | 8 | #include <kern_util.h> |
9 | #include <sysdep/ptrace.h> | 9 | #include <sysdep/ptrace.h> |
10 | #include <sysdep/ptrace_user.h> | ||
10 | #include <sysdep/syscalls.h> | 11 | #include <sysdep/syscalls.h> |
11 | #include <os.h> | ||
12 | 12 | ||
13 | void handle_syscall(struct uml_pt_regs *r) | 13 | void handle_syscall(struct uml_pt_regs *r) |
14 | { | 14 | { |
15 | struct pt_regs *regs = container_of(r, struct pt_regs, regs); | 15 | struct pt_regs *regs = container_of(r, struct pt_regs, regs); |
16 | long result; | ||
17 | int syscall; | 16 | int syscall; |
18 | 17 | ||
19 | if (syscall_trace_enter(regs)) { | 18 | /* Initialize the syscall number and default return value. */ |
20 | result = -ENOSYS; | 19 | UPT_SYSCALL_NR(r) = PT_SYSCALL_NR(r->gp); |
20 | PT_REGS_SET_SYSCALL_RETURN(regs, -ENOSYS); | ||
21 | |||
22 | if (syscall_trace_enter(regs)) | ||
21 | goto out; | 23 | goto out; |
22 | } | ||
23 | 24 | ||
24 | syscall = get_syscall(r); | 25 | /* Update the syscall number after orig_ax has potentially been updated |
26 | * with ptrace. | ||
27 | */ | ||
28 | UPT_SYSCALL_NR(r) = PT_SYSCALL_NR(r->gp); | ||
29 | syscall = UPT_SYSCALL_NR(r); | ||
25 | 30 | ||
26 | if ((syscall > __NR_syscall_max) || syscall < 0) | 31 | if (syscall >= 0 && syscall <= __NR_syscall_max) |
27 | result = -ENOSYS; | 32 | PT_REGS_SET_SYSCALL_RETURN(regs, |
28 | else | 33 | EXECUTE_SYSCALL(syscall, regs)); |
29 | result = EXECUTE_SYSCALL(syscall, regs); | ||
30 | 34 | ||
31 | out: | 35 | out: |
32 | PT_REGS_SET_SYSCALL_RETURN(regs, result); | ||
33 | |||
34 | syscall_trace_leave(regs); | 36 | syscall_trace_leave(regs); |
35 | } | 37 | } |
diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c index b856c66ebd3a..23025d645160 100644 --- a/arch/um/os-Linux/skas/process.c +++ b/arch/um/os-Linux/skas/process.c | |||
@@ -172,13 +172,6 @@ static void handle_trap(int pid, struct uml_pt_regs *regs, | |||
172 | handle_syscall(regs); | 172 | handle_syscall(regs); |
173 | } | 173 | } |
174 | 174 | ||
175 | int get_syscall(struct uml_pt_regs *regs) | ||
176 | { | ||
177 | UPT_SYSCALL_NR(regs) = PT_SYSCALL_NR(regs->gp); | ||
178 | |||
179 | return UPT_SYSCALL_NR(regs); | ||
180 | } | ||
181 | |||
182 | extern char __syscall_stub_start[]; | 175 | extern char __syscall_stub_start[]; |
183 | 176 | ||
184 | static int userspace_tramp(void *stack) | 177 | static int userspace_tramp(void *stack) |
diff --git a/arch/x86/um/ptrace_32.c b/arch/x86/um/ptrace_32.c index a29756f2d940..47c78d5e5c32 100644 --- a/arch/x86/um/ptrace_32.c +++ b/arch/x86/um/ptrace_32.c | |||
@@ -68,6 +68,7 @@ static const int reg_offsets[] = { | |||
68 | [EFL] = HOST_EFLAGS, | 68 | [EFL] = HOST_EFLAGS, |
69 | [UESP] = HOST_SP, | 69 | [UESP] = HOST_SP, |
70 | [SS] = HOST_SS, | 70 | [SS] = HOST_SS, |
71 | [ORIG_EAX] = HOST_ORIG_AX, | ||
71 | }; | 72 | }; |
72 | 73 | ||
73 | int putreg(struct task_struct *child, int regno, unsigned long value) | 74 | int putreg(struct task_struct *child, int regno, unsigned long value) |
@@ -83,6 +84,7 @@ int putreg(struct task_struct *child, int regno, unsigned long value) | |||
83 | case EAX: | 84 | case EAX: |
84 | case EIP: | 85 | case EIP: |
85 | case UESP: | 86 | case UESP: |
87 | case ORIG_EAX: | ||
86 | break; | 88 | break; |
87 | case FS: | 89 | case FS: |
88 | if (value && (value & 3) != 3) | 90 | if (value && (value & 3) != 3) |
@@ -108,9 +110,6 @@ int putreg(struct task_struct *child, int regno, unsigned long value) | |||
108 | value &= FLAG_MASK; | 110 | value &= FLAG_MASK; |
109 | child->thread.regs.regs.gp[HOST_EFLAGS] |= value; | 111 | child->thread.regs.regs.gp[HOST_EFLAGS] |= value; |
110 | return 0; | 112 | return 0; |
111 | case ORIG_EAX: | ||
112 | child->thread.regs.regs.syscall = value; | ||
113 | return 0; | ||
114 | default : | 113 | default : |
115 | panic("Bad register in putreg() : %d\n", regno); | 114 | panic("Bad register in putreg() : %d\n", regno); |
116 | } | 115 | } |
@@ -143,8 +142,6 @@ unsigned long getreg(struct task_struct *child, int regno) | |||
143 | 142 | ||
144 | regno >>= 2; | 143 | regno >>= 2; |
145 | switch (regno) { | 144 | switch (regno) { |
146 | case ORIG_EAX: | ||
147 | return child->thread.regs.regs.syscall; | ||
148 | case FS: | 145 | case FS: |
149 | case GS: | 146 | case GS: |
150 | case DS: | 147 | case DS: |
@@ -163,6 +160,7 @@ unsigned long getreg(struct task_struct *child, int regno) | |||
163 | case EDI: | 160 | case EDI: |
164 | case EBP: | 161 | case EBP: |
165 | case EFL: | 162 | case EFL: |
163 | case ORIG_EAX: | ||
166 | break; | 164 | break; |
167 | default: | 165 | default: |
168 | panic("Bad register in getreg() : %d\n", regno); | 166 | panic("Bad register in getreg() : %d\n", regno); |