diff options
-rw-r--r-- | arch/x86/kernel/kprobes.c | 128 |
1 files changed, 67 insertions, 61 deletions
diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c index c69bb65006f3..4ae95befd0eb 100644 --- a/arch/x86/kernel/kprobes.c +++ b/arch/x86/kernel/kprobes.c | |||
@@ -554,6 +554,69 @@ static int __kprobes kprobe_handler(struct pt_regs *regs) | |||
554 | return 0; | 554 | return 0; |
555 | } | 555 | } |
556 | 556 | ||
557 | #ifdef CONFIG_X86_64 | ||
558 | #define SAVE_REGS_STRING \ | ||
559 | /* Skip cs, ip, orig_ax. */ \ | ||
560 | " subq $24, %rsp\n" \ | ||
561 | " pushq %rdi\n" \ | ||
562 | " pushq %rsi\n" \ | ||
563 | " pushq %rdx\n" \ | ||
564 | " pushq %rcx\n" \ | ||
565 | " pushq %rax\n" \ | ||
566 | " pushq %r8\n" \ | ||
567 | " pushq %r9\n" \ | ||
568 | " pushq %r10\n" \ | ||
569 | " pushq %r11\n" \ | ||
570 | " pushq %rbx\n" \ | ||
571 | " pushq %rbp\n" \ | ||
572 | " pushq %r12\n" \ | ||
573 | " pushq %r13\n" \ | ||
574 | " pushq %r14\n" \ | ||
575 | " pushq %r15\n" | ||
576 | #define RESTORE_REGS_STRING \ | ||
577 | " popq %r15\n" \ | ||
578 | " popq %r14\n" \ | ||
579 | " popq %r13\n" \ | ||
580 | " popq %r12\n" \ | ||
581 | " popq %rbp\n" \ | ||
582 | " popq %rbx\n" \ | ||
583 | " popq %r11\n" \ | ||
584 | " popq %r10\n" \ | ||
585 | " popq %r9\n" \ | ||
586 | " popq %r8\n" \ | ||
587 | " popq %rax\n" \ | ||
588 | " popq %rcx\n" \ | ||
589 | " popq %rdx\n" \ | ||
590 | " popq %rsi\n" \ | ||
591 | " popq %rdi\n" \ | ||
592 | /* Skip orig_ax, ip, cs */ \ | ||
593 | " addq $24, %rsp\n" | ||
594 | #else | ||
595 | #define SAVE_REGS_STRING \ | ||
596 | /* Skip cs, ip, orig_ax and gs. */ \ | ||
597 | " subl $16, %esp\n" \ | ||
598 | " pushl %fs\n" \ | ||
599 | " pushl %ds\n" \ | ||
600 | " pushl %es\n" \ | ||
601 | " pushl %eax\n" \ | ||
602 | " pushl %ebp\n" \ | ||
603 | " pushl %edi\n" \ | ||
604 | " pushl %esi\n" \ | ||
605 | " pushl %edx\n" \ | ||
606 | " pushl %ecx\n" \ | ||
607 | " pushl %ebx\n" | ||
608 | #define RESTORE_REGS_STRING \ | ||
609 | " popl %ebx\n" \ | ||
610 | " popl %ecx\n" \ | ||
611 | " popl %edx\n" \ | ||
612 | " popl %esi\n" \ | ||
613 | " popl %edi\n" \ | ||
614 | " popl %ebp\n" \ | ||
615 | " popl %eax\n" \ | ||
616 | /* Skip ds, es, fs, gs, orig_ax, and ip. Note: don't pop cs here*/\ | ||
617 | " addl $24, %esp\n" | ||
618 | #endif | ||
619 | |||
557 | /* | 620 | /* |
558 | * When a retprobed function returns, this code saves registers and | 621 | * When a retprobed function returns, this code saves registers and |
559 | * calls trampoline_handler() runs, which calls the kretprobe's handler. | 622 | * calls trampoline_handler() runs, which calls the kretprobe's handler. |
@@ -567,65 +630,16 @@ static void __used __kprobes kretprobe_trampoline_holder(void) | |||
567 | /* We don't bother saving the ss register */ | 630 | /* We don't bother saving the ss register */ |
568 | " pushq %rsp\n" | 631 | " pushq %rsp\n" |
569 | " pushfq\n" | 632 | " pushfq\n" |
570 | /* | 633 | SAVE_REGS_STRING |
571 | * Skip cs, ip, orig_ax. | ||
572 | * trampoline_handler() will plug in these values | ||
573 | */ | ||
574 | " subq $24, %rsp\n" | ||
575 | " pushq %rdi\n" | ||
576 | " pushq %rsi\n" | ||
577 | " pushq %rdx\n" | ||
578 | " pushq %rcx\n" | ||
579 | " pushq %rax\n" | ||
580 | " pushq %r8\n" | ||
581 | " pushq %r9\n" | ||
582 | " pushq %r10\n" | ||
583 | " pushq %r11\n" | ||
584 | " pushq %rbx\n" | ||
585 | " pushq %rbp\n" | ||
586 | " pushq %r12\n" | ||
587 | " pushq %r13\n" | ||
588 | " pushq %r14\n" | ||
589 | " pushq %r15\n" | ||
590 | " movq %rsp, %rdi\n" | 634 | " movq %rsp, %rdi\n" |
591 | " call trampoline_handler\n" | 635 | " call trampoline_handler\n" |
592 | /* Replace saved sp with true return address. */ | 636 | /* Replace saved sp with true return address. */ |
593 | " movq %rax, 152(%rsp)\n" | 637 | " movq %rax, 152(%rsp)\n" |
594 | " popq %r15\n" | 638 | RESTORE_REGS_STRING |
595 | " popq %r14\n" | ||
596 | " popq %r13\n" | ||
597 | " popq %r12\n" | ||
598 | " popq %rbp\n" | ||
599 | " popq %rbx\n" | ||
600 | " popq %r11\n" | ||
601 | " popq %r10\n" | ||
602 | " popq %r9\n" | ||
603 | " popq %r8\n" | ||
604 | " popq %rax\n" | ||
605 | " popq %rcx\n" | ||
606 | " popq %rdx\n" | ||
607 | " popq %rsi\n" | ||
608 | " popq %rdi\n" | ||
609 | /* Skip orig_ax, ip, cs */ | ||
610 | " addq $24, %rsp\n" | ||
611 | " popfq\n" | 639 | " popfq\n" |
612 | #else | 640 | #else |
613 | " pushf\n" | 641 | " pushf\n" |
614 | /* | 642 | SAVE_REGS_STRING |
615 | * Skip cs, ip, orig_ax and gs. | ||
616 | * trampoline_handler() will plug in these values | ||
617 | */ | ||
618 | " subl $16, %esp\n" | ||
619 | " pushl %fs\n" | ||
620 | " pushl %es\n" | ||
621 | " pushl %ds\n" | ||
622 | " pushl %eax\n" | ||
623 | " pushl %ebp\n" | ||
624 | " pushl %edi\n" | ||
625 | " pushl %esi\n" | ||
626 | " pushl %edx\n" | ||
627 | " pushl %ecx\n" | ||
628 | " pushl %ebx\n" | ||
629 | " movl %esp, %eax\n" | 643 | " movl %esp, %eax\n" |
630 | " call trampoline_handler\n" | 644 | " call trampoline_handler\n" |
631 | /* Move flags to cs */ | 645 | /* Move flags to cs */ |
@@ -633,15 +647,7 @@ static void __used __kprobes kretprobe_trampoline_holder(void) | |||
633 | " movl %edx, 52(%esp)\n" | 647 | " movl %edx, 52(%esp)\n" |
634 | /* Replace saved flags with true return address. */ | 648 | /* Replace saved flags with true return address. */ |
635 | " movl %eax, 56(%esp)\n" | 649 | " movl %eax, 56(%esp)\n" |
636 | " popl %ebx\n" | 650 | RESTORE_REGS_STRING |
637 | " popl %ecx\n" | ||
638 | " popl %edx\n" | ||
639 | " popl %esi\n" | ||
640 | " popl %edi\n" | ||
641 | " popl %ebp\n" | ||
642 | " popl %eax\n" | ||
643 | /* Skip ds, es, fs, gs, orig_ax and ip */ | ||
644 | " addl $24, %esp\n" | ||
645 | " popf\n" | 651 | " popf\n" |
646 | #endif | 652 | #endif |
647 | " ret\n"); | 653 | " ret\n"); |