From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D73EC432C0 for ; Wed, 27 Nov 2019 20:59:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 65D882158C for ; Wed, 27 Nov 2019 20:59:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888373; bh=F9nfwylI2cbFlI3Gy+RWwoya7DKdqH9GaXiRvmRpGlo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=h1DVjoXpjh193picfW5aYPSWGdB5d/lVdNwgMx0MbfpIGhho81jMlyUOtIB8q0nNZ aI8ajktp4Jrvsz9rfN66oN7jCyDkib7kMNmyGL6U36RR0vHF7o3kDwEcYj9Gy3zg5C tAiTtOYqM/GavYdaLc35QvL8nGVLIHwDda5+pMx8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731419AbfK0U7c (ORCPT ); Wed, 27 Nov 2019 15:59:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:51080 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731430AbfK0U7b (ORCPT ); Wed, 27 Nov 2019 15:59:31 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4D68821556; Wed, 27 Nov 2019 20:59:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888370; bh=F9nfwylI2cbFlI3Gy+RWwoya7DKdqH9GaXiRvmRpGlo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PkhyTMIclWHUE5J72uEdp1OGnAXxUvL5jvGH9hRKKAGXMfgPzmY7MqT03Js5Bvq6D JoS/Gz3iHjIYinNg5fTNCTkb+HiWGI1e6iq2zCpnHrtzaCmCk0oW0J7TOL8x0CXaoS Ifejq6spqS+IROqrdBI4BMiRPM4n6tNO8KmuoNAU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Gustavo A. R. Silva" , Xiang Chen , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.19 109/306] scsi: hisi_sas: Fix NULL pointer dereference Date: Wed, 27 Nov 2019 21:29:19 +0100 Message-Id: <20191127203123.221883725@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Gustavo A. R. Silva [ Upstream commit f4445bb93d82a984657b469e63118c2794a4c3d3 ] There is a NULL pointer dereference in case *slot* happens to be NULL at lines 1053 and 1878: struct hisi_sas_cq *cq = &hisi_hba->cq[slot->dlvry_queue]; Notice that *slot* is being NULL checked at lines 1057 and 1881: if (slot), which implies it may be NULL. Fix this by placing the declaration and definition of variable cq, which contains the pointer dereference slot->dlvry_queue, after slot has been properly NULL checked. Addresses-Coverity-ID: 1474515 ("Dereference before null check") Addresses-Coverity-ID: 1474520 ("Dereference before null check") Fixes: 584f53fe5f52 ("scsi: hisi_sas: Fix the race between IO completion and timeout for SMP/internal IO") Signed-off-by: Gustavo A. R. Silva Reviewed-by: Xiang Chen Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/hisi_sas/hisi_sas_main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c index d4a2625a44232..f478d1f50dfc0 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -1025,11 +1025,11 @@ static int hisi_sas_exec_internal_tmf_task(struct domain_device *device, if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) { if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) { struct hisi_sas_slot *slot = task->lldd_task; - struct hisi_sas_cq *cq = - &hisi_hba->cq[slot->dlvry_queue]; dev_err(dev, "abort tmf: TMF task timeout and not done\n"); if (slot) { + struct hisi_sas_cq *cq = + &hisi_hba->cq[slot->dlvry_queue]; /* * flush tasklet to avoid free'ing task * before using task in IO completion @@ -1856,10 +1856,10 @@ hisi_sas_internal_task_abort(struct hisi_hba *hisi_hba, if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) { if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) { struct hisi_sas_slot *slot = task->lldd_task; - struct hisi_sas_cq *cq = - &hisi_hba->cq[slot->dlvry_queue]; if (slot) { + struct hisi_sas_cq *cq = + &hisi_hba->cq[slot->dlvry_queue]; /* * flush tasklet to avoid free'ing task * before using task in IO completion -- 2.20.1