From patchwork Mon Mar 13 08:46:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Wang X-Patchwork-Id: 68695 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1074243wrd; Mon, 13 Mar 2023 02:04:14 -0700 (PDT) X-Google-Smtp-Source: AK7set98Z1OnpurjDCzQSqoJ7WYPdOXVi55qu/tNmCfSsF88NlgnFlXDby4YxggqAr37QqOtiaWJ X-Received: by 2002:aa7:9a50:0:b0:61d:e10f:4e70 with SMTP id x16-20020aa79a50000000b0061de10f4e70mr13587012pfj.0.1678698254430; Mon, 13 Mar 2023 02:04:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678698254; cv=none; d=google.com; s=arc-20160816; b=HeZ6rmpCBudH6PJ8hCwp9k0k4gcNoP+JnyQCQsdd8lkeNDnC+c6axIdZta5IOz0bnm PgZQ504e7/TQTN7M0nclz9Ab6fO+W8BiOYu2bleLj0UINPdmfN+myUvhF91sTDJHOUMP ajZsbgY+xw20zBCrX+bVOCZtogeGORHtcDuO3RlUg7twrsKhl56ZjiN8v81+MbleXy1l Upjy+Sg9TV4zGFbC6/DK7bHtVGr1fAQySD2/I/9x8qoM5alDKv2VWz27wqzQ38RNM6o5 qQbRQMlaceZ6TP9ikxEWHSe34Jdsd5mtTjXf/61+uwPT0mn2uJx4OFDlNG7GzQcCxkAS fX+w== 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=0txFruaHYw7D6gvoux40mvteetA7L1PU1RtHGjVt8xg=; b=RIovMw5iH7jxU94i0dx8H50hfTjrVNU9FGzWJ3H6KVH5zo3Jd/pHjRkTQMiNDRchD5 mc0CBVSOgZfXnTSEh3UFxNP7ap7Ey8p65wgTWOkXSGvSoFzD7TPrU8ZL9bsP+2cY31wY aMTnUFGgMf7ZBFkHlYxfnUxl21rAWWtnCb060McX+vVDu22GqKOAFiqi9fxV9DHHCjQi rqRkzAqZh2U/v6hdSTC35qQjeYkEx1UqACd22VG1sKivXdW/ad/ub5x35UnKidpKHF3f 4NEIOGejiT2UhftpJ7oMsmWNDjBpxwZQ4j1EXEFLTcLfg845ZVhcCl/oiNFuuqIy5da3 HATQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=TF8AwXNM; 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 m10-20020a6545ca000000b00502d825633asi6086230pgr.639.2023.03.13.02.04.00; Mon, 13 Mar 2023 02:04:14 -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=TF8AwXNM; 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 S230200AbjCMIti (ORCPT + 99 others); Mon, 13 Mar 2023 04:49:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229656AbjCMItP (ORCPT ); Mon, 13 Mar 2023 04:49:15 -0400 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A4D6A58C09; Mon, 13 Mar 2023 01:47:31 -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=0txFr uaHYw7D6gvoux40mvteetA7L1PU1RtHGjVt8xg=; b=TF8AwXNMXQf08Db5rwAMq ZwRjqdhx82roChU596x3fM5nJ4AJIf7lSEW4TFThc78tHAY03YYJZr3YzKBOY1vk Jlj+B8oNYfE2BV7InhHMKKkURwGNiLCJLCemTbzhdmA/TGI25qPsF6Mfo7uLN3sJ oosPsM+nsVPkF6gctSMLuo= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g4-2 (Coremail) with SMTP id _____wD3_cXQ4g5k_c0fAA--.6206S2; Mon, 13 Mar 2023 16:46:08 +0800 (CST) From: Zheng Wang 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 Subject: [PATCH] scsi: qedi: Fix use after free bug in qedi_remove due to race condition Date: Mon, 13 Mar 2023 16:46:07 +0800 Message-Id: <20230313084607.3297813-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: _____wD3_cXQ4g5k_c0fAA--.6206S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Kw17Gry3WFWUtFWUWr4UArb_yoW8GF43pr ZxGryfCw1UWa4FqFn8J3W0qFy0k3yDtFW0ga97Ww47X3W3u3yqv34Ika4jgry7JFZ2qa17 tF4xXFy7WFyDG3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziaZXrUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiQhgxU1aEEo7UBwAAsl 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_MSPIKE_H2, 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760242701270243639?= X-GMAIL-MSGID: =?utf-8?q?1760242701270243639?= 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 --- drivers/scsi/qedi/qedi_main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c index f2ee49756df8..25223f6f5344 100644 --- a/drivers/scsi/qedi/qedi_main.c +++ b/drivers/scsi/qedi/qedi_main.c @@ -2414,6 +2414,10 @@ static void __qedi_remove(struct pci_dev *pdev, int mode) int rval; u16 retry = 10; + /*cancel work*/ + cancel_delayed_work_sync(&qedi->recovery_work); + cancel_delayed_work_sync(&qedi->board_disable_work); + if (mode == QEDI_MODE_NORMAL) iscsi_host_remove(qedi->shost, false); else if (mode == QEDI_MODE_SHUTDOWN)