From: Jann Horn <jannh@google.com>
To: Thomas Gleixner <tglx@linutronix.de>, jannh@google.com
Cc: linux-kernel@vger.kernel.org, Kees Cook <keescook@chromium.org>,
Borislav Petkov <bp@suse.de>,
x86@kernel.org, Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH v2] x86/dumpstack: fix address space casting in show_opcodes()
Date: Fri, 31 Aug 2018 15:51:52 +0200 [thread overview]
Message-ID: <20180831135152.171747-1-jannh@google.com> (raw)
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")
Signed-off-by: Jann Horn <jannh@google.com>
---
arch/x86/kernel/dumpstack.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
index 605c60b1624f..f56895106ccf 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);
+ 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> %"
--
2.19.0.rc1.350.ge57e33dbd1-goog
reply other threads:[~2018-08-31 13:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180831135152.171747-1-jannh@google.com \
--to=jannh@google.com \
--cc=bp@suse.de \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luc.vanoostenryck@gmail.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).