diff options
author | Borislav Petkov <bp@suse.de> | 2018-04-17 12:11:19 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2018-04-26 10:15:26 -0400 |
commit | 9e4a90fd34445df64a13d136676a31a4dd22aea3 (patch) | |
tree | a96285cddfc8bdaba453443ab9bfb7a4b1c5c6fb | |
parent | f0a1d7c11c3ebe2f601b448d13e7fbc3a0364a03 (diff) |
x86/dumpstack: Improve opcodes dumping in the code section
The code used to iterate byte-by-byte over the bytes around RIP and that
is expensive: disabling pagefaults around it, copy_from_user, etc...
Make it read the whole buffer of OPCODE_BUFSIZE size in one go. Use a
statically allocated 64 bytes buffer so that concurrent show_opcodes()
do not interleave in the output even though in the majority of the cases
it's serialized via die_lock. Except the #PF path which doesn't...
Also, do the PAGE_OFFSET check outside of the function because latter
will be reused in other context.
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Link: https://lkml.kernel.org/r/20180417161124.5294-5-bp@alien8.de
-rw-r--r-- | arch/x86/kernel/dumpstack.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c index eb9d6c00a52f..1d6698b54527 100644 --- a/arch/x86/kernel/dumpstack.c +++ b/arch/x86/kernel/dumpstack.c | |||
@@ -72,29 +72,24 @@ static void printk_stack_address(unsigned long address, int reliable, | |||
72 | 72 | ||
73 | static void show_opcodes(u8 *rip) | 73 | static void show_opcodes(u8 *rip) |
74 | { | 74 | { |
75 | unsigned int code_prologue = OPCODE_BUFSIZE * 43 / 64; | 75 | unsigned int code_prologue = OPCODE_BUFSIZE * 2 / 3; |
76 | unsigned int code_len = OPCODE_BUFSIZE; | 76 | u8 opcodes[OPCODE_BUFSIZE]; |
77 | unsigned char c; | ||
78 | u8 *ip; | 77 | u8 *ip; |
79 | int i; | 78 | int i; |
80 | 79 | ||
81 | printk(KERN_DEFAULT "Code: "); | 80 | printk(KERN_DEFAULT "Code: "); |
82 | 81 | ||
83 | ip = (u8 *)rip - code_prologue; | 82 | ip = (u8 *)rip - code_prologue; |
84 | if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) { | 83 | if (probe_kernel_read(opcodes, ip, OPCODE_BUFSIZE)) { |
85 | /* try starting at IP */ | 84 | pr_cont("Bad RIP value.\n"); |
86 | ip = (u8 *)rip; | 85 | return; |
87 | code_len = code_len - code_prologue + 1; | ||
88 | } | 86 | } |
89 | for (i = 0; i < code_len; i++, ip++) { | 87 | |
90 | if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) { | 88 | for (i = 0; i < OPCODE_BUFSIZE; i++, ip++) { |
91 | pr_cont(" Bad RIP value."); | 89 | if (ip == rip) |
92 | break; | 90 | pr_cont("<%02x> ", opcodes[i]); |
93 | } | ||
94 | if (ip == (u8 *)rip) | ||
95 | pr_cont("<%02x> ", c); | ||
96 | else | 91 | else |
97 | pr_cont("%02x ", c); | 92 | pr_cont("%02x ", opcodes[i]); |
98 | } | 93 | } |
99 | pr_cont("\n"); | 94 | pr_cont("\n"); |
100 | } | 95 | } |
@@ -402,6 +397,10 @@ void show_regs(struct pt_regs *regs) | |||
402 | */ | 397 | */ |
403 | if (!user_mode(regs)) { | 398 | if (!user_mode(regs)) { |
404 | show_trace_log_lvl(current, regs, NULL, KERN_DEFAULT); | 399 | show_trace_log_lvl(current, regs, NULL, KERN_DEFAULT); |
405 | show_opcodes((u8 *)regs->ip); | 400 | |
401 | if (regs->ip < PAGE_OFFSET) | ||
402 | printk(KERN_DEFAULT "Code: Bad RIP value.\n"); | ||
403 | else | ||
404 | show_opcodes((u8 *)regs->ip); | ||
406 | } | 405 | } |
407 | } | 406 | } |