Message ID | 20231117125701.58927-1-arefev@swemel.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp504705vqn; Fri, 17 Nov 2023 04:57:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IF9wMVSlJ0h+PusvD7QmqVwoQmwVu/w2rYvRy22gcLRda2thLBSbp92pMwAh6GvEYpSP6FW X-Received: by 2002:a05:6e02:b45:b0:359:a196:d326 with SMTP id f5-20020a056e020b4500b00359a196d326mr23734592ilu.8.1700225846217; Fri, 17 Nov 2023 04:57:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700225846; cv=none; d=google.com; s=arc-20160816; b=UHvr5XE2QHT1naXRfCccVBtcGjzg/ZrRCpnEXSP+OBNqFWFDhjDRlow0iQ+tJGf1+l a7D51wcu62blBnEosMYD0BdXvhQn0al+CMbuAz/TJTtbrWXWM6Qnx82RMipEXxsuIJ/f S6hx3j5tvlMfP3bDBC1j8KkZvOLYM9lnmLmdBfZ7lVkmD25t0eO4HDZXsgVjDQx5ydh3 3EeS167tTINQDBUZRGNGYxvAiDH5KT9Lsgp3H4drz3ZmqE3it8LEwXdO264JCjrisaJ4 byUEYRX3YOyH5mtoVzOhLxP7pueZFfPagYWHIF2ToPmrlb0fi44kx0jGELOqcjoXGL3a L/wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:dkim-signature:from; bh=yZD/Sn1R2SVTne1HGGZ4hKTypVy6dTpTjai+r/elyT4=; fh=P/RQfKjOhNs7ABLLXVaJjAQ7olxvoGqD6PM9QdH06Wo=; b=naiI4C1ADju1BZBU4WZ116+bQZdSOPPzhhu104y/ekRvY+XNgmktAMS6+fBvOMkbHg 6Q//osUREyh0/gjpvFrnB611pqRtpHik1JDjEW58+mheBM7FmZz8HBrMDxClPnacmy5e zGhSHrfDTR28t+iRh/UNa6SSN4Oyp2Rdi7cf/zZISUJOyC9c/QlSpNbx7iDO03GuPj8Y 4PCKO36gLmPJkdyDw/z9Fh1refkTgA+QPYqmK4LR31K+UkB80H8ycHNIdM3lxEr5whLC efRdI7ASYwzDuCuAxdCWrEOgqAMkLGoBhy5nN4PNUR4sJKhZHRAFx2sxsDFoboVJmhDU rKFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@swemel.ru header.s=mail header.b=voctcqkI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=swemel.ru Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id n189-20020a6327c6000000b005c1c5d338a9si1947430pgn.658.2023.11.17.04.57.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 04:57:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@swemel.ru header.s=mail header.b=voctcqkI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=swemel.ru Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id E40F782429A8; Fri, 17 Nov 2023 04:57:23 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345851AbjKQM5N (ORCPT <rfc822;jaysivo@gmail.com> + 30 others); Fri, 17 Nov 2023 07:57:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231359AbjKQM5L (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 17 Nov 2023 07:57:11 -0500 Received: from mx.swemel.ru (mx.swemel.ru [95.143.211.150]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05820D5F for <linux-kernel@vger.kernel.org>; Fri, 17 Nov 2023 04:57:06 -0800 (PST) From: Denis Arefev <arefev@swemel.ru> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=swemel.ru; s=mail; t=1700225821; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=yZD/Sn1R2SVTne1HGGZ4hKTypVy6dTpTjai+r/elyT4=; b=voctcqkI8M3/osfELiL5uRL72hNMig0TDFR1ZR7+xmlj6OJObqtE8LUvi3Qzglfs5uHBl8 LXIe0hTkwSfX6uE4GncVWtF+JtUvwhSrxrJat6y1cVbAtjpajoljkFtpQ3Q4LBOQqC1y8D fGrIKupsOn6duLlxjhLty6v8vm6ONGI= To: Louis Peens <louis.peens@corigine.com> Cc: Jakub Kicinski <kuba@kernel.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Paolo Abeni <pabeni@redhat.com>, oss-drivers@corigine.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org Subject: [PATCH] nfp: flower: Added pointer check and continue. Date: Fri, 17 Nov 2023 15:57:01 +0300 Message-Id: <20231117125701.58927-1-arefev@swemel.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 17 Nov 2023 04:57:23 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782816016467853798 X-GMAIL-MSGID: 1782816016467853798 |
Series |
nfp: flower: Added pointer check and continue.
|
|
Commit Message
Denis Arefev
Nov. 17, 2023, 12:57 p.m. UTC
Return value of a function 'kmalloc_array' is dereferenced at
lag_conf.c without checking for null, but it is usually
checked for this function.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by: Denis Arefev <arefev@swemel.ru>
---
drivers/net/ethernet/netronome/nfp/flower/lag_conf.c | 5 +++++
1 file changed, 5 insertions(+)
Comments
On Fri, Nov 17, 2023 at 03:57:01PM +0300, Denis Arefev wrote: > > Return value of a function 'kmalloc_array' is dereferenced at > lag_conf.c without checking for null, but it is usually > checked for this function. > > Found by Linux Verification Center (linuxtesting.org) with SVACE. > > Signed-off-by: Denis Arefev <arefev@swemel.ru> > --- > drivers/net/ethernet/netronome/nfp/flower/lag_conf.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c b/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c > index 88d6d992e7d0..8cc6cce73283 100644 > --- a/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c > +++ b/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c > @@ -339,6 +339,11 @@ static void nfp_fl_lag_do_work(struct work_struct *work) > acti_netdevs = kmalloc_array(entry->slave_cnt, > sizeof(*acti_netdevs), GFP_KERNEL); > > + if (!acti_netdevs) { > + schedule_delayed_work(&lag->work, NFP_FL_LAG_DELAY); > + continue; > + } > + Thanks for reporting this Denis, it definitely seems to be an oversight. Would you mind adding a 'nfp_flower_cmsg_warn' here as well, so that this case does not go undetected? Maybe something like "cannot allocate memory for group processing" can work. > /* Include sanity check in the loop. It may be that a bond has > * changed between processing the last notification and the > * work queue triggering. If the number of slaves has changed > -- > 2.25.1 >
On Fri, 17 Nov 2023 16:27:17 +0200 Louis Peens wrote: > > acti_netdevs = kmalloc_array(entry->slave_cnt, > > sizeof(*acti_netdevs), GFP_KERNEL); > > Unnecessary new line, please remove it. There should be no empty lines between call and error check. > > + if (!acti_netdevs) { > > + schedule_delayed_work(&lag->work, NFP_FL_LAG_DELAY); > > + continue; > > + } > > + > Thanks for reporting this Denis, it definitely seems to be an oversight. > Would you mind adding a 'nfp_flower_cmsg_warn' here as well, so that > this case does not go undetected? Maybe something like "cannot > allocate memory for group processing" can work. There's a checkpatch check against printing warnings on allocation failures. Kernel will complain loudly on OOM, anyway, there's no need for a local print.
On Sat, Nov 18, 2023 at 08:22:07PM -0800, Jakub Kicinski wrote: > On Fri, 17 Nov 2023 16:27:17 +0200 Louis Peens wrote: > > > acti_netdevs = kmalloc_array(entry->slave_cnt, > > > sizeof(*acti_netdevs), GFP_KERNEL); > > > > > Unnecessary new line, please remove it. > There should be no empty lines between call and error check. > > > > + if (!acti_netdevs) { > > > + schedule_delayed_work(&lag->work, NFP_FL_LAG_DELAY); > > > + continue; > > > + } > > > + > > Thanks for reporting this Denis, it definitely seems to be an oversight. > > Would you mind adding a 'nfp_flower_cmsg_warn' here as well, so that > > this case does not go undetected? Maybe something like "cannot > > allocate memory for group processing" can work. > > There's a checkpatch check against printing warnings on allocation > failures. Kernel will complain loudly on OOM, anyway, there's no need > for a local print. Ah, thanks Jakub, I did not know that this is frowned upon. But I have not thought about OOM - it would indeed not be a silent failure. In that case I would be quite happy to add my Ack to v2 with the newline comment addressed. > -- > pw-bot: cr
diff --git a/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c b/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c index 88d6d992e7d0..8cc6cce73283 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c +++ b/drivers/net/ethernet/netronome/nfp/flower/lag_conf.c @@ -339,6 +339,11 @@ static void nfp_fl_lag_do_work(struct work_struct *work) acti_netdevs = kmalloc_array(entry->slave_cnt, sizeof(*acti_netdevs), GFP_KERNEL); + if (!acti_netdevs) { + schedule_delayed_work(&lag->work, NFP_FL_LAG_DELAY); + continue; + } + /* Include sanity check in the loop. It may be that a bond has * changed between processing the last notification and the * work queue triggering. If the number of slaves has changed