Message ID | 20230413033422.28003-1-zyytlz.wz@163.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp762325vqo; Wed, 12 Apr 2023 20:44:31 -0700 (PDT) X-Google-Smtp-Source: AKy350YU4R60NR7/BQUjNIUu3HEv1zFwwsC14kmwTWJitewKIQDqfcSuB1TnsB2NCJ5EFqARpEH4 X-Received: by 2002:a17:906:140f:b0:94e:2db:533e with SMTP id p15-20020a170906140f00b0094e02db533emr993336ejc.49.1681357470980; Wed, 12 Apr 2023 20:44:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681357470; cv=none; d=google.com; s=arc-20160816; b=jSYGT1rq0c0k5BEuZmaR0MQ56o7PsACw5rO6TN2wL8Q/NEJ0UqlP3ZJ+MjQ85F3bPL JYuzeEFQKe+8aPPmJUTNhe81ij3N2KcxB0HLOBMdmn3kYPnL1b1Gf64oTuLpJCQi4TTx NyyRGusvmSMGInL3T4goqlqdNl2OKT/TUZzniQ+fsIpu7DVayYGkgAI3dg55SlecaJO8 oTIqfdQJrGWrpm+Nwg401RPeHlT7kOu612xgONlUelUA4euo/x1tTO162BnEcIiZSRb2 +b8lfdsY1c1/G4/7TYgN5oZlqqAi/oCpnBz+UxWsyRDqoZwduQu2ieanHcyluW6eCsAw lmqw== 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=lIcVfdDOG5loBmiWhCLSBqSRWz3dIU8sdeChu5hTPJE=; b=AuP7/ZkcjOAzudil2A0G4SDBYHAGW/RjkkC7iqlvNOGtr3X5RbQ1YiC1D1I6F0NS5Q 3F/XRQ0E6UKj7wdb9u8IOAahAaXBx+Oinhu6G9CSO5WzwlneAig/Dorl3QYqSAN1TR9Y NGhRCA05rDOhtWHXx6hLkW0Ux9evgaU7hWJJsDwXN1ea9VFwV0uO0Y38HnxXtaz0W/v/ YrfSgHf9lMZBHtsPpDR8fluiO02Ge6ZvG4CuAKApgRhbPlDoX/+TR7mFn5kn32QzOPfy npwXFIWy4EOYUphiezfqIW0aMNtL8YxdA58h/3QNk8F8AraBJuw9kdALoPU2H/WyJDZi 1Awg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=Z4NDFiWA; 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 ep21-20020a1709069b5500b009094a93d9b7si693008ejc.990.2023.04.12.20.44.06; Wed, 12 Apr 2023 20:44:30 -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=Z4NDFiWA; 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 S229720AbjDMDfB (ORCPT <rfc822;peter110.wang@gmail.com> + 99 others); Wed, 12 Apr 2023 23:35:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229870AbjDMDeh (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 12 Apr 2023 23:34:37 -0400 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.216]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9510772BB; Wed, 12 Apr 2023 20:34:34 -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=lIcVf dDOG5loBmiWhCLSBqSRWz3dIU8sdeChu5hTPJE=; b=Z4NDFiWAEX/oY3sAbcKf8 f/uZQI44HOhZ+dKeMudg4EHiU4h8+fBE9LtBSVGtKEQjZpcQyUjLXLS9bvo0nsqZ p2I1uIfe7I++JOkWrWfRjj4aXt5GRC51tcJ3b/e/uK5rW+axmzlGOUd2UsiQqxPI v43chJJnWtRddW+1vkA4ik= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g2-4 (Coremail) with SMTP id _____wBXFM0_eDdkjKocBQ--.60991S2; Thu, 13 Apr 2023 11:34:23 +0800 (CST) From: Zheng Wang <zyytlz.wz@163.com> To: njavali@marvell.com Cc: mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com, jejb@linux.ibm.com, martin.petersen@oracle.com, linux-scsi@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 v2] scsi: qedi: Fix use after free bug in qedi_remove due to race condition Date: Thu, 13 Apr 2023 11:34:22 +0800 Message-Id: <20230413033422.28003-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wBXFM0_eDdkjKocBQ--.60991S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Kw17Gry3WFWUtFWUWr4UArb_yoW8Wr48pr ZxGa4Fkw45KFyrXFn8JF10qFy0kayDtFW0ga97W3y7X3Wa93ykZFySka4jgFyUJFs2va17 tF1kXFy3W3WDGaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zimFAAUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiQgRPU1aEE9wfvgACsk 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?1763031091544348047?= X-GMAIL-MSGID: =?utf-8?q?1763031091544348047?= |
Series |
[v2] scsi: qedi: Fix use after free bug in qedi_remove due to race condition
|
|
Commit Message
Zheng Wang
April 13, 2023, 3:34 a.m. UTC
In qedi_probe, it calls __qedi_probe, which bound &qedi->recovery_work
with qedi_recovery_handler and bound &qedi->board_disable_work
with qedi_board_disable_work.
When it calls qedi_schedule_recovery_handler, it will finally
call schedule_delayed_work to start the work.
When we call qedi_remove to remove the driver, there
may be a sequence as follows:
Fix it by finishing the work before cleanup in qedi_remove.
CPU0 CPU1
|qedi_recovery_handler
qedi_remove |
__qedi_remove |
iscsi_host_free |
scsi_host_put |
//free shost |
|iscsi_host_for_each_session
|//use qedi->shost
Fixes: 4b1068f5d74b ("scsi: qedi: Add MFW error recovery process")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
v2:
- remove unnecessary comment suggested by Mike Christie and cancel the work
after qedi_ops->stop and qedi_ops->ll2->stop which ensure there is no more
work suggested by Manish Rangankar
---
drivers/scsi/qedi/qedi_main.c | 3 +++
1 file changed, 3 insertions(+)
Comments
> -----Original Message----- > From: Zheng Wang <zyytlz.wz@163.com> > Sent: Thursday, April 13, 2023 9:04 AM > To: Nilesh Javali <njavali@marvell.com> > Cc: Manish Rangankar <mrangankar@marvell.com>; GR-QLogic-Storage- > Upstream <GR-QLogic-Storage-Upstream@marvell.com>; > jejb@linux.ibm.com; martin.petersen@oracle.com; linux- > scsi@vger.kernel.org; linux-kernel@vger.kernel.org; > hackerzheng666@gmail.com; 1395428693sheep@gmail.com; > alex000young@gmail.com; Zheng Wang <zyytlz.wz@163.com> > Subject: [EXT] [PATCH v2] scsi: qedi: Fix use after free bug in qedi_remove > due to race condition > > External Email > > ---------------------------------------------------------------------- > In qedi_probe, it calls __qedi_probe, which bound &qedi->recovery_work > with qedi_recovery_handler and bound &qedi->board_disable_work with > qedi_board_disable_work. > > When it calls qedi_schedule_recovery_handler, it will finally call > schedule_delayed_work to start the work. > > When we call qedi_remove to remove the driver, there may be a sequence > as follows: > > Fix it by finishing the work before cleanup in qedi_remove. > > CPU0 CPU1 > > |qedi_recovery_handler > qedi_remove | > __qedi_remove | > iscsi_host_free | > scsi_host_put | > //free shost | > |iscsi_host_for_each_session > |//use qedi->shost > > Fixes: 4b1068f5d74b ("scsi: qedi: Add MFW error recovery process") > Signed-off-by: Zheng Wang <zyytlz.wz@163.com> > --- > v2: > - remove unnecessary comment suggested by Mike Christie and cancel the > work after qedi_ops->stop and qedi_ops->ll2->stop which ensure there is no > more work suggested by Manish Rangankar > --- > drivers/scsi/qedi/qedi_main.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c > index f2ee49756df8..45d359554182 100644 > --- a/drivers/scsi/qedi/qedi_main.c > +++ b/drivers/scsi/qedi/qedi_main.c > @@ -2450,6 +2450,9 @@ static void __qedi_remove(struct pci_dev *pdev, > int mode) > qedi_ops->ll2->stop(qedi->cdev); > } > > + cancel_delayed_work_sync(&qedi->recovery_work); > + cancel_delayed_work_sync(&qedi->board_disable_work); > + > qedi_free_iscsi_pf_param(qedi); > > rval = qedi_ops->common->update_drv_state(qedi->cdev, false); > -- > 2.25.1 Thanks, Acked-by: Manish Rangankar <mrangankar@marvell.com>
On 4/12/23 10:34 PM, Zheng Wang wrote: > In qedi_probe, it calls __qedi_probe, which bound &qedi->recovery_work > with qedi_recovery_handler and bound &qedi->board_disable_work > with qedi_board_disable_work. > > When it calls qedi_schedule_recovery_handler, it will finally > call schedule_delayed_work to start the work. > > When we call qedi_remove to remove the driver, there > may be a sequence as follows: > > Fix it by finishing the work before cleanup in qedi_remove. > > CPU0 CPU1 > > |qedi_recovery_handler > qedi_remove | > __qedi_remove | > iscsi_host_free | > scsi_host_put | > //free shost | > |iscsi_host_for_each_session > |//use qedi->shost > > Fixes: 4b1068f5d74b ("scsi: qedi: Add MFW error recovery process") > Signed-off-by: Zheng Wang <zyytlz.wz@163.com> > --- > v2: > - remove unnecessary comment suggested by Mike Christie and cancel the work > after qedi_ops->stop and qedi_ops->ll2->stop which ensure there is no more > work suggested by Manish Rangankar Look ok to me now. Thanks. Reviewed-by: Mike Christie <michael.christie@oracle.com>
Manish Rangankar <mrangankar@marvell.com> 于2023年4月20日周四 13:49写道: > > > > > -----Original Message----- > > From: Zheng Wang <zyytlz.wz@163.com> > > Sent: Thursday, April 13, 2023 9:04 AM > > To: Nilesh Javali <njavali@marvell.com> > > Cc: Manish Rangankar <mrangankar@marvell.com>; GR-QLogic-Storage- > > Upstream <GR-QLogic-Storage-Upstream@marvell.com>; > > jejb@linux.ibm.com; martin.petersen@oracle.com; linux- > > scsi@vger.kernel.org; linux-kernel@vger.kernel.org; > > hackerzheng666@gmail.com; 1395428693sheep@gmail.com; > > alex000young@gmail.com; Zheng Wang <zyytlz.wz@163.com> > > Subject: [EXT] [PATCH v2] scsi: qedi: Fix use after free bug in qedi_remove > > due to race condition > > > > External Email > > > > ---------------------------------------------------------------------- > > In qedi_probe, it calls __qedi_probe, which bound &qedi->recovery_work > > with qedi_recovery_handler and bound &qedi->board_disable_work with > > qedi_board_disable_work. > > > > When it calls qedi_schedule_recovery_handler, it will finally call > > schedule_delayed_work to start the work. > > > > When we call qedi_remove to remove the driver, there may be a sequence > > as follows: > > > > Fix it by finishing the work before cleanup in qedi_remove. > > > > CPU0 CPU1 > > > > |qedi_recovery_handler > > qedi_remove | > > __qedi_remove | > > iscsi_host_free | > > scsi_host_put | > > //free shost | > > |iscsi_host_for_each_session > > |//use qedi->shost > > > > Fixes: 4b1068f5d74b ("scsi: qedi: Add MFW error recovery process") > > Signed-off-by: Zheng Wang <zyytlz.wz@163.com> > > --- > > v2: > > - remove unnecessary comment suggested by Mike Christie and cancel the > > work after qedi_ops->stop and qedi_ops->ll2->stop which ensure there is no > > more work suggested by Manish Rangankar > > --- > > drivers/scsi/qedi/qedi_main.c | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c > > index f2ee49756df8..45d359554182 100644 > > --- a/drivers/scsi/qedi/qedi_main.c > > +++ b/drivers/scsi/qedi/qedi_main.c > > @@ -2450,6 +2450,9 @@ static void __qedi_remove(struct pci_dev *pdev, > > int mode) > > qedi_ops->ll2->stop(qedi->cdev); > > } > > > > + cancel_delayed_work_sync(&qedi->recovery_work); > > + cancel_delayed_work_sync(&qedi->board_disable_work); > > + > > qedi_free_iscsi_pf_param(qedi); > > > > rval = qedi_ops->common->update_drv_state(qedi->cdev, false); > > -- > > 2.25.1 > > Thanks, > > Acked-by: Manish Rangankar <mrangankar@marvell.com> > Thanks for your review. Best regards, Zheng
Mike Christie <michael.christie@oracle.com> 于2023年4月20日周四 23:39写道: > > On 4/12/23 10:34 PM, Zheng Wang wrote: > > In qedi_probe, it calls __qedi_probe, which bound &qedi->recovery_work > > with qedi_recovery_handler and bound &qedi->board_disable_work > > with qedi_board_disable_work. > > > > When it calls qedi_schedule_recovery_handler, it will finally > > call schedule_delayed_work to start the work. > > > > When we call qedi_remove to remove the driver, there > > may be a sequence as follows: > > > > Fix it by finishing the work before cleanup in qedi_remove. > > > > CPU0 CPU1 > > > > |qedi_recovery_handler > > qedi_remove | > > __qedi_remove | > > iscsi_host_free | > > scsi_host_put | > > //free shost | > > |iscsi_host_for_each_session > > |//use qedi->shost > > > > Fixes: 4b1068f5d74b ("scsi: qedi: Add MFW error recovery process") > > Signed-off-by: Zheng Wang <zyytlz.wz@163.com> > > --- > > v2: > > - remove unnecessary comment suggested by Mike Christie and cancel the work > > after qedi_ops->stop and qedi_ops->ll2->stop which ensure there is no more > > work suggested by Manish Rangankar > > Look ok to me now. Thanks. > > Reviewed-by: Mike Christie <michael.christie@oracle.com> Thanks for your review. Best regards, Zheng
Zheng, > In qedi_probe, it calls __qedi_probe, which bound &qedi->recovery_work > with qedi_recovery_handler and bound &qedi->board_disable_work > with qedi_board_disable_work. Applied to 6.4/scsi-staging, thanks!
diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c index f2ee49756df8..45d359554182 100644 --- a/drivers/scsi/qedi/qedi_main.c +++ b/drivers/scsi/qedi/qedi_main.c @@ -2450,6 +2450,9 @@ static void __qedi_remove(struct pci_dev *pdev, int mode) qedi_ops->ll2->stop(qedi->cdev); } + cancel_delayed_work_sync(&qedi->recovery_work); + cancel_delayed_work_sync(&qedi->board_disable_work); + qedi_free_iscsi_pf_param(qedi); rval = qedi_ops->common->update_drv_state(qedi->cdev, false);