The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] vsprintf: Prevent NULL dereference using %pNF
@ 2012-01-17 18:37 Joe Perches
  2012-01-17 18:46 ` David Miller
  0 siblings, 1 reply; 10+ messages in thread
From: Joe Perches @ 2012-01-17 18:37 UTC (permalink / raw)
  To: Michał Mirosław; +Cc: David S. Miller, LKML

Passing NULL to %pNF is done in skb_gso_segment
which could be dereferenced.

Add noinline_for_stack to function.
Make pointer argument the actual type.
Check pointer for NULL and use 0 when so.

Signed-off-by: Joe Perches <joe@perches.com>
---
 lib/vsprintf.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 8e75003..0f1dfd9 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -777,16 +777,24 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
 	return string(buf, end, uuid, spec);
 }
 
-static
-char *netdev_feature_string(char *buf, char *end, const u8 *addr,
-		      struct printf_spec spec)
+static noinline_for_stack
+char *netdev_feature_string(char *buf, char *end,
+			    const netdev_features_t *features,
+			    struct printf_spec spec)
 {
+	unsigned long long num;
+
+	if (features)
+		num = (unsigned long long)*features;
+	else
+		num = 0;
+
 	spec.flags |= SPECIAL | SMALL | ZEROPAD;
 	if (spec.field_width == -1)
 		spec.field_width = 2 + 2 * sizeof(netdev_features_t);
 	spec.base = 16;
 
-	return number(buf, end, *(const netdev_features_t *)addr, spec);
+	return number(buf, end, num, spec);
 }
 
 int kptr_restrict __read_mostly;



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

end of thread, other threads:[~2012-01-18  2:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-17 18:37 [PATCH] vsprintf: Prevent NULL dereference using %pNF Joe Perches
2012-01-17 18:46 ` David Miller
2012-01-17 18:51   ` Joe Perches
2012-01-17 18:52     ` David Miller
2012-01-17 18:54       ` Joe Perches
2012-01-17 18:59         ` David Miller
2012-01-17 19:39     ` Michał Mirosław
2012-01-17 19:43       ` Joe Perches
2012-01-17 21:12         ` Michał Mirosław
2012-01-18  2:43           ` Joe Perches

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