From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933984AbdKBP7y (ORCPT ); Thu, 2 Nov 2017 11:59:54 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:44054 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932280AbdKBP7w (ORCPT ); Thu, 2 Nov 2017 11:59:52 -0400 X-Google-Smtp-Source: ABhQp+RtGBxFzwWtf/icSgr6yDJaGyWnivZvz3X9j7QiNp1iSVjyPZvSWCe11stapUYj+XeEsbEEKg== Date: Thu, 2 Nov 2017 08:59:47 -0700 From: Alexei Starovoitov To: Arnd Bergmann Cc: Alexei Starovoitov , Daniel Borkmann , "David S. Miller" , Edward Cree , John Fastabend , Jakub Kicinski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] [net-next] bpf: fix out-of-bounds access warning in bpf_check Message-ID: <20171102155945.vvrrugvhrgdvvkso@ast-mbp> References: <20171102110558.2746221-1-arnd@arndb.de> <20171102110558.2746221-2-arnd@arndb.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171102110558.2746221-2-arnd@arndb.de> User-Agent: NeoMutt/20170421 (1.8.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 02, 2017 at 12:05:52PM +0100, Arnd Bergmann wrote: > The bpf_verifer_ops array is generated dynamically and may be > empty depending on configuration, which then causes an out > of bounds access: > > kernel/bpf/verifier.c: In function 'bpf_check': > kernel/bpf/verifier.c:4320:29: error: array subscript is above array bounds [-Werror=array-bounds] > > This adds a check to the start of the function as a workaround. > I would assume that the function is never called in that configuration, > so the warning is probably harmless. > > Fixes: 00176a34d9e2 ("bpf: remove the verifier ops from program structure") > Signed-off-by: Arnd Bergmann > --- > Since there hasn't been a linux-next release in two weeks, I'm not > entirely sure this is still needed, but from looking of the net-next > contents it seems it is. I did not check any other trees that might > have a fix already. > --- > kernel/bpf/verifier.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > index 750aff880ecb..debb60ad08ee 100644 > --- a/kernel/bpf/verifier.c > +++ b/kernel/bpf/verifier.c > @@ -4447,6 +4447,10 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr) > struct bpf_verifer_log *log; > int ret = -EINVAL; > > + /* no program is valid */ > + if (ARRAY_SIZE(bpf_verifier_ops) == 0) > + return -EINVAL; sorry I don't see how bpf_verifier_ops can be empty. Did you mix it up with your previous patch when you made bpf_analyzer_ops empty?