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 3/3] vsprintf: Add support for %pb and friends to vbin_printf()
Date: Wed, 29 Jun 2016 16:05:25 -0400 [thread overview]
Message-ID: <20160629201224.718341351@goodmis.org> (raw)
In-Reply-To: <20160629200522.686965980@goodmis.org>
[-- Attachment #1: 0003-vsprintf-Add-support-for-pb-and-friends-to-vbin_prin.patch --]
[-- Type: text/plain, Size: 2432 bytes --]
From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
printk() allows a %pb to print out cpumasks. As it uses a pointer to
reference the mask it can be problematic for vbin_printf() to use, as the
referencing is done at a later time (via bstr_printf()). Instead of saving
the pointer to the cpumask, simply save the entire cpumask to the structure
and use that data for bstr_printf() to print it out.
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
lib/vsprintf.c | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 1eb4c7bc3509..474d9ddaca6f 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -2273,7 +2273,6 @@ static bool supported_bin_ptr(const char *fmt)
switch (fmt[0]) {
case 'R':
case 'r':
- case 'b':
case 'M':
case 'm':
case 'I':
@@ -2397,6 +2396,16 @@ do { \
str += sizeof(ptr);
break;
}
+ case 'b': {
+ unsigned long *mask = va_arg(args, void *);
+ int len = BITS_TO_LONGS(spec.field_width);
+
+ str = PTR_ALIGN(str, sizeof(u32));
+ if (str + len <= end)
+ memcpy(str, mask, len);
+ str += len;
+ break;
+ }
default:
save_arg(void *);
}
@@ -2552,11 +2561,18 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
}
case FORMAT_TYPE_PTR: {
+ unsigned long *tmp_ptr;
+ unsigned long *ptr;
const char *_fmt = fmt;
char tmp_fmt[2];
if (supported_bin_ptr(fmt)) {
switch (fmt[0]) {
+ case 'b': {
+ tmp_ptr = get_arg(void *);
+ ptr = (void *)&tmp_ptr;
+ break;
+ }
case 'F':
case 'f':
/*
@@ -2567,7 +2583,9 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
tmp_fmt[0] = 's' - ('f' - fmt[0]);
tmp_fmt[1] = 0;
_fmt = tmp_fmt;
- break;
+ /* Fall through */
+ default:
+ ptr = get_arg(void *);
}
} else {
int len = sizeof(unsupported_str) + 1;
@@ -2583,8 +2601,10 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
/* Just show the pointer itself */
_fmt = "";
spec.field_width = -1;
+ ptr = get_arg(void *);
}
- str = pointer(_fmt, str, end, get_arg(void *), spec);
+
+ str = pointer(_fmt, str, end, ptr, spec);
while (isalnum(*fmt))
fmt++;
--
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 ` [RFC][PATCH 2/3] vsprintf: Add support for %pf and %pF to vbin_printf() Steven Rostedt
2016-06-29 20:05 ` Steven Rostedt [this message]
2016-06-30 14:56 ` [RFC][PATCH 3/3] vsprintf: Add support for %pb and friends " 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.718341351@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
Powered by JetHome