Skip to contentSkip to conversation

x86/dumpstack: fix address space casting in show_opcodes()

PATCH New Jann Horn 1 participant 1 message Aug 31, 2018

Subsystems (2)
lore
Share & tools
lore

Jann Horn

author
#0 lore raw

PATCH v2 1/1 x86/dumpstack: fix address space casting in show_opcodes()

I sloppily passed a kernel-typed pointer to __range_not_ok(), and sparse doesn't like that.
Make prologue an unsigned long and cast it to a kernel pointer when calling probe_kernel_read(), just like ~everyone else who calls probe_kernel_read().
Instead of __range_not_ok() with a cast, call __chk_range_not_ok directly.

Fixes a644cf538b11 ("x86/dumpstack: Don't dump kernel memory based on usermode RIP")
---
 arch/x86/kernel/dumpstack.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/x86/kernel/dumpstack.c +4 -3
index 605c60b1624f..f56895106ccf 100644
@@ -96,7 +96,7 @@ void show_opcodes(struct pt_regs *regs, const char *loglvl)
 #define EPILOGUE_SIZE 21
 #define OPCODE_BUFSIZE (PROLOGUE_SIZE + 1 + EPILOGUE_SIZE)
 	u8 opcodes[OPCODE_BUFSIZE];
-	u8 *prologue = (u8 *)(regs->ip - PROLOGUE_SIZE);
+	unsigned long prologue = regs->ip - PROLOGUE_SIZE;
 	bool bad_ip;
 
 	/*
@@ -104,9 +104,10 @@ void show_opcodes(struct pt_regs *regs, const char *loglvl)
 	 * memory by pointing the userspace instruction pointer at it.
 	 */
 	bad_ip = user_mode(regs) &&
-		__range_not_ok(prologue, OPCODE_BUFSIZE, TASK_SIZE_MAX);
+		__chk_range_not_ok(prologue, OPCODE_BUFSIZE, TASK_SIZE_MAX);
 
-	if (bad_ip || probe_kernel_read(opcodes, prologue, OPCODE_BUFSIZE)) {
+	if (bad_ip || probe_kernel_read(opcodes, (u8 *)prologue,
+					OPCODE_BUFSIZE)) {
 		printk("%sCode: Bad RIP value.\n", loglvl);
 	} else {
 		printk("%sCode: %" __stringify(PROLOGUE_SIZE) "ph <%02x> %"
Signature · 1 line
2.19.0.rc1.350.ge57e33dbd1-goog