From: Jia He <justin.he@arm.com>
To: Petr Mladek <pmladek@suse.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>
Cc: "Steven Rostedt (VMware)" <rostedt@goodmis.org>,
Kees Cook <keescook@chromium.org>, Shuah Khan <shuah@kernel.org>,
"Tobin C. Harding" <tobin@kernel.org>, Jia He <justin.he@arm.com>
Subject: [PATCH 1/2] vsprintf: Prevent crash when dereferencing invalid pointers for %pD
Date: Fri, 9 Aug 2019 09:24:56 +0800 [thread overview]
Message-ID: <20190809012457.56685-1-justin.he@arm.com> (raw)
Commit 3e5903eb9cff ("vsprintf: Prevent crash when dereferencing invalid
pointers") prevents most crash except for %pD.
There is an additional pointer dereferencing before dentry_name.
At least, vma->file can be NULL and be passed to printk %pD in
print_bad_pte, which can cause crash.
This patch fixes it with introducing a new file_dentry_name.
Signed-off-by: Jia He <justin.he@arm.com>
---
lib/vsprintf.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 63937044c57d..b4a119176fdb 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -869,6 +869,15 @@ char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_sp
return widen_string(buf, n, end, spec);
}
+static noinline_for_stack
+char *file_dentry_name(char *buf, char *end, const struct file *f,
+ struct printf_spec spec, const char *fmt)
+{
+ if (check_pointer(&buf, end, f, spec))
+ return buf;
+
+ return dentry_name(buf, end, f->f_path.dentry, spec, fmt);
+}
#ifdef CONFIG_BLOCK
static noinline_for_stack
char *bdev_name(char *buf, char *end, struct block_device *bdev,
@@ -2166,9 +2175,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
case 'C':
return clock(buf, end, ptr, spec, fmt);
case 'D':
- return dentry_name(buf, end,
- ((const struct file *)ptr)->f_path.dentry,
- spec, fmt);
+ return file_dentry_name(buf, end, ptr, spec, fmt);
#ifdef CONFIG_BLOCK
case 'g':
return bdev_name(buf, end, ptr, spec, fmt);
--
2.17.1
next reply other threads:[~2019-08-09 1:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-09 1:24 Jia He [this message]
2019-08-09 1:24 ` [PATCH 2/2] lib/test_printf: add test of null/invalid pointer dereference for dentry Jia He
2019-08-09 10:51 ` Andy Shevchenko
2019-08-16 8:26 ` Petr Mladek
2019-08-16 8:31 ` Justin He (Arm Technology China)
2019-08-09 10:51 ` [PATCH 1/2] vsprintf: Prevent crash when dereferencing invalid pointers for %pD Andy Shevchenko
2019-08-09 10:56 ` Justin He (Arm Technology China)
2019-08-16 8:20 ` Petr Mladek
2019-08-15 7:52 ` Sergey Senozhatsky
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=20190809012457.56685-1-justin.he@arm.com \
--to=justin.he@arm.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=geert+renesas@glider.be \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky@gmail.com \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
--cc=tobin@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
all inboxes | Powered by JetHome®