Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7ADCC4332F for ; Mon, 6 Dec 2021 15:05:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346558AbhLFPIq (ORCPT ); Mon, 6 Dec 2021 10:08:46 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:56258 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346498AbhLFPGf (ORCPT ); Mon, 6 Dec 2021 10:06:35 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9561C61309; Mon, 6 Dec 2021 15:03:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A4F7C341C1; Mon, 6 Dec 2021 15:03:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1638802986; bh=ndOXS9KXsxvEwuKPKH64yIMrAtFzTbeJd27fUhEFgO0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SbqZMuukuO74R47ZKQcl8rFxOUGNn2eZyCcSbB8PyffqNUyIPW0kQe7tyh1JMtYSl 6CLFwyfZ4QQsPnqPtQP8V04XbIPvJsf7m7noapGB7oO9Bsw8IGvkav4QCGaXAeJQy3 LJo5Hy2vjUXqZBZSTyhH9VoQjqGoqOcRGkDBVSUY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sreekanth Reddy , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.9 18/62] scsi: mpt3sas: Fix kernel panic during drive powercycle test Date: Mon, 6 Dec 2021 15:56:01 +0100 Message-Id: <20211206145549.802086417@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20211206145549.155163074@linuxfoundation.org> References: <20211206145549.155163074@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sreekanth Reddy [ Upstream commit 0ee4ba13e09c9d9c1cb6abb59da8295d9952328b ] While looping over shost's sdev list it is possible that one of the drives is getting removed and its sas_target object is freed but its sdev object remains intact. Consequently, a kernel panic can occur while the driver is trying to access the sas_address field of sas_target object without also checking the sas_target object for NULL. Link: https://lore.kernel.org/r/20211117104909.2069-1-sreekanth.reddy@broadcom.com Fixes: f92363d12359 ("[SCSI] mpt3sas: add new driver supporting 12GB SAS") Signed-off-by: Sreekanth Reddy Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c index 58876b8a2e9f8..8063b97bf2e9b 100644 --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c @@ -2927,7 +2927,7 @@ _scsih_ublock_io_device(struct MPT3SAS_ADAPTER *ioc, u64 sas_address) shost_for_each_device(sdev, ioc->shost) { sas_device_priv_data = sdev->hostdata; - if (!sas_device_priv_data) + if (!sas_device_priv_data || !sas_device_priv_data->sas_target) continue; if (sas_device_priv_data->sas_target->sas_address != sas_address) -- 2.33.0