Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp409626rwe; Thu, 25 Aug 2022 02:38:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR4+f8mJ8AHjLNIe71oNagQlp7AvwXvpElHu8aYTx1yg2AB72HpNt2ubW4UJXy5vaSpE5npo X-Received: by 2002:a17:906:a0d3:b0:73d:be5b:2b52 with SMTP id bh19-20020a170906a0d300b0073dbe5b2b52mr1845932ejb.727.1661420281228; Thu, 25 Aug 2022 02:38:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661420281; cv=none; d=google.com; s=arc-20160816; b=twqFhdNzdQBCyJYviCkxF9oEFqIGI6zShYRCDSIdztKufxqa3dySgII7WsK04Kidqb spJCdmZ+yOyZcisiwpiceKGIFI4cK20Rtdh5snxz6UkGpQHusO5zDouuv2c9noJVjuiN 4a4IjVZR3/oRC5JVgpKgbAjrNi7u6aIezgNgDQlsQsvZxa6WFDeNRqJD/A2667Ze35ub Y/0k/f+M8+wpRW8sA/xKybgcWtSTHf7KDoPBSmowolwudmxQz2ccrHa1kg21Mc01nXgt j445vySP31z3kuZByGaTherlU++4Q6wpNF8t2qBZTivtbV9RTmsbHHUV5328aGhe+9Lg Ngrg== 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=6kRKPEDJzd7uCW3vEmzwA/9148JjbxPPxtaTCIkn/Jk=; b=uoqnVqRjoL61yuhA6DmxHqoPhW9ZY3PbAa3JFn8bn6LzhqL39Hz5kxofjTZw3T3p4N uXVagsMNQq0Ewddt6Myej/1cg6cO6qTR86BE/xbGNuLISbh7rCRAaiJqWmYnmF1qNmPE 7/XYRxWXIpHwog51S/kbPlxFTT4eMRDm5pRvH7knFC2cnR5bkFVGVGWjGKgoRr154Vdl IwjvnV4OLU3B1vrjHE1FRVB82XZt/gXK9Q/rYVEoGiVkHr6s/gsYWUJC3RL3XpTEWDvY D5JUTXtKt+OuQ9i5zyHiDzjndGrip5cWhsIXxBFnIzlciCqS1c0/RwEbnbqBTqtBGeEO fUdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=UB1taWoi; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dt5-20020a170906b78500b0073cb69ac7eesi3500856ejb.379.2022.08.25.02.37.35; Thu, 25 Aug 2022 02:38:01 -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=UB1taWoi; 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 S233969AbiHYJ2z (ORCPT + 99 others); Thu, 25 Aug 2022 05:28:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240238AbiHYJ2k (ORCPT ); Thu, 25 Aug 2022 05:28:40 -0400 Received: from mail-m974.mail.163.com (mail-m974.mail.163.com [123.126.97.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 99CA7AA4C4; Thu, 25 Aug 2022 02:28:28 -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=6kRKP EDJzd7uCW3vEmzwA/9148JjbxPPxtaTCIkn/Jk=; b=UB1taWoipwDCWnApJL0+y 1Gtp8t3PTwNHHK2BhtQyHjO/zj/B+qiBHJW2aN9VVcfz7labkc8CBC6rWk2rntWm ZWh2Cvvcoc372k1zOO9Idqg8a39I8YQR9q4VSRpeR6vEvhN2WW5Ag23XxyiNUtQx NRrAnD4QGtJ/oL++LAlN1g= Received: from localhost.localdomain (unknown [116.128.244.169]) by smtp4 (Coremail) with SMTP id HNxpCgCXduOUQAdjbzILXg--.6127S2; Thu, 25 Aug 2022 17:27:49 +0800 (CST) From: huhai <15815827059@163.com> To: jejb@linux.ibm.com, martin.petersen@oracle.com Cc: sathya.prakash@broadcom.com, sreekanth.reddy@broadcom.com, suganath-prabu.subramani@broadcom.com, MPT-FusionLinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, huhai , stable@vger.kernel.org, Jackie Liu Subject: [PATCH] scsi: mpt3sas: Fix NULL pointer crash due to missing check device hostdata Date: Thu, 25 Aug 2022 17:26:45 +0800 Message-Id: <20220825092645.326953-1-15815827059@163.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: HNxpCgCXduOUQAdjbzILXg--.6127S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxur1UtFWrCFy8GryDCFWDCFg_yoW5KrWUpr 98C34Fkr4kGr42g3W7Wa1UZr15Ja13AF10gF4Iv34kWF1Uu34qqry8tr4jyF18GrW5X3WU tF4qqrn5KFWDJaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UEsj8UUUUU= X-Originating-IP: [116.128.244.169] X-CM-SenderInfo: rprvmiivyslimvzbiqqrwthudrp/1tbiRRVohWDuxhOu4QAAsp X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,FROM_LOCAL_DIGITS,FROM_LOCAL_HEX,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: huhai If _scsih_io_done() is called with scmd->device->hostdata=NULL, it can lead to the following panic: BUG: unable to handle kernel NULL pointer dereference at 0000000000000018 PGD 4547a4067 P4D 4547a4067 PUD 0 Oops: 0002 [#1] SMP NOPTI CPU: 62 PID: 0 Comm: swapper/62 Kdump: loaded Not tainted 4.19.90-24.4.v2101.ky10.x86_64 #1 Hardware name: Storage Server/65N32-US, BIOS SQL1041217 05/30/2022 RIP: 0010:_scsih_set_satl_pending+0x2d/0x50 [mpt3sas] Code: 00 00 48 8b 87 60 01 00 00 0f b6 10 80 fa a1 74 09 31 c0 80 fa 85 74 02 f3 c3 48 8b 47 38 40 84 f6 48 8b 80 98 00 00 00 75 08 80 60 18 fe 31 c0 c3 f0 48 0f ba 68 18 00 0f 92 c0 0f b6 c0 c3 RSP: 0018:ffff8ec22fc03e00 EFLAGS: 00010046 RAX: 0000000000000000 RBX: ffff8eba1b072518 RCX: 0000000000000001 RDX: 0000000000000085 RSI: 0000000000000000 RDI: ffff8eba1b072518 RBP: 0000000000000dbd R08: 0000000000000000 R09: 0000000000029700 R10: ffff8ec22fc03f80 R11: 0000000000000000 R12: ffff8ebe2d3609e8 R13: ffff8ebe2a72b600 R14: ffff8eca472707e0 R15: 0000000000000020 FS: 0000000000000000(0000) GS:ffff8ec22fc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000018 CR3: 000000046e5f6000 CR4: 00000000003406e0 Call Trace: _scsih_io_done+0x4a/0x9f0 [mpt3sas] _base_interrupt+0x23f/0xe10 [mpt3sas] __handle_irq_event_percpu+0x40/0x190 handle_irq_event_percpu+0x30/0x70 handle_irq_event+0x36/0x60 handle_edge_irq+0x7e/0x190 handle_irq+0xa8/0x110 do_IRQ+0x49/0xe0 Fix it by move scmd->device->hostdata check before _scsih_set_satl_pending called. Other changes: - It looks clear to move get mpi_reply to near its check. Fixes: ffb584565894 ("scsi: mpt3sas: fix hang on ata passthrough commands") Cc: # v4.9+ Co-developed-by: Jackie Liu Signed-off-by: Jackie Liu Signed-off-by: huhai --- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index def37a7e5980..85f5749a0421 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -5704,27 +5704,26 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply) struct MPT3SAS_DEVICE *sas_device_priv_data; u32 response_code = 0; - mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); - scmd = mpt3sas_scsih_scsi_lookup_get(ioc, smid); if (scmd == NULL) return 1; + sas_device_priv_data = scmd->device->hostdata; + if (!sas_device_priv_data || !sas_device_priv_data->sas_target || + sas_device_priv_data->sas_target->deleted) { + scmd->result = DID_NO_CONNECT << 16; + goto out; + } _scsih_set_satl_pending(scmd, false); mpi_request = mpt3sas_base_get_msg_frame(ioc, smid); + mpi_reply = mpt3sas_base_get_reply_virt_addr(ioc, reply); if (mpi_reply == NULL) { scmd->result = DID_OK << 16; goto out; } - sas_device_priv_data = scmd->device->hostdata; - if (!sas_device_priv_data || !sas_device_priv_data->sas_target || - sas_device_priv_data->sas_target->deleted) { - scmd->result = DID_NO_CONNECT << 16; - goto out; - } ioc_status = le16_to_cpu(mpi_reply->IOCStatus); /* -- 2.27.0 No virus found Checked by Hillstone Network AntiVirus