Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1430296

RE: [PATCH 1/2] tracing: Handle NULL formats in hold_module_trace_bprintk_format()

Path csiph.com!weretis.net!feeder4.news.weretis.net!news.unit0.net!news.panservice.it!bofh.it!news.nic.it!robomod
From "Xing, Zhengjun" <zhengjun.xing@intel.com>
Newsgroups linux.kernel
Subject RE: [PATCH 1/2] tracing: Handle NULL formats in hold_module_trace_bprintk_format()
Date Fri, 24 Jun 2016 04:20:02 +0200
Message-ID <rNoSS-230-11@gated-at.bofh.it> (permalink)
References <rM7U6-w3-11@gated-at.bofh.it> <rM7U6-w3-9@gated-at.bofh.it>
X-Extloop1 1
X-Ironport-Av E=Sophos;i="5.26,518,1459839600"; d="scan'208";a="834255814"
Thread-Topic [PATCH 1/2] tracing: Handle NULL formats in hold_module_trace_bprintk_format()
Thread-Index AQHRyvs8+Fr1g3ZvJU6GpEQXUSUt6Z/349BQ
Accept-Language en-US
Content-Language en-US
X-Ctpclassification CTP_IC
X-Titus-Metadata-40 eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNWI2ZWIwZTEtMTI2Mi00Njg5LWIzNDUtY2NmNmNjOGM1NjI1IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6Im9XQlpuTE83WU0wZElWa1EzM1BRSFRaTStCRjZPN1plMUNkMVVsM3VRZms9In0=
X-Originating-IP [10.239.127.40]
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding 8BIT
MIME-Version 1.0
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 57
Organization linux.* mail to news gateway
X-Original-Cc Linus Torvalds <torvalds@linux-foundation.org>, Ingo Molnar <mingo@kernel.org>, Andrew Morton <akpm@linux-foundation.org>, Namhyung Kim <namhyung@kernel.org>, "stable@vger.kernel.org" <stable@vger.kernel.org>
X-Original-Date Fri, 24 Jun 2016 02:14:06 +0000
X-Original-Message-ID <13D79DBE8302154F8AC69AD78FCDF45936BAABDE@SHSMSX101.ccr.corp.intel.com>
X-Original-References <20160620135253.069384486@goodmis.org> <20160620135356.253802298@goodmis.org>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1430296

Show key headers only | View raw


I agree with you. You can also add me to the "Signed-off-by".

Best Regards,
Zhengjun

-----Original Message-----
From: Steven Rostedt [mailto:rostedt@goodmis.org] 
Sent: Monday, June 20, 2016 9:53 PM
To: linux-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>; Ingo Molnar <mingo@kernel.org>; Andrew Morton <akpm@linux-foundation.org>; Xing, Zhengjun <zhengjun.xing@intel.com>; Namhyung Kim <namhyung@kernel.org>; stable@vger.kernel.org
Subject: [PATCH 1/2] tracing: Handle NULL formats in hold_module_trace_bprintk_format()

From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>

If a task uses a non constant string for the format parameter in trace_printk(), then the trace_printk_fmt variable is set to NULL. This variable is then saved in the __trace_printk_fmt section.

The function hold_module_trace_bprintk_format() checks to see if duplicate formats are used by modules, and reuses them if so (saves them to the list if it is new). But this function calls lookup_format() that does a strcmp() to the value (which is now NULL) and can cause a kernel oops.

This wasn't an issue till 3debb0a9ddb ("tracing: Fix trace_printk() to print when not using bprintk()") which added "__used" to the trace_printk_fmt variable, and before that, the kernel simply optimized it out (no NULL value was saved).

The fix is simply to handle the NULL pointer in lookup_format() and have the caller ignore the value if it was NULL.

Link: http://lkml.kernel.org/r/1464769870-18344-1-git-send-email-zhengjun.xing@intel.com

Reported-by: xingzhen <zhengjun.xing@intel.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Fixes: 3debb0a9ddb ("tracing: Fix trace_printk() to print when not using bprintk()")
Cc: stable@vger.kernel.org # v3.5+
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/trace_printk.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_printk.c b/kernel/trace/trace_printk.c index f96f0383f6c6..ad1d6164e946 100644
--- a/kernel/trace/trace_printk.c
+++ b/kernel/trace/trace_printk.c
@@ -36,6 +36,10 @@ struct trace_bprintk_fmt {  static inline struct trace_bprintk_fmt *lookup_format(const char *fmt)  {
 	struct trace_bprintk_fmt *pos;
+
+	if (!fmt)
+		return ERR_PTR(-EINVAL);
+
 	list_for_each_entry(pos, &trace_bprintk_fmt_list, list) {
 		if (!strcmp(pos->fmt, fmt))
 			return pos;
@@ -57,7 +61,8 @@ void hold_module_trace_bprintk_format(const char **start, const char **end)
 	for (iter = start; iter < end; iter++) {
 		struct trace_bprintk_fmt *tb_fmt = lookup_format(*iter);
 		if (tb_fmt) {
-			*iter = tb_fmt->fmt;
+			if (!IS_ERR(tb_fmt))
+				*iter = tb_fmt->fmt;
 			continue;
 		}
 
--
2.8.0.rc3

Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

[PATCH 1/2] tracing: Handle NULL formats in hold_module_trace_bprintk_format() Steven Rostedt <rostedt@goodmis.org> - 2016-06-20 16:00 +0200
  RE: [PATCH 1/2] tracing: Handle NULL formats in  hold_module_trace_bprintk_format() "Xing, Zhengjun" <zhengjun.xing@intel.com> - 2016-06-24 04:20 +0200

csiph-web