aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kernel
diff options
context:
space:
mode:
authorMichael Ellerman <mpe@ellerman.id.au>2018-10-05 02:43:55 -0400
committerMichael Ellerman <mpe@ellerman.id.au>2018-10-05 09:18:12 -0400
commita932ed3b718147c6537da290b7a91e990fdedb43 (patch)
tree9b0f53e526e5ef0b85a8b82ef58b0469da3e6a4b /arch/powerpc/kernel
parentb45ba4a51cde29b2939365ef0c07ad34c8321789 (diff)
powerpc: Don't print kernel instructions in show_user_instructions()
Recently we implemented show_user_instructions() which dumps the code around the NIP when a user space process dies with an unhandled signal. This was modelled on the x86 code, and we even went so far as to implement the exact same bug, namely that if the user process crashed with its NIP pointing into the kernel we will dump kernel text to dmesg. eg: bad-bctr[2996]: segfault (11) at c000000000010000 nip c000000000010000 lr 12d0b0894 code 1 bad-bctr[2996]: code: fbe10068 7cbe2b78 7c7f1b78 fb610048 38a10028 38810020 fb810050 7f8802a6 bad-bctr[2996]: code: 3860001c f8010080 48242371 60000000 <7c7b1b79> 4082002c e8010080 eb610048 This was discovered on x86 by Jann Horn and fixed in commit 342db04ae712 ("x86/dumpstack: Don't dump kernel memory based on usermode RIP"). Fix it by checking the adjusted NIP value (pc) and number of instructions against USER_DS, and bail if we fail the check, eg: bad-bctr[2969]: segfault (11) at c000000000010000 nip c000000000010000 lr 107930894 code 1 bad-bctr[2969]: Bad NIP, not dumping instructions. Fixes: 88b0fe175735 ("powerpc: Add show_user_instructions()") Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'arch/powerpc/kernel')
-rw-r--r--arch/powerpc/kernel/process.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 913c5725cdb2..bb6ac471a784 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -1306,6 +1306,16 @@ void show_user_instructions(struct pt_regs *regs)
1306 1306
1307 pc = regs->nip - (instructions_to_print * 3 / 4 * sizeof(int)); 1307 pc = regs->nip - (instructions_to_print * 3 / 4 * sizeof(int));
1308 1308
1309 /*
1310 * Make sure the NIP points at userspace, not kernel text/data or
1311 * elsewhere.
1312 */
1313 if (!__access_ok(pc, instructions_to_print * sizeof(int), USER_DS)) {
1314 pr_info("%s[%d]: Bad NIP, not dumping instructions.\n",
1315 current->comm, current->pid);
1316 return;
1317 }
1318
1309 pr_info("%s[%d]: code: ", current->comm, current->pid); 1319 pr_info("%s[%d]: code: ", current->comm, current->pid);
1310 1320
1311 for (i = 0; i < instructions_to_print; i++) { 1321 for (i = 0; i < instructions_to_print; i++) {