From patchwork Wed Nov 1 12:35:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: renmingshuai X-Patchwork-Id: 13442807 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14A521FC4 for ; Wed, 1 Nov 2023 12:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0747D11B; Wed, 1 Nov 2023 05:36:06 -0700 (PDT) Received: from dggpemm500011.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SL5y36YB1zrTPC; Wed, 1 Nov 2023 20:32:59 +0800 (CST) Received: from huawei.com (10.175.104.170) by dggpemm500011.china.huawei.com (7.185.36.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Wed, 1 Nov 2023 20:36:01 +0800 From: Ren Mingshuai To: CC: , , , , , , Subject: [PATCH] net: usbnet: Fix potential NULL pointer dereference Date: Wed, 1 Nov 2023 20:35:59 +0800 Message-ID: <20231101123559.210756-1-renmingshuai@huawei.com> X-Mailer: git-send-email 2.27.0 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.175.104.170] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500011.china.huawei.com (7.185.36.110) X-CFilter-Loop: Reflected X-Patchwork-Delegate: kuba@kernel.org 23ba07991dad said SKB can be NULL without describing the triggering scenario. Always Check it before dereference to void potential NULL pointer dereference. Fix smatch warning: drivers/net/usb/usbnet.c:1380 usbnet_start_xmit() error: we previously assumed 'skb' could be null (see line 1359) Signed-off-by: Ren Mingshuai --- drivers/net/usb/usbnet.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c index 64a9a80b2309..386cb1a4ff03 100644 --- a/drivers/net/usb/usbnet.c +++ b/drivers/net/usb/usbnet.c @@ -1374,6 +1374,11 @@ netdev_tx_t usbnet_start_xmit (struct sk_buff *skb, } } + if (!skb) { + netif_dbg(dev, tx_err, dev->net, "tx skb is NULL\n"); + goto drop; + } + if (!(urb = usb_alloc_urb (0, GFP_ATOMIC))) { netif_dbg(dev, tx_err, dev->net, "no urb\n"); goto drop;