From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Frederic Weisbecker <fweisbec@gmail.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>
Subject: [RFC][PATCH 2/3] vsprintf: Add support for %pf and %pF to vbin_printf()
Date: Wed, 29 Jun 2016 16:05:24 -0400 [thread overview]
Message-ID: <20160629201224.546349056@goodmis.org> (raw)
In-Reply-To: 20160629200522.686965980@goodmis.org
[-- Attachment #1: 0002-vsprintf-Add-support-for-pf-and-pF-to-vbin_printf.patch --]
[-- Type: text/plain, Size: 2127 bytes --]
From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
Some architectures require a dereference of function pointers (See powerpc).
The dereferenced poiner must be saved into the buffer in vbin_printf() to be
safe to access it later.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
lib/vsprintf.c | 44 ++++++++++++++++++++++++++++++++------------
1 file changed, 32 insertions(+), 12 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index b2a331d948a2..1eb4c7bc3509 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -2271,15 +2271,6 @@ static bool supported_bin_ptr(const char *fmt)
bool supported = false;
switch (fmt[0]) {
- case 'F':
- case 'f':
- /* Some archs dereference function pointers */
- if (vbin_printf ==
- dereference_function_descriptor(vbin_printf)) {
- supported = true;
- break;
- }
- /* Fall through */
case 'R':
case 'r':
case 'b':
@@ -2394,7 +2385,21 @@ do { \
}
case FORMAT_TYPE_PTR:
- save_arg(void *);
+ switch (fmt[0]) {
+ case 'F':
+ case 'f': {
+ void *ptr = va_arg(args, void *);
+
+ ptr = dereference_function_descriptor(ptr);
+ str = PTR_ALIGN(str, sizeof(u32));
+ if (str + sizeof(ptr) <= end)
+ *(void **)str = ptr;
+ str += sizeof(ptr);
+ break;
+ }
+ default:
+ save_arg(void *);
+ }
/* skip all alphanumeric pointer suffixes */
while (isalnum(*fmt))
fmt++;
@@ -2548,8 +2553,23 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
case FORMAT_TYPE_PTR: {
const char *_fmt = fmt;
-
- if (!supported_bin_ptr(fmt)) {
+ char tmp_fmt[2];
+
+ if (supported_bin_ptr(fmt)) {
+ switch (fmt[0]) {
+ case 'F':
+ case 'f':
+ /*
+ * The saved pointer has already
+ * been derefenced. Convert the
+ * 'f' to 's' or 'F' to 'S'.
+ */
+ tmp_fmt[0] = 's' - ('f' - fmt[0]);
+ tmp_fmt[1] = 0;
+ _fmt = tmp_fmt;
+ break;
+ }
+ } else {
int len = sizeof(unsupported_str) + 1;
if (str + len <= end) {
--
2.8.1
next prev parent reply other threads:[~2016-06-29 20:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-29 20:05 [RFC][PATCH 0/3] vsprintf: Do not dereference pointers in bstr_printf() Steven Rostedt
2016-06-29 20:05 ` [RFC][PATCH 1/3] vsprintf: Prevent vbin_printf() from using dereferenced pointers Steven Rostedt
2016-06-29 20:05 ` Steven Rostedt [this message]
2016-06-29 20:05 ` [RFC][PATCH 3/3] vsprintf: Add support for %pb and friends to vbin_printf() Steven Rostedt
2016-06-30 14:56 ` Jiri Olsa
2016-06-30 15:48 ` Steven Rostedt
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=20160629201224.546349056@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=fweisbec@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
/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).