Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2217957imm; Thu, 18 Oct 2018 10:52:06 -0700 (PDT) X-Google-Smtp-Source: ACcGV62VnnqBqZVYNJrmckqoOKUMSkFPRzg9ZOmQSKcqw/xFzy6OUNM/qr6QT1quXLCloUr1T7L/ X-Received: by 2002:a17:902:5a0c:: with SMTP id q12-v6mr15898270pli.253.1539885126174; Thu, 18 Oct 2018 10:52:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539885126; cv=none; d=google.com; s=arc-20160816; b=hngS64nKZIL/Qt+jG6OVzNBKBOS8fnZoDgOdlhJe6Zs5/7EZZKHQ1vr06n2j/7tuG/ EqKb4otJ6sSt++fUAJLJZF8e65Jd30GKez98OU2bckVRwqtxnlQb6sDUwqz2cvvd4Fkp H2pLwGh6vb5Uuen+hGvpqVCeGyA4xUm762qAWnH8OAjmYGPqzTJM40akoccfc+pVAVrO HwWMbLWKUO1tKVPAlGBMJcK+8bLhpKvcRvVxCPhd7nerv8ycmTbXzvi9E0ZXCqF+P7LM XsOUSD6GsAag84eBXpQpuRvEKl2VjIav0vaOBa9YpFhR5Ds5ssveL2jY31+DNPS/tBrf Gfhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date; bh=VIGVBjtPYCzg6H9glVwK9XOqn5VjC05VbtxhHu/uM1s=; b=POAboozWSElNRp/t6G96mmTamCpsPN6oyhwPJe7+mDFVJoyw6OUTvpNKngM78waN/t lpNd4W0PB3LolBe3grGFwYfCq7DtyHtwNL8rFljEs/mtCfG/LbzSniKRu24eEnYrezrR wovESHwOljcbE5S6MYMFn2QTIQawgVvEFiB+njdkOacDHJUc3S0akYZlvVqbwd77ob81 1mnToVhNXdDgQe3lPq0YimlQtSHe7WoaLdfSYMtcHqlyE+ee8bt+GtIP4sBmspVtzDLj cgnqSruDFOZbdUYUDOjfNzklukxmkdN+cCVAhDpAeLBaK1Y512ZXkZ/i6RxjZ1IQ7sDq EQ6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c12-v6si21596320pgj.70.2018.10.18.10.51.50; Thu, 18 Oct 2018 10:52:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727615AbeJSBwD (ORCPT + 99 others); Thu, 18 Oct 2018 21:52:03 -0400 Received: from gateway36.websitewelcome.com ([192.185.185.36]:29758 "EHLO gateway36.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726608AbeJSBwD (ORCPT ); Thu, 18 Oct 2018 21:52:03 -0400 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 36E1740131D52 for ; Thu, 18 Oct 2018 11:07:15 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id DBeCgE7Cetz4jDBeQgLQj5; Thu, 18 Oct 2018 12:00:07 -0500 X-Authority-Reason: nr=8 Received: from lfbn-1-466-13.w86-245.abo.wanadoo.fr ([86.245.173.13]:58840 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1gDBeB-000s3J-IE; Thu, 18 Oct 2018 11:59:44 -0500 Date: Thu, 18 Oct 2018 18:59:39 +0200 From: "Gustavo A. R. Silva" To: John Garry , "James E.J. Bottomley" , "Martin K. Petersen" , Xiang Chen Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH v2] scsi: hisi_sas: Fix NULL pointer dereference Message-ID: <20181018165939.GA26491@embeddedor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 86.245.173.13 X-Source-L: No X-Exim-ID: 1gDBeB-000s3J-IE X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: lfbn-1-466-13.w86-245.abo.wanadoo.fr (embeddedor) [86.245.173.13]:58840 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 18 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Changes in v2: - Fix another instance of the same issue at line 1053. - Update commit log. 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 2e5eaf1..b3f01d5 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_main.c +++ b/drivers/scsi/hisi_sas/hisi_sas_main.c @@ -1050,11 +1050,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 @@ -1875,10 +1875,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.7.4