Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752366AbdHHQtC (ORCPT ); Tue, 8 Aug 2017 12:49:02 -0400 Received: from shards.monkeyblade.net ([184.105.139.130]:51342 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752126AbdHHQtA (ORCPT ); Tue, 8 Aug 2017 12:49:00 -0400 Date: Tue, 08 Aug 2017 09:48:57 -0700 (PDT) Message-Id: <20170808.094857.245786887664041622.davem@davemloft.net> To: daniel@iogearbox.net Cc: james.hogan@imgtec.com, ast@kernel.org, linux-kernel@vger.kernel.org, rostedt@goodmis.org, mingo@redhat.com, netdev@vger.kernel.org Subject: Re: [RFC PATCH 2/2] bpf: Initialise mod[] in bpf_trace_printk From: David Miller In-Reply-To: <59897A7C.10009@iogearbox.net> References: <20170807222514.24292-1-james.hogan@imgtec.com> <20170807222514.24292-3-james.hogan@imgtec.com> <59897A7C.10009@iogearbox.net> X-Mailer: Mew version 6.7 on Emacs 25.2 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Tue, 08 Aug 2017 09:48:59 -0700 (PDT) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1804 Lines: 50 From: Daniel Borkmann Date: Tue, 08 Aug 2017 10:46:52 +0200 > On 08/08/2017 12:25 AM, James Hogan wrote: >> In bpf_trace_printk(), the elements in mod[] are left uninitialised, >> but >> they are then incremented to track the width of the formats. Zero >> initialise the array just in case the memory contains non-zero values >> on >> entry. >> >> Fixes: 9c959c863f82 ("tracing: Allow BPF programs to call >> bpf_trace_printk()") >> Signed-off-by: James Hogan >> Cc: Alexei Starovoitov >> Cc: Daniel Borkmann >> Cc: Steven Rostedt >> Cc: Ingo Molnar >> Cc: netdev@vger.kernel.org >> --- >> When I checked (on MIPS32), the elements tended to have the value zero >> anyway (does BPF zero the stack or something clever?), so this is a >> purely theoretical fix. >> --- >> kernel/trace/bpf_trace.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c >> index 32dcbe1b48f2..86a52857d941 100644 >> --- a/kernel/trace/bpf_trace.c >> +++ b/kernel/trace/bpf_trace.c >> @@ -129,7 +129,7 @@ BPF_CALL_5(bpf_trace_printk, char *, fmt, u32, >> fmt_size, u64, arg1, >> u64, arg2, u64, arg3) >> { >> bool str_seen = false; >> - int mod[3] = {}; >> + int mod[3] = { 0, 0, 0 }; > > I'm probably missing something, but is the behavior of gcc wrt > above initializers different on mips (it zeroes just fine on x86 > at least)? If yes, we'd probably need a cocci script to also check > rest of the kernel given this is used in a number of places. Hm, > could you elaborate? This change is not necessary at all. An empty initializer must clear the whole object to zero. "theoretical" fix indeed... :-(