[net] net: ethernet: fix use after free bug in ns83820_remove_one due to race condition
Message ID | 20230309094231.3808770-1-zyytlz.wz@163.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp205235wrd; Thu, 9 Mar 2023 02:12:37 -0800 (PST) X-Google-Smtp-Source: AK7set/uXQiphAWKRmgRoXtOFVscBEvlNw2G+qLiZtBE5HAvIhK4GmEfxuWsLaVp3i+omyNoMZkB X-Received: by 2002:a17:902:efd4:b0:19e:f86c:256e with SMTP id ja20-20020a170902efd400b0019ef86c256emr3929742plb.62.1678356757319; Thu, 09 Mar 2023 02:12:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678356757; cv=none; d=google.com; s=arc-20160816; b=kkgFe38cR/CuRk8NzIiQaDx6s4TTOn5p2G4cKYNkR/Dhs9nFEIh04fOqK45pGJqyoj gIAiEtiPd9ifYMjsp4NA3MWB2zEOMqp/8pld8SCls7R4jqCmdzMLmIC5iKuxgOuwnILF UMkZ5q51tlS/D5FbsTnKchoYTHLFqh76jZwbnsEFL+4pyUmGNdsV+2Lv9OqR+WbUKvrs Pq18ePjkDDjU5mOkL4cLZUvftM7SsNukuFlvaA/H6NSTDgFoNl1Xkvpa/xhX14K6WuQe EuQM55GKgysVlNgJP2huMY/WULXY5507vHQaGCPFvgVX9HTN4kE7AKLmTw6VLNCKrfAN Poaw== 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=1LAKM8ujTmsjgTGR7X/vNMNjwpQJAdiC96EghkHvIIM=; b=ZBYRFmP8KcUCAuIJX0xLdW6sHRVspaqqYsjJ+f0fx97IEZS5ZVXiziOTnHCimOUtBp rNzdMJjRtHdpcDKzZzYTQhx5ymAVvGxMudSkFq76GUbh2fT3sR1O5FDo7/tYuCYLXYYf lD5Zqwu3efo7id3CFSfVKhtDnFkk6oeL5glYUJXzXKyIxLQdc7cOuQ/3clwD79ivZnG1 uWBT9eavqI2XgdLCTlk2weKxk2gxoeotQzc4vZUBVN0cShPog0bsarPYEM9dZ2/yRDXc 0rgoiJbTXLZziQagZ7Gi7/wRmHNEgz+Tx6DEhkxurA/h1IPQCqE9VJCMkK3ONI8P/fT6 JQeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=V3tmhaUx; 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 t141-20020a635f93000000b00502f4cae52dsi17405860pgb.850.2023.03.09.02.12.21; Thu, 09 Mar 2023 02:12:37 -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=V3tmhaUx; 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 S231336AbjCIJna (ORCPT <rfc822;carlos.wei.hk@gmail.com> + 99 others); Thu, 9 Mar 2023 04:43:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231324AbjCIJnV (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 9 Mar 2023 04:43:21 -0500 Received: from m12.mail.163.com (m12.mail.163.com [123.126.96.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 29D4C5552C; Thu, 9 Mar 2023 01:43:17 -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=1LAKM 8ujTmsjgTGR7X/vNMNjwpQJAdiC96EghkHvIIM=; b=V3tmhaUxN5E19Lu4oMuCu C8F3LLtelKjSMeOzC9QAfey0k6++9pZ28Tki2rspG4oPrln+sox+M164Swk6qVWm T8YOgTRzWTID8iPrq4QDQJJGbi33J6hlJUJT8HLI0Ahs3WMRneYY1gnEgVjIRKZX tpsx4OLwTsIjieqPqbjLD0= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by smtp19 (Coremail) with SMTP id R9xpCgAnKa0IqglkPaTXGw--.56707S2; Thu, 09 Mar 2023 17:42:33 +0800 (CST) From: Zheng Wang <zyytlz.wz@163.com> To: davem@davemloft.net Cc: edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, Zheng Wang <zyytlz.wz@163.com> Subject: [PATCH net] net: ethernet: fix use after free bug in ns83820_remove_one due to race condition Date: Thu, 9 Mar 2023 17:42:31 +0800 Message-Id: <20230309094231.3808770-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: R9xpCgAnKa0IqglkPaTXGw--.56707S2 X-Coremail-Antispam: 1Uf129KBjvdXoWrtw45WryrZFyDWFy3KFWDCFg_yoWkXrcEg3 srZF4Skw4UKr1rtw4UGrsxX34jkr9Y9r9Y9rWDta9Iv343Kws5Cw1kur1fJr48uwnxJFW2 kry7KFyfA343AjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRKBT5JUUUUU== X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiQgktU1aEEmftKQAAsW 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?1759884614926293415?= X-GMAIL-MSGID: =?utf-8?q?1759884614926293415?= |
Series |
[net] net: ethernet: fix use after free bug in ns83820_remove_one due to race condition
|
|
Commit Message
Zheng Wang
March 9, 2023, 9:42 a.m. UTC
In ns83820_init_one, dev->tq_refill was bound with queue_refill.
If irq happens, it will call ns83820_irq->ns83820_do_isr.
Then it invokes tasklet_schedule(&dev->rx_tasklet) to start
rx_action function. And rx_action will call ns83820_rx_kick
and finally start queue_refill function.
If we remove the driver without finishing the work, there
may be a race condition between ndev, which may cause UAF
bug.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
drivers/net/ethernet/natsemi/ns83820.c | 1 +
1 file changed, 1 insertion(+)
Comments
On Thu, 9 Mar 2023 17:42:31 +0800 Zheng Wang wrote: > + cancel_work_sync(&dev->tq_refill); > ns83820_disable_interrupts(dev); /* paranoia */ > > unregister_netdev(ndev); Canceling the work before unregister can't work. Please take a closer look, the work to refill a ring should be canceled when the ring itself is dismantled.
Jakub Kicinski <kuba@kernel.org> 于2023年3月14日周二 07:26写道: > > On Thu, 9 Mar 2023 17:42:31 +0800 Zheng Wang wrote: > > + cancel_work_sync(&dev->tq_refill); > > ns83820_disable_interrupts(dev); /* paranoia */ > > > > unregister_netdev(ndev); > > Canceling the work before unregister can't work. > Please take a closer look, the work to refill a ring should be > canceled when the ring itself is dismantled. Hi Jakub, Thanks for your review! After seeing code again, I found when handling IRQ request, it will finally call ns83820_irq->ns83820_do_isr-> ns83820_rx_kick->schedule_work to start work. So I think we should move the code after free_irq. What do you think? Best regards, Zheng
On Tue, 14 Mar 2023 09:59:09 +0800 Zheng Hacker wrote: > Jakub Kicinski <kuba@kernel.org> 于2023年3月14日周二 07:26写道: > > On Thu, 9 Mar 2023 17:42:31 +0800 Zheng Wang wrote: > > > + cancel_work_sync(&dev->tq_refill); > > > ns83820_disable_interrupts(dev); /* paranoia */ > > > > > > unregister_netdev(ndev); > > > > Canceling the work before unregister can't work. > > Please take a closer look, the work to refill a ring should be > > canceled when the ring itself is dismantled. > > Hi Jakub, > > Thanks for your review! After seeing code again, I found when handling > IRQ request, it will finally call ns83820_irq->ns83820_do_isr-> > ns83820_rx_kick->schedule_work to start work. So I think we should > move the code after free_irq. What do you think? Sorry, we have over 300 patches which need reviews. I don't have the time to help you. Perhaps someone else will. Please make sure you work on a single networking fix at a time. All the patches you posted had the same issues.
Jakub Kicinski <kuba@kernel.org> 于2023年3月15日周三 12:10写道: > > On Tue, 14 Mar 2023 09:59:09 +0800 Zheng Hacker wrote: > > Jakub Kicinski <kuba@kernel.org> 于2023年3月14日周二 07:26写道: > > > On Thu, 9 Mar 2023 17:42:31 +0800 Zheng Wang wrote: > > > > + cancel_work_sync(&dev->tq_refill); > > > > ns83820_disable_interrupts(dev); /* paranoia */ > > > > > > > > unregister_netdev(ndev); > > > > > > Canceling the work before unregister can't work. > > > Please take a closer look, the work to refill a ring should be > > > canceled when the ring itself is dismantled. > > > > Hi Jakub, > > > > Thanks for your review! After seeing code again, I found when handling > > IRQ request, it will finally call ns83820_irq->ns83820_do_isr-> > > ns83820_rx_kick->schedule_work to start work. So I think we should > > move the code after free_irq. What do you think? > > Sorry, we have over 300 patches which need reviews. I don't have > the time to help you. Perhaps someone else will. > Hi Jakub, Thanks for your precious and kind reminder. I'll think about it again and write the next version of patch. > Please make sure you work on a single networking fix at a time. > All the patches you posted had the same issues. Yes, I'll keep that in mind. Best regards, Zheng
diff --git a/drivers/net/ethernet/natsemi/ns83820.c b/drivers/net/ethernet/natsemi/ns83820.c index 998586872599..285fe0fa33eb 100644 --- a/drivers/net/ethernet/natsemi/ns83820.c +++ b/drivers/net/ethernet/natsemi/ns83820.c @@ -2206,6 +2206,7 @@ static void ns83820_remove_one(struct pci_dev *pci_dev) if (!ndev) /* paranoia */ return; + cancel_work_sync(&dev->tq_refill); ns83820_disable_interrupts(dev); /* paranoia */ unregister_netdev(ndev);