Message ID | 20230418142918.70510-1-n.zhandarovich@fintech.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2915614vqo; Tue, 18 Apr 2023 08:00:05 -0700 (PDT) X-Google-Smtp-Source: AKy350YI3+fWJwx9sUEwbB8+5wp96EfBUHWedEd6NcBnzMS/BUXN+IPEZFgO/UWvdsc6l4Nbjup4 X-Received: by 2002:a05:6a00:1a89:b0:63b:62d1:d868 with SMTP id e9-20020a056a001a8900b0063b62d1d868mr103210pfv.8.1681830005006; Tue, 18 Apr 2023 08:00:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681830004; cv=none; d=google.com; s=arc-20160816; b=CPmfKrHl0zwrI15vH4g4nGMQITSSZvhQXCOBc5BQcQ8yYE8QnjJlj7ADqvvy9lxXnz vBkqy2VUhu6wtOCdpq2h8MEKeEl+72HEsdvTKk/RSRQjNnY6HvwlbCelQn1py95a2GIL BkXfEFYmfia82dZa9R/mX8on9qo6zYfiBiJFCEasnNaoYbBaNDtg80UVyoiDNBOLhPSY bM7OfSx7aZdnDuwaU/4OZIGA6dB7NEoRl6ul906Geo2yx2Dch/OH164r4CkmVeWkjz8N n5QHjdtrL2S6qu6YSSTVvMFlDvL92xwGHb8RQDi7BDEJtraBliUrUrV/2AKY2uh2/4xX aL+w== 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:from; bh=OrXowOnFfJaG6QJqFEdFpUCcxC5PyKbITJu/owFfKdI=; b=fgGySdK/149uipml/z1DIlduFXciDw4H+Mkg5RbW0f5r+I0dY60w6VbQHH5h9lZYka 19E7UlQdTBLsIwGtCYH9OAbdmKbyU0UNZo92zFZXCTGmyDsP2kL3bVMpttF3r8O/ZZFe TaWwGghsK8VVgcMc+TAyFC5T2TdS3ADSRYR2BLgnfqQn9A13r4mzjyz3camhGZV095BS J5jSxWcJkrx/Xh2UHoi7Fnzw5vS0sYDcjHBeRuHtcUGgVoTzc0TyLZ/XSbsXr6YNPl7h hpIog3R71tHXmcRL5iG0b7LHgkXArwVs7oaA7lKEULhBi+JuuieVZkFSKg+9/1PlqVbT i5eg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l189-20020a6225c6000000b00628a75401bdsi8960411pfl.142.2023.04.18.07.59.50; Tue, 18 Apr 2023 08:00:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231635AbjDRO33 (ORCPT <rfc822;leviz.kernel.dev@gmail.com> + 99 others); Tue, 18 Apr 2023 10:29:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231499AbjDRO30 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 18 Apr 2023 10:29:26 -0400 Received: from exchange.fintech.ru (exchange.fintech.ru [195.54.195.159]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8946DD; Tue, 18 Apr 2023 07:29:24 -0700 (PDT) Received: from Ex16-01.fintech.ru (10.0.10.18) by exchange.fintech.ru (195.54.195.159) with Microsoft SMTP Server (TLS) id 14.3.498.0; Tue, 18 Apr 2023 17:29:23 +0300 Received: from localhost (10.0.253.138) by Ex16-01.fintech.ru (10.0.10.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Tue, 18 Apr 2023 17:29:22 +0300 From: Nikita Zhandarovich <n.zhandarovich@fintech.ru> To: Larry Finger <Larry.Finger@lwfinger.net> CC: Nikita Zhandarovich <n.zhandarovich@fintech.ru>, Kalle Valo <kvalo@kernel.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, "John W. Linville" <linville@tuxdriver.com>, <linux-wireless@vger.kernel.org>, <b43-dev@lists.infradead.org>, <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <lvc-project@linuxtesting.org>, Natalia Petrova <n.petrova@fintech.ru> Subject: [PATCH v2] b43legacy: Add checking for null for ssb_get_devtypedata(dev) Date: Tue, 18 Apr 2023 07:29:18 -0700 Message-ID: <20230418142918.70510-1-n.zhandarovich@fintech.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.0.253.138] X-ClientProxiedBy: Ex16-02.fintech.ru (10.0.10.19) To Ex16-01.fintech.ru (10.0.10.18) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763526579064532388?= X-GMAIL-MSGID: =?utf-8?q?1763526579064532388?= |
Series |
[v2] b43legacy: Add checking for null for ssb_get_devtypedata(dev)
|
|
Commit Message
Nikita Zhandarovich
April 18, 2023, 2:29 p.m. UTC
Since second call of ssb_get_devtypedata() may fail as well as the
first one, the NULL return value in 'wl' will be later dereferenced in
calls to b43legacy_one_core_attach() and schedule_work().
Instead of merely warning about this failure with
B43legacy_WARN_ON(), properly return with error to avoid any further
NULL pointer dereferences.
Found by Linux Verification Center (linuxtesting.org) with static
analysis tool SVACE.
Fixes: 75388acd0cd8 ("[B43LEGACY]: add mac80211-based driver for legacy BCM43xx devices")
Co-developed-by: Natalia Petrova <n.petrova@fintech.ru>
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
---
v2: fix issues with overlooked null-ptr-dereferences pointed out by
Simon Horman <simon.horman@corigine.com>
Link: https://lore.kernel.org/all/Y+eb9mZntfe6rO3v@corigine.com/
drivers/net/wireless/broadcom/b43legacy/main.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
Comments
On Tue, 18 Apr 2023 07:29:18 -0700 Nikita Zhandarovich <n.zhandarovich@fintech.ru> wrote: > Since second call of ssb_get_devtypedata() may fail as well as the > first one, the NULL return value in 'wl' will be later dereferenced in > calls to b43legacy_one_core_attach() and schedule_work(). No, the second call can't fail, because b43legacy_wireless_init() will always initialize it before returning 0. > a/drivers/net/wireless/broadcom/b43legacy/main.c +++ > b/drivers/net/wireless/broadcom/b43legacy/main.c @@ -3857,7 +3857,11 > @@ static int b43legacy_probe(struct ssb_device *dev, if (err) > goto out; > wl = ssb_get_devtypedata(dev); > - B43legacy_WARN_ON(!wl); > + if (!wl) { > + B43legacy_WARN_ON(!wl); > + err = -ENODEV; > + goto out; And the 'goto out' would be the wrong error recovery path, too. > + } > } > err = b43legacy_one_core_attach(dev, wl); > if (err) Nack. Please drop this patch. The code is correct as-is.
On 4/18/23 09:29, Nikita Zhandarovich wrote: > Since second call of ssb_get_devtypedata() may fail as well as the > first one, the NULL return value in 'wl' will be later dereferenced in > calls to b43legacy_one_core_attach() and schedule_work(). > > Instead of merely warning about this failure with > B43legacy_WARN_ON(), properly return with error to avoid any further > NULL pointer dereferences. > > Found by Linux Verification Center (linuxtesting.org) with static > analysis tool SVACE. > > Fixes: 75388acd0cd8 ("[B43LEGACY]: add mac80211-based driver for legacy BCM43xx devices") > Co-developed-by: Natalia Petrova <n.petrova@fintech.ru> > Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru> > --- > v2: fix issues with overlooked null-ptr-dereferences pointed out by > Simon Horman <simon.horman@corigine.com> > Link: https://lore.kernel.org/all/Y+eb9mZntfe6rO3v@corigine.com/ > > drivers/net/wireless/broadcom/b43legacy/main.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/net/wireless/broadcom/b43legacy/main.c b/drivers/net/wireless/broadcom/b43legacy/main.c > index 760136638a95..5a706dd0b1a4 100644 > --- a/drivers/net/wireless/broadcom/b43legacy/main.c > +++ b/drivers/net/wireless/broadcom/b43legacy/main.c > @@ -3857,7 +3857,11 @@ static int b43legacy_probe(struct ssb_device *dev, > if (err) > goto out; > wl = ssb_get_devtypedata(dev); > - B43legacy_WARN_ON(!wl); > + if (!wl) { > + B43legacy_WARN_ON(!wl); > + err = -ENODEV; > + goto out; > + } > } > err = b43legacy_one_core_attach(dev, wl); > if (err) I do not recall seeing v1. One additional nitpick: The latest convention would have the subject as "wifi: b43legacy:...". Kalle may be able to fix this on merging, but it not, a v3 might be required. Otherwise, the patch is good. Reviewed-by: Larry Finger <Larry.Finger@lwfinger.net> Thanks, Larry
On Fri, 21 Apr 2023 17:14:18 -0500 Larry Finger <Larry.Finger@lwfinger.net> wrote: > > (err) goto out; > > wl = ssb_get_devtypedata(dev); > > - B43legacy_WARN_ON(!wl); > > + if (!wl) { > > + B43legacy_WARN_ON(!wl); > > + err = -ENODEV; > > + goto out; > > + } > > } > > err = b43legacy_one_core_attach(dev, wl); > > if (err) > > I do not recall seeing v1. One additional nitpick: The latest > convention would have the subject as "wifi: b43legacy:...". Kalle may > be able to fix this on merging, but it not, a v3 might be required. > Otherwise, the patch is good. > > Reviewed-by: Larry Finger <Larry.Finger@lwfinger.net> No, it's not good. It's wrong. I already replied to it. wl can never be NULL here and the goto-out path is wrong (if there was a chance for it to trigger). Please drop this patch, Kalle.
Nikita Zhandarovich <n.zhandarovich@fintech.ru> wrote: > Since second call of ssb_get_devtypedata() may fail as well as the > first one, the NULL return value in 'wl' will be later dereferenced in > calls to b43legacy_one_core_attach() and schedule_work(). > > Instead of merely warning about this failure with > B43legacy_WARN_ON(), properly return with error to avoid any further > NULL pointer dereferences. > > Found by Linux Verification Center (linuxtesting.org) with static > analysis tool SVACE. > > Fixes: 75388acd0cd8 ("[B43LEGACY]: add mac80211-based driver for legacy BCM43xx devices") > Co-developed-by: Natalia Petrova <n.petrova@fintech.ru> > Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru> > Reviewed-by: Larry Finger <Larry.Finger@lwfinger.net> Dropped per Michael's request. Patch set to Rejected.
diff --git a/drivers/net/wireless/broadcom/b43legacy/main.c b/drivers/net/wireless/broadcom/b43legacy/main.c index 760136638a95..5a706dd0b1a4 100644 --- a/drivers/net/wireless/broadcom/b43legacy/main.c +++ b/drivers/net/wireless/broadcom/b43legacy/main.c @@ -3857,7 +3857,11 @@ static int b43legacy_probe(struct ssb_device *dev, if (err) goto out; wl = ssb_get_devtypedata(dev); - B43legacy_WARN_ON(!wl); + if (!wl) { + B43legacy_WARN_ON(!wl); + err = -ENODEV; + goto out; + } } err = b43legacy_one_core_attach(dev, wl); if (err)