Message ID | 20230312160837.2040857-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 v21csp795218wrd; Sun, 12 Mar 2023 09:52:05 -0700 (PDT) X-Google-Smtp-Source: AK7set9oOugFhKLk0QjzrKGFurD40HrAtEYJU0vMXHsogjfP5G0U43VCl9kdB98/npTLAeWXNCCT X-Received: by 2002:a05:6a20:258a:b0:cc:868f:37b3 with SMTP id k10-20020a056a20258a00b000cc868f37b3mr32541301pzd.58.1678639925141; Sun, 12 Mar 2023 09:52:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678639925; cv=none; d=google.com; s=arc-20160816; b=opNXAILnmwYIRBeCJ8207rfMNhOOKRnfddDoCXQsdRpet7xxMCKE1PQvv2dY89jyrd QbjPyHN92rVWk5Gn/m/XD+4QKHYgDIQUL7DAgoaG8js31sUuDBWeQhybj4rt5GU+evkl fbs84G2bB76FxmndRFHocFq2Zoi8iItcO85rsunO9V7ej6kJ7unerDK6OETalNLpo0R8 jHyq/tPdvk8CqolxbKyEPyWWXzOivjYBn1utxdkokNbi9u/c1ndtjVnUf4PvIKYbrknx LJlA3Q5CWox+/FebDrbSfViQTsaddq/f+N1TlecSrbODg5QPTltH86EZs3bwGTt8NYVv nvtQ== 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=KI84VtG+lYqaZnPKW41rtqtNaa7xafoaTjef1FxWfNk=; b=aUFS/8kWVSx6Mi0OONQcGKA4OtdHHR/OewUm6JeeEXNrGQ9jgt7BCsL2Wy6pfxCTEy aN0C2100eEkZ3NmnThQZotWDjxxtIpY6b7fia9ZL0oxDpA0KeF9vO/5WAGZnkqoNLLYs Jy6V9s8kKCo2Gil5J7dO3+u8te3qSEyH3tU44zQ8rYX04C1kSHh263IIGvbnS5nwLKmj vQKuCOQIi1IwSspvP7aUlyF77CNVXOgjXhe74BP3yYxZ0p1FmmeHomZ8j0b/gtJHMcGC 8eNFMQoks9rJuOqLz86JeIWeInXz60j8hn99OhEzkEimtboQHMU1kd8z5txQZY5ml5TB pCdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=O5JbGqq+; 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 t189-20020a6381c6000000b0050a16d20f02si1521310pgd.688.2023.03.12.09.51.49; Sun, 12 Mar 2023 09:52:05 -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; dkim=pass header.i=@163.com header.s=s110527 header.b=O5JbGqq+; 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 S230071AbjCLQJS (ORCPT <rfc822;realc9580@gmail.com> + 99 others); Sun, 12 Mar 2023 12:09:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230050AbjCLQJP (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 12 Mar 2023 12:09:15 -0400 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.216]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B23AB36454; Sun, 12 Mar 2023 09:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=KI84V tG+lYqaZnPKW41rtqtNaa7xafoaTjef1FxWfNk=; b=O5JbGqq+arN23HQxkzzqT 16DPhluNdsKhhWqNAGjvgJcToQ6opfINB3wmSN4fXeJc/1htJfJaDJWI4MSLJUqF 36WIXaAuxlR3igqyXLTJljNN4fM0BnlmCT2VnDZVVWeUWADVy0kLvE3FvoTNj8/G Pz91ZBKEjEUzGqIb5lf2BE= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g4-3 (Coremail) with SMTP id _____wAXRBAG+Q1kULNrDA--.9072S2; Mon, 13 Mar 2023 00:08:38 +0800 (CST) From: Zheng Wang <zyytlz.wz@163.com> To: krzysztof.kozlowski@linaro.org Cc: 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] nfc: st-nci: Fix use after free bug in ndlc_remove due to race condition Date: Mon, 13 Mar 2023 00:08:37 +0800 Message-Id: <20230312160837.2040857-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wAXRBAG+Q1kULNrDA--.9072S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7WFyrJFyrKw47KFy7WF18uFg_yoW8XFWkpr ZxXryruFWrGF4FyFZ7WF4UGr1YkwsrtryDK3y3W343ZFnayrs0qr92yFW5uF1IqF4IyFW2 y3yDX3Z8Ja4kCa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziJDGrUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiXQkwU1WBo4he9QAAsj 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,RCVD_IN_MSPIKE_H2, 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?1760181537748682111?= X-GMAIL-MSGID: =?utf-8?q?1760181537748682111?= |
Series |
nfc: st-nci: Fix use after free bug in ndlc_remove due to race condition
|
|
Commit Message
Zheng Wang
March 12, 2023, 4:08 p.m. UTC
This bug influences both st_nci_i2c_remove and st_nci_spi_remove.
Take st_nci_i2c_remove as an example.
In st_nci_i2c_probe, it called ndlc_probe and bound &ndlc->sm_work
with llt_ndlc_sm_work.
When it calls ndlc_recv or timeout handler, it will finally call
schedule_work to start the work.
When we call st_nci_i2c_remove to remove the driver, there
may be a sequence as follows:
Fix it by finishing the work before cleanup in ndlc_remove
CPU0 CPU1
|llt_ndlc_sm_work
st_nci_i2c_remove |
ndlc_remove |
st_nci_remove |
nci_free_device|
kfree(ndev) |
//free ndlc->ndev |
|llt_ndlc_rcv_queue
|nci_recv_frame
|//use ndlc->ndev
Fixes: 35630df68d60 ("NFC: st21nfcb: Add driver for STMicroelectronics ST21NFCB NFC chip")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
drivers/nfc/st-nci/ndlc.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
Comments
On 12/03/2023 17:08, Zheng Wang wrote: > This bug influences both st_nci_i2c_remove and st_nci_spi_remove. > Take st_nci_i2c_remove as an example. > > In st_nci_i2c_probe, it called ndlc_probe and bound &ndlc->sm_work > with llt_ndlc_sm_work. > > When it calls ndlc_recv or timeout handler, it will finally call > schedule_work to start the work. > > When we call st_nci_i2c_remove to remove the driver, there > may be a sequence as follows: > > Fix it by finishing the work before cleanup in ndlc_remove Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Best regards, Krzysztof
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> 于2023年3月13日周一 14:52写道: > > On 12/03/2023 17:08, Zheng Wang wrote: > > This bug influences both st_nci_i2c_remove and st_nci_spi_remove. > > Take st_nci_i2c_remove as an example. > > > > In st_nci_i2c_probe, it called ndlc_probe and bound &ndlc->sm_work > > with llt_ndlc_sm_work. > > > > When it calls ndlc_recv or timeout handler, it will finally call > > schedule_work to start the work. > > > > When we call st_nci_i2c_remove to remove the driver, there > > may be a sequence as follows: > > > > Fix it by finishing the work before cleanup in ndlc_remove > > > Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> > Thanks for the detailed review. Best regards, Zheng > Best regards, > Krzysztof >
Hello: This patch was applied to netdev/net.git (main) by Jakub Kicinski <kuba@kernel.org>: On Mon, 13 Mar 2023 00:08:37 +0800 you wrote: > This bug influences both st_nci_i2c_remove and st_nci_spi_remove. > Take st_nci_i2c_remove as an example. > > In st_nci_i2c_probe, it called ndlc_probe and bound &ndlc->sm_work > with llt_ndlc_sm_work. > > When it calls ndlc_recv or timeout handler, it will finally call > schedule_work to start the work. > > [...] Here is the summary with links: - nfc: st-nci: Fix use after free bug in ndlc_remove due to race condition https://git.kernel.org/netdev/net/c/5000fe6c2782 You are awesome, thank you!
diff --git a/drivers/nfc/st-nci/ndlc.c b/drivers/nfc/st-nci/ndlc.c index 755460a73c0d..d2aa9f766738 100644 --- a/drivers/nfc/st-nci/ndlc.c +++ b/drivers/nfc/st-nci/ndlc.c @@ -282,13 +282,15 @@ EXPORT_SYMBOL(ndlc_probe); void ndlc_remove(struct llt_ndlc *ndlc) { - st_nci_remove(ndlc->ndev); - /* cancel timers */ del_timer_sync(&ndlc->t1_timer); del_timer_sync(&ndlc->t2_timer); ndlc->t2_active = false; ndlc->t1_active = false; + /* cancel work */ + cancel_work_sync(&ndlc->sm_work); + + st_nci_remove(ndlc->ndev); skb_queue_purge(&ndlc->rcv_q); skb_queue_purge(&ndlc->send_q);