Skip to content

Commit 70c8217

Browse files
committed
tracing: Handle NULL formats in hold_module_trace_bprintk_format()
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 3debb0a ("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: 3debb0a ("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>
1 parent 5edb564 commit 70c8217

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎kernel/trace/trace_printk.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ struct trace_bprintk_fmt {
3636
static inline struct trace_bprintk_fmt *lookup_format(const char *fmt)
3737
{
3838
struct trace_bprintk_fmt *pos;
39+
40+
if (!fmt)
41+
return ERR_PTR(-EINVAL);
42+
3943
list_for_each_entry(pos, &trace_bprintk_fmt_list, list) {
4044
if (!strcmp(pos->fmt, fmt))
4145
return pos;
@@ -57,7 +61,8 @@ void hold_module_trace_bprintk_format(const char **start, const char **end)
5761
for (iter = start; iter < end; iter++) {
5862
struct trace_bprintk_fmt *tb_fmt = lookup_format(*iter);
5963
if (tb_fmt) {
60-
*iter = tb_fmt->fmt;
64+
if (!IS_ERR(tb_fmt))
65+
*iter = tb_fmt->fmt;
6166
continue;
6267
}
6368

0 commit comments

Comments
 (0)