mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/dumpstack: fix address space casting in show_opcodes()
@ 2018-08-30 19:47 Jann Horn
  2018-08-31  8:04 ` Borislav Petkov
  2018-08-31  8:27 ` Luc Van Oostenryck
  0 siblings, 2 replies; 5+ messages in thread
From: Jann Horn @ 2018-08-30 19:47 UTC (permalink / raw)
  To: Thomas Gleixner, jannh; +Cc: linux-kernel, Kees Cook, Borislav Petkov

I sloppily passed a kernel-typed pointer to __range_not_ok(), and sparse
doesn't like that.
Make `prologue` a __user pointer (to protect against accidental
dereferences) and force-cast it to a kernel pointer when calling
probe_kernel_read(), which will then immediately force-cast it back to a
user pointer.

Fixes: a644cf538b11 ("x86/dumpstack: Don't dump kernel memory based on usermode RIP")
Signed-off-by: Jann Horn <jannh@google.com>
---
 arch/x86/kernel/dumpstack.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
index 605c60b1624f..651aed36291a 100644
--- a/arch/x86/kernel/dumpstack.c
+++ b/arch/x86/kernel/dumpstack.c
@@ -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);
+	u8 __user *prologue = (u8 __user *)(regs->ip - PROLOGUE_SIZE);
 	bool bad_ip;
 
 	/*
@@ -106,7 +106,8 @@ void show_opcodes(struct pt_regs *regs, const char *loglvl)
 	bad_ip = user_mode(regs) &&
 		__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, (__force u8 *)prologue,
+					OPCODE_BUFSIZE)) {
 		printk("%sCode: Bad RIP value.\n", loglvl);
 	} else {
 		printk("%sCode: %" __stringify(PROLOGUE_SIZE) "ph <%02x> %"
-- 
2.19.0.rc0.228.g281dcd1b4d0-goog


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-08-31 14:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-30 19:47 [PATCH] x86/dumpstack: fix address space casting in show_opcodes() Jann Horn
2018-08-31  8:04 ` Borislav Petkov
2018-08-31  8:27 ` Luc Van Oostenryck
2018-08-31 13:26   ` Jann Horn
2018-08-31 14:38     ` Luc Van Oostenryck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®