public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Wei Yongjun <yjwei@cn.fujitsu.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/3] tracing/events: parameter check for __string() and *_str()
Date: Thu, 27 Aug 2009 18:42:06 +0800	[thread overview]
Message-ID: <4A9662FE.3080400@cn.fujitsu.com> (raw)
In-Reply-To: <4A966288.8020402@cn.fujitsu.com>

If we pass a NULL pointer to __string() and *_str(), kernel will
crash, this patch stop it and print the NULL pointer to user, for
example:

sshd-2545  [000]    95.588404: napi_poll: ifname=<NULL>

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
---
 include/trace/ftrace.h             |   11 +++++++----
 kernel/trace/trace_events_filter.c |    2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
index 360a77a..036aa0e 100644
--- a/include/trace/ftrace.h
+++ b/include/trace/ftrace.h
@@ -229,8 +229,9 @@ ftrace_format_##call(struct ftrace_event_call *unused,			\
 #define TP_printk(fmt, args...) fmt "\n", args
 
 #undef __get_dynamic_array
-#define __get_dynamic_array(field)	\
-		((void *)__entry + (__entry->__data_loc_##field & 0xffff))
+#define __get_dynamic_array(field)					\
+	((__entry->__data_loc_##field & 0xffff0000) ?			\
+	((void *)__entry + (__entry->__data_loc_##field & 0xffff)) : NULL)
 
 #undef __get_str
 #define __get_str(field) (char *)__get_dynamic_array(field)
@@ -357,7 +358,8 @@ ftrace_define_fields_##call(struct ftrace_event_call *event_call)	\
 	__data_size += (len) * sizeof(type);
 
 #undef __string
-#define __string(item, src) __dynamic_array(char, item, strlen(src) + 1)       \
+#define __string(item, src)						\
+	__dynamic_array(char, item, src ? strlen(src) + 1 : 0)
 
 #undef TRACE_EVENT
 #define TRACE_EVENT(call, proto, args, tstruct, assign, print)		\
@@ -554,7 +556,8 @@ static void ftrace_profile_disable_##call(struct ftrace_event_call *event_call)\
 
 #undef __assign_str
 #define __assign_str(dst, src)						\
-	strcpy(__get_str(dst), src);
+	if (src) 							\
+		strcpy(__get_str(dst), src);
 
 #undef TRACE_EVENT
 #define TRACE_EVENT(call, proto, args, tstruct, assign, print)		\
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 9f03082..9f1838a 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -196,7 +196,7 @@ static int filter_pred_strloc(struct filter_pred *pred, void *event,
 	char *addr = (char *)(event + str_loc);
 	int cmp, match;
 
-	cmp = strncmp(addr, pred->str_val, str_len);
+	cmp = str_len ? strncmp(addr, pred->str_val, str_len) : -1;
 
 	match = (!cmp) ^ pred->not;
 
-- 
1.6.1.2



  reply	other threads:[~2009-08-27 10:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-27 10:40 [PATCH 1/3] drop_monitor: fix trace_napi_poll_hit() Xiao Guangrong
2009-08-27 10:42 ` Xiao Guangrong [this message]
2009-08-27 10:56 ` [PATCH 3/3] tracing/events: convert NAPI's tracepoint and fix DEFINE_TRACE_FN Xiao Guangrong
2009-08-27 12:46 ` [PATCH 1/3] drop_monitor: fix trace_napi_poll_hit() Neil Horman
2009-08-31  4:57 ` David Miller

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=4A9662FE.3080400@cn.fujitsu.com \
    --to=xiaoguangrong@cn.fujitsu.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    --cc=yjwei@cn.fujitsu.com \
    /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