Message ID | 20230203041644.581649-1-zyytlz.wz@163.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp636098wrn; Thu, 2 Feb 2023 20:24:25 -0800 (PST) X-Google-Smtp-Source: AK7set+4tOCqMwmg2qEeLkQqDZHN7feECWp+yv21xNLygL/UulWhrehUdDcDfEmvZCuQoyFUcJ7g X-Received: by 2002:a50:fb81:0:b0:498:b9ea:1894 with SMTP id e1-20020a50fb81000000b00498b9ea1894mr9448485edq.15.1675398264978; Thu, 02 Feb 2023 20:24:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675398264; cv=none; d=google.com; s=arc-20160816; b=S2P8777ZdGswEjTswc+jGfd+6jnQPjo7oCeEAfdySGDGoYycBk/5hT9m1+JaL9T5fT HQxOjGHdvLPTsdDQwM4wpMLalmZLF6fyT1RHkvyos/bVtmzXHd093E8h+LoQv2k91ddf bWlBkASwoDgMsQf7CCh0CmqskdRByJzR3be5Mhuo4Wa+HPEJKXl3mzEA+4Vjs7qLNyWv wO3rSWQGdfTiFSe9WshX6kvAfomL5hEDYBaHrHy8QUkF84COH3jnHwd0VBQDGRXAgu8v 4moMjBOMksRtUH+DtIB0jO+NFm3UfIwbYwthlePCXXubi9fAj8ViMHLDRmldjSwWkw3g gZhA== 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:dkim-signature; bh=ZP/G2/Wc7Zu5bVyWuLioRq1av3H4XStIgza6mcAOiVM=; b=eQNjqpCmNxBCKJulTE06CwVVrprwZivNBWXJb8DFR4aNwGso4OaeocakheNiyfH5cv +Y4kKX0lGmHoYUX16KkG394DLWWx56JN37Eg4wszH6U9tlXkmngbfjVi+FXUUGiOgySB PbVpLejtLnEY60aJBL/nXXanFe9pOxI1a+HSyPe9llEqjKJK7LvCb9rk8/Ts8gYPbiPI JlMvbfxs78C3ddqiKEgXLnkbFmFN1f98UwxRp8OwrUgv/insNhe5HgzePGMxHDcOvHtp TKLp0N00hM5e9pLTuFdaVKBCKvPhJE0CFmiD7UyUpM0HDDMXi6/Qo6+9IWwXkMcxeBpt cl2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=YJhjVkWn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fk23-20020a056402399700b0049e34ecef51si1634653edb.517.2023.02.02.20.24.00; Thu, 02 Feb 2023 20:24:24 -0800 (PST) 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; dkim=pass header.i=@163.com header.s=s110527 header.b=YJhjVkWn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231688AbjBCERi (ORCPT <rfc822;il.mystafa@gmail.com> + 99 others); Thu, 2 Feb 2023 23:17:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230094AbjBCERg (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 2 Feb 2023 23:17:36 -0500 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A37B88B30F for <linux-kernel@vger.kernel.org>; Thu, 2 Feb 2023 20:17:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=ZP/G2 /Wc7Zu5bVyWuLioRq1av3H4XStIgza6mcAOiVM=; b=YJhjVkWntd6e37EVVkgEk 3p9BjAnddXGF0adc+AJmUfm546JQLGRXB8mT7zYeb2hwlcmJC0HRMt166iaMmeEa n3G6tN7/l0gHN1ydsebmCN+/sp9BQ0CGIcsQ0esB7elmbPMSCMTW8vwiUNZmxHgP XZ7CIUMoHyX6PLVRW1QoCE= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g2-4 (Coremail) with SMTP id _____wAnLCyvitxjfZi1Cg--.56355S2; Fri, 03 Feb 2023 12:16:47 +0800 (CST) From: Zheng Wang <zyytlz.wz@163.com> To: srini.raju@purelifi.com Cc: kvalo@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Zheng Wang <zyytlz.wz@163.com> Subject: [PATCH] wifi: plfxlc: fix potential NULL pointer dereference in plfxlc_usb_wreq_async() Date: Fri, 3 Feb 2023 12:16:44 +0800 Message-Id: <20230203041644.581649-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wAnLCyvitxjfZi1Cg--.56355S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7CF1rtr43ur4UtryfCw4kWFg_yoW8GrWDpF s5GasI9w1UJr47Ja1xJFs2vFWFgan5Kry8KF4xZa98urZ5JwnYy3ySga4aq3W8Zr4UX3W7 XryUtry3WFnxG3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pE_HUrUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiQhALU1aEEPGiVgAAsN X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS 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?1756782411197054367?= X-GMAIL-MSGID: =?utf-8?q?1756782411197054367?= |
Series |
wifi: plfxlc: fix potential NULL pointer dereference in plfxlc_usb_wreq_async()
|
|
Commit Message
Zheng Wang
Feb. 3, 2023, 4:16 a.m. UTC
Although the usb_alloc_urb uses GFP_ATOMIC, tring to make sure the memory
allocated not to be NULL. But in some low-memory situation, it's still
possible to return NULL. It'll pass urb as argument in
usb_fill_bulk_urb, which will finally lead to a NULL pointer dereference.
Fix it by adding additional check.
Note that, as a bug found by static analysis, it can be a false
positive or hard to trigger.
Fixes: 68d57a07bfe5 ("wireless: add plfxlc driver for pureLiFi X, XL, XC devices")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
drivers/net/wireless/purelifi/plfxlc/usb.c | 7 +++++++
1 file changed, 7 insertions(+)
Comments
Le 03/02/2023 à 05:16, Zheng Wang a écrit : > Although the usb_alloc_urb uses GFP_ATOMIC, tring to make sure the memory > allocated not to be NULL. But in some low-memory situation, it's still > possible to return NULL. It'll pass urb as argument in > usb_fill_bulk_urb, which will finally lead to a NULL pointer dereference. > > Fix it by adding additional check. > > Note that, as a bug found by static analysis, it can be a false > positive or hard to trigger. > > Fixes: 68d57a07bfe5 ("wireless: add plfxlc driver for pureLiFi X, XL, XC devices") > > Signed-off-by: Zheng Wang <zyytlz.wz@163.com> > --- > drivers/net/wireless/purelifi/plfxlc/usb.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/drivers/net/wireless/purelifi/plfxlc/usb.c b/drivers/net/wireless/purelifi/plfxlc/usb.c > index 76d0a778636a..ac149aa64908 100644 > --- a/drivers/net/wireless/purelifi/plfxlc/usb.c > +++ b/drivers/net/wireless/purelifi/plfxlc/usb.c > @@ -496,10 +496,17 @@ int plfxlc_usb_wreq_async(struct plfxlc_usb *usb, const u8 *buffer, > struct urb *urb = usb_alloc_urb(0, GFP_ATOMIC); > int r; > > + if (!urb) { > + r = -ENOMEM; > + kfree(urb); Hi, why kfree() in such a case? CJ > + goto out; > + } > usb_fill_bulk_urb(urb, udev, usb_sndbulkpipe(udev, EP_DATA_OUT), > (void *)buffer, buffer_len, complete_fn, context); > > r = usb_submit_urb(urb, GFP_ATOMIC); > + > +out: > if (r) > dev_err(&udev->dev, "Async write submit failed (%d)\n", r); >
At 2023-02-03 13:25:45, "Christophe JAILLET" <christophe.jaillet@wanadoo.fr> wrote: >Le 03/02/2023 à 05:16, Zheng Wang a écrit : >> Although the usb_alloc_urb uses GFP_ATOMIC, tring to make sure the memory >> allocated not to be NULL. But in some low-memory situation, it's still >> possible to return NULL. It'll pass urb as argument in >> usb_fill_bulk_urb, which will finally lead to a NULL pointer dereference. >> >> Fix it by adding additional check. >> >> Note that, as a bug found by static analysis, it can be a false >> positive or hard to trigger. >> >> Fixes: 68d57a07bfe5 ("wireless: add plfxlc driver for pureLiFi X, XL, XC devices") >> >> Signed-off-by: Zheng Wang <zyytlz.wz@163.com> >> --- >> drivers/net/wireless/purelifi/plfxlc/usb.c | 7 +++++++ >> 1 file changed, 7 insertions(+) >> >> diff --git a/drivers/net/wireless/purelifi/plfxlc/usb.c b/drivers/net/wireless/purelifi/plfxlc/usb.c >> index 76d0a778636a..ac149aa64908 100644 >> --- a/drivers/net/wireless/purelifi/plfxlc/usb.c >> +++ b/drivers/net/wireless/purelifi/plfxlc/usb.c >> @@ -496,10 +496,17 @@ int plfxlc_usb_wreq_async(struct plfxlc_usb *usb, const u8 *buffer, >> struct urb *urb = usb_alloc_urb(0, GFP_ATOMIC); >> int r; >> >> + if (!urb) { >> + r = -ENOMEM; >> + kfree(urb); > >Hi, >why kfree() in such a case? Hello CJ, Thanks for pointing that out. Kfree is unnecessary in such case, we can just return. Regards, Zheng Wang > >> + goto out; >> + } >> usb_fill_bulk_urb(urb, udev, usb_sndbulkpipe(udev, EP_DATA_OUT), >> (void *)buffer, buffer_len, complete_fn, context); >> >> r = usb_submit_urb(urb, GFP_ATOMIC); >> + >> +out: >> if (r) >> dev_err(&udev->dev, "Async write submit failed (%d)\n", r); >>
diff --git a/drivers/net/wireless/purelifi/plfxlc/usb.c b/drivers/net/wireless/purelifi/plfxlc/usb.c index 76d0a778636a..ac149aa64908 100644 --- a/drivers/net/wireless/purelifi/plfxlc/usb.c +++ b/drivers/net/wireless/purelifi/plfxlc/usb.c @@ -496,10 +496,17 @@ int plfxlc_usb_wreq_async(struct plfxlc_usb *usb, const u8 *buffer, struct urb *urb = usb_alloc_urb(0, GFP_ATOMIC); int r; + if (!urb) { + r = -ENOMEM; + kfree(urb); + goto out; + } usb_fill_bulk_urb(urb, udev, usb_sndbulkpipe(udev, EP_DATA_OUT), (void *)buffer, buffer_len, complete_fn, context); r = usb_submit_urb(urb, GFP_ATOMIC); + +out: if (r) dev_err(&udev->dev, "Async write submit failed (%d)\n", r);