Message ID | 20230307164338.1246287-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 v21csp2541053wrd; Tue, 7 Mar 2023 08:59:55 -0800 (PST) X-Google-Smtp-Source: AK7set8/HHX4UQwcp6gOo/GAlKZw2M+kkedhA+/N+zhKhk7G2j8miM/wwPsCtiE5TXoJmIVvDUTO X-Received: by 2002:a17:907:d109:b0:878:78f9:d1be with SMTP id uy9-20020a170907d10900b0087878f9d1bemr14471380ejc.23.1678208395725; Tue, 07 Mar 2023 08:59:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678208395; cv=none; d=google.com; s=arc-20160816; b=zis0iAHAQW0o0PMZd/XXYJ2U/aRn8XwQMfd/SplG0k4fKeObvXhxup8dWe5jYDAFiX /wieksaLy2x9sdg85TtGtCpDqCATljXYedgJqHFRq2+9wyYjl6JwaqlNclMJJWSH+8T+ lHxzmodEok2oV2aHolmFO3h9OFqbNxerLQAZxMXlT7z9ZVgCxx5iBoiH1W/1ImzTdYwU O7P0dYnPVAc6I3kP+qpUecDp/w1n0pKCZdyr+2U0OsRHrMDHtQlhpEEERzRyMDKozAxt QT76Y/S+J5E0s0nSqwURvdB1BwSVVwhN3Sh9Jvio2cGOdupID45iPtQKJZpx4vlGIHeG KOCQ== 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=1ivYQwqOn8JyrJaO1zoBrVOK/bF8D750luT+YfP9nNM=; b=FpKejiHB65BQhiMDFqXzIC2fXxtzV+x9ol6V75bZ1M3c6q4EZbCQWG5AwkZHVaXNzP yaeE8MJWC2DDNm1CJHck2V0WR2Gdorn8Omqf5DQCgrNrYpMoLysCrDFzkb76EAx1J5Pf RbBjcLn8BzzYN9Sv5d1JubEbyTmFGe0bhsoB1XWj98F5t39SwIAqHhOvYOrtY39gXNEY ePiTIYXOF0AUL2hQ3EG+/C/l50z6LM4ls3UKFlY260AIBE8dm+73BIBBKzcddeOY1itN 0wiFSd8h7kJVQnuor5mXyrvguxxcIf4TySc4Nmy9hnR5wviC6aaM87SMkhQERBI4lZe1 2/6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b="N3/JEcH/"; 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 qp12-20020a170907206c00b008bfb217d8e7si2299522ejb.628.2023.03.07.08.59.32; Tue, 07 Mar 2023 08:59:55 -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="N3/JEcH/"; 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 S231295AbjCGQsJ (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Tue, 7 Mar 2023 11:48:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230023AbjCGQrH (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 7 Mar 2023 11:47:07 -0500 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.214]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 24AEB96C1A; Tue, 7 Mar 2023 08:44:10 -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=1ivYQ wqOn8JyrJaO1zoBrVOK/bF8D750luT+YfP9nNM=; b=N3/JEcH/5IYG6OfhhVuz4 tjn+798v15BSmjd9km5CDcux4X+XcJHObmSglh+qyc3/OvtXwJIdhl3V4BujFf7L EcsEX/65UFC2SiVqEkUEuE03SCw8qiu1Us8DYsVUwD5H2zbKdHbBfXw8m3YZPDaj O+mmjHqpXDPcSGhiAS6HcI= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g4-1 (Coremail) with SMTP id _____wD3_x+8aQdkVNnZCQ--.17524S2; Wed, 08 Mar 2023 00:43:40 +0800 (CST) From: Zheng Wang <zyytlz.wz@163.com> To: maximlevitsky@gmail.com Cc: oakad@yahoo.com, ulf.hansson@linaro.org, linux-mmc@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] memstick: r592: Fix UAF bug in r592_remove due to race condition Date: Wed, 8 Mar 2023 00:43:38 +0800 Message-Id: <20230307164338.1246287-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wD3_x+8aQdkVNnZCQ--.17524S2 X-Coremail-Antispam: 1Uf129KBjvdXoW7Jr1rJryfAr4rKrWxGFyUWrg_yoWkuwb_uF yrZFySgr48Grn5Ww1UCFy3ur4Uuw1qgFZ7Za18Kry3JayUGF1UXr1kZr9ava1xu3y29Fy3 CrWUJ3WIgw15ujkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7xRKAwIJUUUUU== X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiGgorU1aEEfnAagABs5 X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_VALIDITY_RPBL,SPF_HELO_NONE,SPF_PASS autolearn=no 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?1759728641750077645?= X-GMAIL-MSGID: =?utf-8?q?1759729046272345998?= |
Series |
memstick: r592: Fix UAF bug in r592_remove due to race condition
|
|
Commit Message
Zheng Wang
March 7, 2023, 4:43 p.m. UTC
In r592_probe, dev->detect_timer was bound with r592_detect_timer.
In r592_irq function, the timer function will be invoked by mod_timer.
If we remove the module which will call hantro_release to make cleanup,
there may be a unfinished work. The possible sequence is as follows,
which will cause a typical UAF bug.
Fix it by canceling the work before cleanup in r592_remove.
CPU0 CPU1
|r592_detect_timer
r592_remove |
memstick_free_host|
put_device; |
kfree(host); |
|
| queue_work
| &host->media_checker //use
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
drivers/memstick/host/r592.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Tue, 7 Mar 2023 at 17:44, Zheng Wang <zyytlz.wz@163.com> wrote: > > In r592_probe, dev->detect_timer was bound with r592_detect_timer. > In r592_irq function, the timer function will be invoked by mod_timer. > > If we remove the module which will call hantro_release to make cleanup, > there may be a unfinished work. The possible sequence is as follows, > which will cause a typical UAF bug. > > Fix it by canceling the work before cleanup in r592_remove. > > CPU0 CPU1 > > |r592_detect_timer > r592_remove | > memstick_free_host| > put_device; | > kfree(host); | > | > | queue_work > | &host->media_checker //use > > Signed-off-by: Zheng Wang <zyytlz.wz@163.com> Applied for next, thanks! Kind regards Uffe > --- > drivers/memstick/host/r592.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c > index 1d35d147552d..2bfa7eaae80a 100644 > --- a/drivers/memstick/host/r592.c > +++ b/drivers/memstick/host/r592.c > @@ -829,7 +829,7 @@ static void r592_remove(struct pci_dev *pdev) > /* Stop the processing thread. > That ensures that we won't take any more requests */ > kthread_stop(dev->io_thread); > - > + del_timer_sync(&dev->detect_timer); > r592_enable_device(dev, false); > > while (!error && dev->req) { > -- > 2.25.1 >
Ulf Hansson <ulf.hansson@linaro.org> 于2023年3月9日周四 23:02写道: > > On Tue, 7 Mar 2023 at 17:44, Zheng Wang <zyytlz.wz@163.com> wrote: > > > > In r592_probe, dev->detect_timer was bound with r592_detect_timer. > > In r592_irq function, the timer function will be invoked by mod_timer. > > > > If we remove the module which will call hantro_release to make cleanup, > > there may be a unfinished work. The possible sequence is as follows, > > which will cause a typical UAF bug. > > > > Fix it by canceling the work before cleanup in r592_remove. > > > > CPU0 CPU1 > > > > |r592_detect_timer > > r592_remove | > > memstick_free_host| > > put_device; | > > kfree(host); | > > | > > | queue_work > > | &host->media_checker //use > > > > Signed-off-by: Zheng Wang <zyytlz.wz@163.com> > > Applied for next, thanks! > Sorry for my late reply and thanks for your effort! Best regards, Zheng > > > > --- > > drivers/memstick/host/r592.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c > > index 1d35d147552d..2bfa7eaae80a 100644 > > --- a/drivers/memstick/host/r592.c > > +++ b/drivers/memstick/host/r592.c > > @@ -829,7 +829,7 @@ static void r592_remove(struct pci_dev *pdev) > > /* Stop the processing thread. > > That ensures that we won't take any more requests */ > > kthread_stop(dev->io_thread); > > - > > + del_timer_sync(&dev->detect_timer); > > r592_enable_device(dev, false); > > > > while (!error && dev->req) { > > -- > > 2.25.1 > >
diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c index 1d35d147552d..2bfa7eaae80a 100644 --- a/drivers/memstick/host/r592.c +++ b/drivers/memstick/host/r592.c @@ -829,7 +829,7 @@ static void r592_remove(struct pci_dev *pdev) /* Stop the processing thread. That ensures that we won't take any more requests */ kthread_stop(dev->io_thread); - + del_timer_sync(&dev->detect_timer); r592_enable_device(dev, false); while (!error && dev->req) {