* Re: [kees:format-security 2/3] arch/sh/kernel/dumpstack.c:118:2: error: format not a string literal and no format arguments [not found] <531d3b0e.4MeVQMzUoamEWeW7%fengguang.wu@intel.com> @ 2014-03-10 17:41 ` Kees Cook 2014-03-11 9:59 ` Matt Fleming 0 siblings, 1 reply; 3+ messages in thread From: Kees Cook @ 2014-03-10 17:41 UTC (permalink / raw) To: Matt Fleming, Paul Mundt; +Cc: kbuild test robot, LKML On Sun, Mar 9, 2014 at 9:09 PM, kbuild test robot <fengguang.wu@intel.com> wrote: > tree: git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git format-security > head: 78ac7178787f348d93ac16cda556265af4b8ce17 > commit: 3aac21c82091399e96c528c8ac4f337757d6e81b [2/3] Make all format string problems fail the build > config: make ARCH=sh allnoconfig > > All error/warnings: > > arch/sh/kernel/dumpstack.c: In function 'print_trace_address': >>> arch/sh/kernel/dumpstack.c:118:2: error: format not a string literal and no format arguments [-Werror=format-security] > cc1: all warnings being treated as errors > > vim +118 arch/sh/kernel/dumpstack.c > > 4e14dfc7 Matt Fleming 2009-08-07 102 context, &graph); > 4e14dfc7 Matt Fleming 2009-08-07 103 } > 4e14dfc7 Matt Fleming 2009-08-07 104 } > 4e14dfc7 Matt Fleming 2009-08-07 105 } > 4e14dfc7 Matt Fleming 2009-08-07 106 > 4e14dfc7 Matt Fleming 2009-08-07 107 static int print_trace_stack(void *data, char *name) > 4e14dfc7 Matt Fleming 2009-08-07 108 { > 4e14dfc7 Matt Fleming 2009-08-07 109 printk("%s <%s> ", (char *)data, name); > 4e14dfc7 Matt Fleming 2009-08-07 110 return 0; > 4e14dfc7 Matt Fleming 2009-08-07 111 } > 4e14dfc7 Matt Fleming 2009-08-07 112 > 4e14dfc7 Matt Fleming 2009-08-07 113 /* > 4e14dfc7 Matt Fleming 2009-08-07 114 * Print one address/symbol entries per line. > 4e14dfc7 Matt Fleming 2009-08-07 115 */ > 4e14dfc7 Matt Fleming 2009-08-07 116 static void print_trace_address(void *data, unsigned long addr, int reliable) > 4e14dfc7 Matt Fleming 2009-08-07 117 { > 4e14dfc7 Matt Fleming 2009-08-07 @118 printk(data); This needs to be "printk("%s", data);" so there is no chance of having "data" interpreted as a format string itself. Thanks! -Kees > 4e14dfc7 Matt Fleming 2009-08-07 119 printk_address(addr, reliable); > 4e14dfc7 Matt Fleming 2009-08-07 120 } > 4e14dfc7 Matt Fleming 2009-08-07 121 > 4e14dfc7 Matt Fleming 2009-08-07 122 static const struct stacktrace_ops print_trace_ops = { > 4e14dfc7 Matt Fleming 2009-08-07 123 .stack = print_trace_stack, > 4e14dfc7 Matt Fleming 2009-08-07 124 .address = print_trace_address, > 4e14dfc7 Matt Fleming 2009-08-07 125 }; > 4e14dfc7 Matt Fleming 2009-08-07 126 > > :::::: The code at line 118 was first introduced by commit > :::::: 4e14dfc722b8e9e07a355f97aa60a3d9f0739071 sh: Use the generalized stacktrace ops > > :::::: TO: Matt Fleming <matt@console-pimps.org> > :::::: CC: Paul Mundt <lethal@linux-sh.org> > > --- > 0-DAY kernel build testing backend Open Source Technology Center > http://lists.01.org/mailman/listinfo/kbuild Intel Corporation -- Kees Cook Chrome OS Security ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [kees:format-security 2/3] arch/sh/kernel/dumpstack.c:118:2: error: format not a string literal and no format arguments 2014-03-10 17:41 ` [kees:format-security 2/3] arch/sh/kernel/dumpstack.c:118:2: error: format not a string literal and no format arguments Kees Cook @ 2014-03-11 9:59 ` Matt Fleming 2014-03-11 20:01 ` Kees Cook 0 siblings, 1 reply; 3+ messages in thread From: Matt Fleming @ 2014-03-11 9:59 UTC (permalink / raw) To: Kees Cook; +Cc: Paul Mundt, kbuild test robot, LKML, Andrew Morton On Mon, 10 Mar, at 10:41:57AM, Kees Cook wrote: > > 4e14dfc7 Matt Fleming 2009-08-07 113 /* > > 4e14dfc7 Matt Fleming 2009-08-07 114 * Print one address/symbol entries per line. > > 4e14dfc7 Matt Fleming 2009-08-07 115 */ > > 4e14dfc7 Matt Fleming 2009-08-07 116 static void print_trace_address(void *data, unsigned long addr, int reliable) > > 4e14dfc7 Matt Fleming 2009-08-07 117 { > > 4e14dfc7 Matt Fleming 2009-08-07 @118 printk(data); > > This needs to be "printk("%s", data);" so there is no chance of having > "data" interpreted as a format string itself. OMG, I suck. Thanks for the report Kees. Have you got a patch for x86? I think that's where this code came from. Including Andrew, because I'm not sure who else is going to take this patch. --- >From 2284f3a27f68cec665aa982c0a226cf3fbf96ddf Mon Sep 17 00:00:00 2001 From: Matt Fleming <matt.fleming@intel.com> Date: Tue, 11 Mar 2014 09:50:26 +0000 Subject: [PATCH] sh: Fix format string bug in stack tracer Kees reported the following error, arch/sh/kernel/dumpstack.c: In function 'print_trace_address': >> arch/sh/kernel/dumpstack.c:118:2: error: format not a string literal and no format arguments [-Werror=format-security] Use the "%s" format so that it's impossible to interpret 'data' as a format string. Reported-by: Kees Cook <keescook@chromium.org> Cc: Paul Mundt <lethal@linux-sh.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: stable@vger.kernel.org Signed-off-by: Matt Fleming <matt.fleming@intel.com> --- arch/sh/kernel/dumpstack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/sh/kernel/dumpstack.c b/arch/sh/kernel/dumpstack.c index b959f5592604..8dfe645bcc4b 100644 --- a/arch/sh/kernel/dumpstack.c +++ b/arch/sh/kernel/dumpstack.c @@ -115,7 +115,7 @@ static int print_trace_stack(void *data, char *name) */ static void print_trace_address(void *data, unsigned long addr, int reliable) { - printk(data); + printk("%s", (char *)data); printk_address(addr, reliable); } -- 1.8.5.3 -- Matt Fleming, Intel Open Source Technology Center ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [kees:format-security 2/3] arch/sh/kernel/dumpstack.c:118:2: error: format not a string literal and no format arguments 2014-03-11 9:59 ` Matt Fleming @ 2014-03-11 20:01 ` Kees Cook 0 siblings, 0 replies; 3+ messages in thread From: Kees Cook @ 2014-03-11 20:01 UTC (permalink / raw) To: Matt Fleming; +Cc: Paul Mundt, kbuild test robot, LKML, Andrew Morton On Tue, Mar 11, 2014 at 2:59 AM, Matt Fleming <matt@console-pimps.org> wrote: > On Mon, 10 Mar, at 10:41:57AM, Kees Cook wrote: >> > 4e14dfc7 Matt Fleming 2009-08-07 113 /* >> > 4e14dfc7 Matt Fleming 2009-08-07 114 * Print one address/symbol entries per line. >> > 4e14dfc7 Matt Fleming 2009-08-07 115 */ >> > 4e14dfc7 Matt Fleming 2009-08-07 116 static void print_trace_address(void *data, unsigned long addr, int reliable) >> > 4e14dfc7 Matt Fleming 2009-08-07 117 { >> > 4e14dfc7 Matt Fleming 2009-08-07 @118 printk(data); >> >> This needs to be "printk("%s", data);" so there is no chance of having >> "data" interpreted as a format string itself. > > OMG, I suck. Thanks for the report Kees. Have you got a patch for x86? > I think that's where this code came from. Your patch looks great, thanks! -Kees > > Including Andrew, because I'm not sure who else is going to take this > patch. > > --- > > From 2284f3a27f68cec665aa982c0a226cf3fbf96ddf Mon Sep 17 00:00:00 2001 > From: Matt Fleming <matt.fleming@intel.com> > Date: Tue, 11 Mar 2014 09:50:26 +0000 > Subject: [PATCH] sh: Fix format string bug in stack tracer > > Kees reported the following error, > > arch/sh/kernel/dumpstack.c: In function 'print_trace_address': >>> arch/sh/kernel/dumpstack.c:118:2: error: format not a string literal and no format arguments [-Werror=format-security] > > Use the "%s" format so that it's impossible to interpret 'data' as a > format string. > > Reported-by: Kees Cook <keescook@chromium.org> > Cc: Paul Mundt <lethal@linux-sh.org> > Cc: Andrew Morton <akpm@linux-foundation.org> > Cc: stable@vger.kernel.org > Signed-off-by: Matt Fleming <matt.fleming@intel.com> > --- > arch/sh/kernel/dumpstack.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/sh/kernel/dumpstack.c b/arch/sh/kernel/dumpstack.c > index b959f5592604..8dfe645bcc4b 100644 > --- a/arch/sh/kernel/dumpstack.c > +++ b/arch/sh/kernel/dumpstack.c > @@ -115,7 +115,7 @@ static int print_trace_stack(void *data, char *name) > */ > static void print_trace_address(void *data, unsigned long addr, int reliable) > { > - printk(data); > + printk("%s", (char *)data); > printk_address(addr, reliable); > } > > -- > 1.8.5.3 > > -- > Matt Fleming, Intel Open Source Technology Center -- Kees Cook Chrome OS Security ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-03-11 20:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <531d3b0e.4MeVQMzUoamEWeW7%fengguang.wu@intel.com>
2014-03-10 17:41 ` [kees:format-security 2/3] arch/sh/kernel/dumpstack.c:118:2: error: format not a string literal and no format arguments Kees Cook
2014-03-11 9:59 ` Matt Fleming
2014-03-11 20:01 ` Kees Cook
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