diff options
Diffstat (limited to 'arch/x86/kernel/signal_64.c')
-rw-r--r-- | arch/x86/kernel/signal_64.c | 133 |
1 files changed, 66 insertions, 67 deletions
diff --git a/arch/x86/kernel/signal_64.c b/arch/x86/kernel/signal_64.c index 38d806467c0f..7347bb14e306 100644 --- a/arch/x86/kernel/signal_64.c +++ b/arch/x86/kernel/signal_64.c | |||
@@ -39,7 +39,7 @@ asmlinkage long | |||
39 | sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, | 39 | sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, |
40 | struct pt_regs *regs) | 40 | struct pt_regs *regs) |
41 | { | 41 | { |
42 | return do_sigaltstack(uss, uoss, regs->rsp); | 42 | return do_sigaltstack(uss, uoss, regs->sp); |
43 | } | 43 | } |
44 | 44 | ||
45 | 45 | ||
@@ -64,8 +64,8 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, unsigned | |||
64 | 64 | ||
65 | #define COPY(x) err |= __get_user(regs->x, &sc->x) | 65 | #define COPY(x) err |= __get_user(regs->x, &sc->x) |
66 | 66 | ||
67 | COPY(rdi); COPY(rsi); COPY(rbp); COPY(rsp); COPY(rbx); | 67 | COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx); |
68 | COPY(rdx); COPY(rcx); COPY(rip); | 68 | COPY(dx); COPY(cx); COPY(ip); |
69 | COPY(r8); | 69 | COPY(r8); |
70 | COPY(r9); | 70 | COPY(r9); |
71 | COPY(r10); | 71 | COPY(r10); |
@@ -86,9 +86,9 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, unsigned | |||
86 | 86 | ||
87 | { | 87 | { |
88 | unsigned int tmpflags; | 88 | unsigned int tmpflags; |
89 | err |= __get_user(tmpflags, &sc->eflags); | 89 | err |= __get_user(tmpflags, &sc->flags); |
90 | regs->eflags = (regs->eflags & ~0x40DD5) | (tmpflags & 0x40DD5); | 90 | regs->flags = (regs->flags & ~0x40DD5) | (tmpflags & 0x40DD5); |
91 | regs->orig_rax = -1; /* disable syscall checks */ | 91 | regs->orig_ax = -1; /* disable syscall checks */ |
92 | } | 92 | } |
93 | 93 | ||
94 | { | 94 | { |
@@ -108,7 +108,7 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, unsigned | |||
108 | } | 108 | } |
109 | } | 109 | } |
110 | 110 | ||
111 | err |= __get_user(*prax, &sc->rax); | 111 | err |= __get_user(*prax, &sc->ax); |
112 | return err; | 112 | return err; |
113 | 113 | ||
114 | badframe: | 114 | badframe: |
@@ -119,9 +119,9 @@ asmlinkage long sys_rt_sigreturn(struct pt_regs *regs) | |||
119 | { | 119 | { |
120 | struct rt_sigframe __user *frame; | 120 | struct rt_sigframe __user *frame; |
121 | sigset_t set; | 121 | sigset_t set; |
122 | unsigned long eax; | 122 | unsigned long ax; |
123 | 123 | ||
124 | frame = (struct rt_sigframe __user *)(regs->rsp - 8); | 124 | frame = (struct rt_sigframe __user *)(regs->sp - 8); |
125 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) { | 125 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) { |
126 | goto badframe; | 126 | goto badframe; |
127 | } | 127 | } |
@@ -135,17 +135,17 @@ asmlinkage long sys_rt_sigreturn(struct pt_regs *regs) | |||
135 | recalc_sigpending(); | 135 | recalc_sigpending(); |
136 | spin_unlock_irq(¤t->sighand->siglock); | 136 | spin_unlock_irq(¤t->sighand->siglock); |
137 | 137 | ||
138 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &eax)) | 138 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) |
139 | goto badframe; | 139 | goto badframe; |
140 | 140 | ||
141 | #ifdef DEBUG_SIG | 141 | #ifdef DEBUG_SIG |
142 | printk("%d sigreturn rip:%lx rsp:%lx frame:%p rax:%lx\n",current->pid,regs->rip,regs->rsp,frame,eax); | 142 | printk("%d sigreturn ip:%lx sp:%lx frame:%p ax:%lx\n",current->pid,regs->ip,regs->sp,frame,ax); |
143 | #endif | 143 | #endif |
144 | 144 | ||
145 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->rsp) == -EFAULT) | 145 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT) |
146 | goto badframe; | 146 | goto badframe; |
147 | 147 | ||
148 | return eax; | 148 | return ax; |
149 | 149 | ||
150 | badframe: | 150 | badframe: |
151 | signal_fault(regs,frame,"sigreturn"); | 151 | signal_fault(regs,frame,"sigreturn"); |
@@ -165,14 +165,14 @@ setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, unsigned lo | |||
165 | err |= __put_user(0, &sc->gs); | 165 | err |= __put_user(0, &sc->gs); |
166 | err |= __put_user(0, &sc->fs); | 166 | err |= __put_user(0, &sc->fs); |
167 | 167 | ||
168 | err |= __put_user(regs->rdi, &sc->rdi); | 168 | err |= __put_user(regs->di, &sc->di); |
169 | err |= __put_user(regs->rsi, &sc->rsi); | 169 | err |= __put_user(regs->si, &sc->si); |
170 | err |= __put_user(regs->rbp, &sc->rbp); | 170 | err |= __put_user(regs->bp, &sc->bp); |
171 | err |= __put_user(regs->rsp, &sc->rsp); | 171 | err |= __put_user(regs->sp, &sc->sp); |
172 | err |= __put_user(regs->rbx, &sc->rbx); | 172 | err |= __put_user(regs->bx, &sc->bx); |
173 | err |= __put_user(regs->rdx, &sc->rdx); | 173 | err |= __put_user(regs->dx, &sc->dx); |
174 | err |= __put_user(regs->rcx, &sc->rcx); | 174 | err |= __put_user(regs->cx, &sc->cx); |
175 | err |= __put_user(regs->rax, &sc->rax); | 175 | err |= __put_user(regs->ax, &sc->ax); |
176 | err |= __put_user(regs->r8, &sc->r8); | 176 | err |= __put_user(regs->r8, &sc->r8); |
177 | err |= __put_user(regs->r9, &sc->r9); | 177 | err |= __put_user(regs->r9, &sc->r9); |
178 | err |= __put_user(regs->r10, &sc->r10); | 178 | err |= __put_user(regs->r10, &sc->r10); |
@@ -183,8 +183,8 @@ setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, unsigned lo | |||
183 | err |= __put_user(regs->r15, &sc->r15); | 183 | err |= __put_user(regs->r15, &sc->r15); |
184 | err |= __put_user(me->thread.trap_no, &sc->trapno); | 184 | err |= __put_user(me->thread.trap_no, &sc->trapno); |
185 | err |= __put_user(me->thread.error_code, &sc->err); | 185 | err |= __put_user(me->thread.error_code, &sc->err); |
186 | err |= __put_user(regs->rip, &sc->rip); | 186 | err |= __put_user(regs->ip, &sc->ip); |
187 | err |= __put_user(regs->eflags, &sc->eflags); | 187 | err |= __put_user(regs->flags, &sc->flags); |
188 | err |= __put_user(mask, &sc->oldmask); | 188 | err |= __put_user(mask, &sc->oldmask); |
189 | err |= __put_user(me->thread.cr2, &sc->cr2); | 189 | err |= __put_user(me->thread.cr2, &sc->cr2); |
190 | 190 | ||
@@ -198,18 +198,18 @@ setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, unsigned lo | |||
198 | static void __user * | 198 | static void __user * |
199 | get_stack(struct k_sigaction *ka, struct pt_regs *regs, unsigned long size) | 199 | get_stack(struct k_sigaction *ka, struct pt_regs *regs, unsigned long size) |
200 | { | 200 | { |
201 | unsigned long rsp; | 201 | unsigned long sp; |
202 | 202 | ||
203 | /* Default to using normal stack - redzone*/ | 203 | /* Default to using normal stack - redzone*/ |
204 | rsp = regs->rsp - 128; | 204 | sp = regs->sp - 128; |
205 | 205 | ||
206 | /* This is the X/Open sanctioned signal stack switching. */ | 206 | /* This is the X/Open sanctioned signal stack switching. */ |
207 | if (ka->sa.sa_flags & SA_ONSTACK) { | 207 | if (ka->sa.sa_flags & SA_ONSTACK) { |
208 | if (sas_ss_flags(rsp) == 0) | 208 | if (sas_ss_flags(sp) == 0) |
209 | rsp = current->sas_ss_sp + current->sas_ss_size; | 209 | sp = current->sas_ss_sp + current->sas_ss_size; |
210 | } | 210 | } |
211 | 211 | ||
212 | return (void __user *)round_down(rsp - size, 16); | 212 | return (void __user *)round_down(sp - size, 16); |
213 | } | 213 | } |
214 | 214 | ||
215 | static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, | 215 | static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
@@ -246,7 +246,7 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, | |||
246 | err |= __put_user(0, &frame->uc.uc_flags); | 246 | err |= __put_user(0, &frame->uc.uc_flags); |
247 | err |= __put_user(0, &frame->uc.uc_link); | 247 | err |= __put_user(0, &frame->uc.uc_link); |
248 | err |= __put_user(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp); | 248 | err |= __put_user(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp); |
249 | err |= __put_user(sas_ss_flags(regs->rsp), | 249 | err |= __put_user(sas_ss_flags(regs->sp), |
250 | &frame->uc.uc_stack.ss_flags); | 250 | &frame->uc.uc_stack.ss_flags); |
251 | err |= __put_user(me->sas_ss_size, &frame->uc.uc_stack.ss_size); | 251 | err |= __put_user(me->sas_ss_size, &frame->uc.uc_stack.ss_size); |
252 | err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0], me); | 252 | err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0], me); |
@@ -271,21 +271,21 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, | |||
271 | goto give_sigsegv; | 271 | goto give_sigsegv; |
272 | 272 | ||
273 | #ifdef DEBUG_SIG | 273 | #ifdef DEBUG_SIG |
274 | printk("%d old rip %lx old rsp %lx old rax %lx\n", current->pid,regs->rip,regs->rsp,regs->rax); | 274 | printk("%d old ip %lx old sp %lx old ax %lx\n", current->pid,regs->ip,regs->sp,regs->ax); |
275 | #endif | 275 | #endif |
276 | 276 | ||
277 | /* Set up registers for signal handler */ | 277 | /* Set up registers for signal handler */ |
278 | regs->rdi = sig; | 278 | regs->di = sig; |
279 | /* In case the signal handler was declared without prototypes */ | 279 | /* In case the signal handler was declared without prototypes */ |
280 | regs->rax = 0; | 280 | regs->ax = 0; |
281 | 281 | ||
282 | /* This also works for non SA_SIGINFO handlers because they expect the | 282 | /* This also works for non SA_SIGINFO handlers because they expect the |
283 | next argument after the signal number on the stack. */ | 283 | next argument after the signal number on the stack. */ |
284 | regs->rsi = (unsigned long)&frame->info; | 284 | regs->si = (unsigned long)&frame->info; |
285 | regs->rdx = (unsigned long)&frame->uc; | 285 | regs->dx = (unsigned long)&frame->uc; |
286 | regs->rip = (unsigned long) ka->sa.sa_handler; | 286 | regs->ip = (unsigned long) ka->sa.sa_handler; |
287 | 287 | ||
288 | regs->rsp = (unsigned long)frame; | 288 | regs->sp = (unsigned long)frame; |
289 | 289 | ||
290 | /* Set up the CS register to run signal handlers in 64-bit mode, | 290 | /* Set up the CS register to run signal handlers in 64-bit mode, |
291 | even if the handler happens to be interrupting 32-bit code. */ | 291 | even if the handler happens to be interrupting 32-bit code. */ |
@@ -295,12 +295,12 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, | |||
295 | see include/asm-x86_64/uaccess.h for details. */ | 295 | see include/asm-x86_64/uaccess.h for details. */ |
296 | set_fs(USER_DS); | 296 | set_fs(USER_DS); |
297 | 297 | ||
298 | regs->eflags &= ~TF_MASK; | 298 | regs->flags &= ~X86_EFLAGS_TF; |
299 | if (test_thread_flag(TIF_SINGLESTEP)) | 299 | if (test_thread_flag(TIF_SINGLESTEP)) |
300 | ptrace_notify(SIGTRAP); | 300 | ptrace_notify(SIGTRAP); |
301 | #ifdef DEBUG_SIG | 301 | #ifdef DEBUG_SIG |
302 | printk("SIG deliver (%s:%d): sp=%p pc=%lx ra=%p\n", | 302 | printk("SIG deliver (%s:%d): sp=%p pc=%lx ra=%p\n", |
303 | current->comm, current->pid, frame, regs->rip, frame->pretcode); | 303 | current->comm, current->pid, frame, regs->ip, frame->pretcode); |
304 | #endif | 304 | #endif |
305 | 305 | ||
306 | return 0; | 306 | return 0; |
@@ -321,44 +321,40 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, | |||
321 | int ret; | 321 | int ret; |
322 | 322 | ||
323 | #ifdef DEBUG_SIG | 323 | #ifdef DEBUG_SIG |
324 | printk("handle_signal pid:%d sig:%lu rip:%lx rsp:%lx regs=%p\n", | 324 | printk("handle_signal pid:%d sig:%lu ip:%lx sp:%lx regs=%p\n", |
325 | current->pid, sig, | 325 | current->pid, sig, |
326 | regs->rip, regs->rsp, regs); | 326 | regs->ip, regs->sp, regs); |
327 | #endif | 327 | #endif |
328 | 328 | ||
329 | /* Are we from a system call? */ | 329 | /* Are we from a system call? */ |
330 | if ((long)regs->orig_rax >= 0) { | 330 | if ((long)regs->orig_ax >= 0) { |
331 | /* If so, check system call restarting.. */ | 331 | /* If so, check system call restarting.. */ |
332 | switch (regs->rax) { | 332 | switch (regs->ax) { |
333 | case -ERESTART_RESTARTBLOCK: | 333 | case -ERESTART_RESTARTBLOCK: |
334 | case -ERESTARTNOHAND: | 334 | case -ERESTARTNOHAND: |
335 | regs->rax = -EINTR; | 335 | regs->ax = -EINTR; |
336 | break; | 336 | break; |
337 | 337 | ||
338 | case -ERESTARTSYS: | 338 | case -ERESTARTSYS: |
339 | if (!(ka->sa.sa_flags & SA_RESTART)) { | 339 | if (!(ka->sa.sa_flags & SA_RESTART)) { |
340 | regs->rax = -EINTR; | 340 | regs->ax = -EINTR; |
341 | break; | 341 | break; |
342 | } | 342 | } |
343 | /* fallthrough */ | 343 | /* fallthrough */ |
344 | case -ERESTARTNOINTR: | 344 | case -ERESTARTNOINTR: |
345 | regs->rax = regs->orig_rax; | 345 | regs->ax = regs->orig_ax; |
346 | regs->rip -= 2; | 346 | regs->ip -= 2; |
347 | break; | 347 | break; |
348 | } | 348 | } |
349 | } | 349 | } |
350 | 350 | ||
351 | /* | 351 | /* |
352 | * If TF is set due to a debugger (PT_DTRACE), clear the TF | 352 | * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF |
353 | * flag so that register information in the sigcontext is | 353 | * flag so that register information in the sigcontext is correct. |
354 | * correct. | ||
355 | */ | 354 | */ |
356 | if (unlikely(regs->eflags & TF_MASK)) { | 355 | if (unlikely(regs->flags & X86_EFLAGS_TF) && |
357 | if (likely(current->ptrace & PT_DTRACE)) { | 356 | likely(test_and_clear_thread_flag(TIF_FORCED_TF))) |
358 | current->ptrace &= ~PT_DTRACE; | 357 | regs->flags &= ~X86_EFLAGS_TF; |
359 | regs->eflags &= ~TF_MASK; | ||
360 | } | ||
361 | } | ||
362 | 358 | ||
363 | #ifdef CONFIG_IA32_EMULATION | 359 | #ifdef CONFIG_IA32_EMULATION |
364 | if (test_thread_flag(TIF_IA32)) { | 360 | if (test_thread_flag(TIF_IA32)) { |
@@ -430,21 +426,21 @@ static void do_signal(struct pt_regs *regs) | |||
430 | } | 426 | } |
431 | 427 | ||
432 | /* Did we come from a system call? */ | 428 | /* Did we come from a system call? */ |
433 | if ((long)regs->orig_rax >= 0) { | 429 | if ((long)regs->orig_ax >= 0) { |
434 | /* Restart the system call - no handlers present */ | 430 | /* Restart the system call - no handlers present */ |
435 | long res = regs->rax; | 431 | long res = regs->ax; |
436 | switch (res) { | 432 | switch (res) { |
437 | case -ERESTARTNOHAND: | 433 | case -ERESTARTNOHAND: |
438 | case -ERESTARTSYS: | 434 | case -ERESTARTSYS: |
439 | case -ERESTARTNOINTR: | 435 | case -ERESTARTNOINTR: |
440 | regs->rax = regs->orig_rax; | 436 | regs->ax = regs->orig_ax; |
441 | regs->rip -= 2; | 437 | regs->ip -= 2; |
442 | break; | 438 | break; |
443 | case -ERESTART_RESTARTBLOCK: | 439 | case -ERESTART_RESTARTBLOCK: |
444 | regs->rax = test_thread_flag(TIF_IA32) ? | 440 | regs->ax = test_thread_flag(TIF_IA32) ? |
445 | __NR_ia32_restart_syscall : | 441 | __NR_ia32_restart_syscall : |
446 | __NR_restart_syscall; | 442 | __NR_restart_syscall; |
447 | regs->rip -= 2; | 443 | regs->ip -= 2; |
448 | break; | 444 | break; |
449 | } | 445 | } |
450 | } | 446 | } |
@@ -461,13 +457,13 @@ void | |||
461 | do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags) | 457 | do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags) |
462 | { | 458 | { |
463 | #ifdef DEBUG_SIG | 459 | #ifdef DEBUG_SIG |
464 | printk("do_notify_resume flags:%x rip:%lx rsp:%lx caller:%p pending:%x\n", | 460 | printk("do_notify_resume flags:%x ip:%lx sp:%lx caller:%p pending:%x\n", |
465 | thread_info_flags, regs->rip, regs->rsp, __builtin_return_address(0),signal_pending(current)); | 461 | thread_info_flags, regs->ip, regs->sp, __builtin_return_address(0),signal_pending(current)); |
466 | #endif | 462 | #endif |
467 | 463 | ||
468 | /* Pending single-step? */ | 464 | /* Pending single-step? */ |
469 | if (thread_info_flags & _TIF_SINGLESTEP) { | 465 | if (thread_info_flags & _TIF_SINGLESTEP) { |
470 | regs->eflags |= TF_MASK; | 466 | regs->flags |= X86_EFLAGS_TF; |
471 | clear_thread_flag(TIF_SINGLESTEP); | 467 | clear_thread_flag(TIF_SINGLESTEP); |
472 | } | 468 | } |
473 | 469 | ||
@@ -488,9 +484,12 @@ do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags) | |||
488 | void signal_fault(struct pt_regs *regs, void __user *frame, char *where) | 484 | void signal_fault(struct pt_regs *regs, void __user *frame, char *where) |
489 | { | 485 | { |
490 | struct task_struct *me = current; | 486 | struct task_struct *me = current; |
491 | if (show_unhandled_signals && printk_ratelimit()) | 487 | if (show_unhandled_signals && printk_ratelimit()) { |
492 | printk("%s[%d] bad frame in %s frame:%p rip:%lx rsp:%lx orax:%lx\n", | 488 | printk("%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx", |
493 | me->comm,me->pid,where,frame,regs->rip,regs->rsp,regs->orig_rax); | 489 | me->comm,me->pid,where,frame,regs->ip,regs->sp,regs->orig_ax); |
490 | print_vma_addr(" in ", regs->ip); | ||
491 | printk("\n"); | ||
492 | } | ||
494 | 493 | ||
495 | force_sig(SIGSEGV, me); | 494 | force_sig(SIGSEGV, me); |
496 | } | 495 | } |