Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp732849ybc; Sat, 16 Nov 2019 07:45:13 -0800 (PST) X-Google-Smtp-Source: APXvYqwA+dCFcVZpgafmKRMHUNevCtWowVZDDW6ovA6DxoA9MP+0SurERCAuBKLkq3cWnig8DfKq X-Received: by 2002:a17:906:af5a:: with SMTP id ly26mr10923232ejb.252.1573919113152; Sat, 16 Nov 2019 07:45:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573919113; cv=none; d=google.com; s=arc-20160816; b=HiIt1aOcs80a6DMlPGh3rD7AsfODTcshKUTIx2tc2M73tJg92/BDqvwNJDX6iFX1zB jnEapwJtSz6B9wq2uKMOrhFL6AROYjbeKXdI2ypk5hvJvIuO0ERnHCSZSkiRbsajRwKa uNKOYWY2+tCmkkAo7CpwjfgFOMsuGVrUFRXASDfninJv2oT5zUD2ea0ix5JTETj03Auk 9AV363QN5Cqyh46e1CbWN3ea9/9IF9y5O2l3xeV3Iz4BZZkT0+FrkUJBtcpPImKI3ZSO o3JOjzFwG7127GkFWllmhW7FcLZeuD/sLQCr28UB2QM/SsewVjT9gTLKVmByZ3u0dtIh AdBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LuXjZayIrFrZX9nNLLGrpWOwnxqms9rKdworOI82/DI=; b=T2GZsF6AMz+UtbkLhsjhkzz0k03u0nFJB7tPyy458I/JBcU3aT0CUFS5xQINBUDGXj 9x7R56kUSTl8P3YhQUf9y9F8B90mrT42OLhpAweZpUMP9l030KcaOdgYxmGDZOzpqS2z 0Q7WCD4ZLwZWKhDnubUIclQTObcMT6ob077/CkLHEfYEcPeAWXF9zUPHk5jnG+EhILPC b3OX1vpWN5Wkx9z125L2SrZXt3yN7pjb8zaAdOfYMTEQ30a07xk08ckfPpcni4aiQiNg MXnjtoAnemu/Boi1okTHtR6VKbTTnyHbg9JyaN+vrGyC0PLD/5pjYvt8nwxdFSUHby78 cVlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=M0maQnGZ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y4si8443251edp.177.2019.11.16.07.44.48; Sat, 16 Nov 2019 07:45:13 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=M0maQnGZ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728566AbfKPPnD (ORCPT + 99 others); Sat, 16 Nov 2019 10:43:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:46892 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728547AbfKPPnB (ORCPT ); Sat, 16 Nov 2019 10:43:01 -0500 Received: from sasha-vm.mshome.net (unknown [50.234.116.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BC3C92075B; Sat, 16 Nov 2019 15:43:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573918981; bh=RhEQdIRWLTuBSUEAgYQ268wy45fY4RTZSKHNk1bT7B8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M0maQnGZUFuKgwgs3Tqt0qV1c8IPS6o9JPidNCtd1m5OZNhNnmPnou/2dWTjNFECh C4fhnkJsI9nXTQUNobuXf2UbB2nbuPLxJh1v7DGs9LslqY6GixitVP+ohhrrLvdgy6 QaogoqDc5KvQUbqPb9PJy/H3gZrCf6duEITBEtP8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Gustavo A. R. Silva" , Xiang Chen , "Martin K . Petersen" , Sasha Levin , linux-scsi@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 090/237] scsi: hisi_sas: Fix NULL pointer dereference Date: Sat, 16 Nov 2019 10:38:45 -0500 Message-Id: <20191116154113.7417-90-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191116154113.7417-1-sashal@kernel.org> References: <20191116154113.7417-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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