Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp945007imm; Wed, 11 Jul 2018 14:00:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfCScelaOayXwQkzeoHpQ6doLQimdW1SzeThF/b+pnSlKNeKK0Qp1uZdBz76i2nZHCnc5UZ X-Received: by 2002:a62:4585:: with SMTP id n5-v6mr234586pfi.32.1531342819495; Wed, 11 Jul 2018 14:00:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531342819; cv=none; d=google.com; s=arc-20160816; b=VA2QHiI+PYE3f6ooco9IH4kik4FAdObvC0mT/g+p0AcRm+6bAJY7d3nQONsxvoiX+F IdKn3ytcaLAd3F9sCrA3cAFsqJJxWLqps7pAjDo5ixXA1Dot/22IzKElq43bT3ykf26J gWGxcPqUVFtwoZYjr5lCIH4p4YTA3t0Pq0GoN3mkT6JmVpaPNpFTrOGC7qC2XeYsoeKn EKpZ2u+9wbybi70+9ChiXWbxQ0MrNy42AkxP7ZC1ZI2vUl1LiCplRA3t9jUW3ASkcCwW 9KmPlEWQS7iegVYwxWo6JsYKSRaAxFsw5wGHtZWan4ZDRd5kbNnE4uXOnJD5p/fYl0eY MXxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=5Z6L8HAFq6FB5PckUfWdadEv/Oi2X2KHYKoMb8jRB74=; b=lbRwPJ+iAslL9Shh/sDd2X414fWVP4vs7OTZq544JgSnAL28OaHzV9lzzvW4yVIzlk uQCgsUJ1V+o6ulV2nzbdelB7dBW5chKq2ePppWv+ipfdnvc/etYTAL2y5dNX26fG8Cfe bJQVgS8+/1IEx7pJg3+3r2AlsxjSt/G/R+ydn5Ak6j01XhXTlq6RlFHhFAAsgiEzgl6I tDwR/QokMZL3es7sZMVUeyXfiSZp4IrmZFxHIliNqCtTAYx01cAVXar5va0cmgeQhk15 vCmR0Hlvr1MRJNHFnA6JaZBlCpYRWk16WwJ18OI0Plks/Uh8K8CCEBlgk3/i8adkzbMk rCCA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w5-v6si19137352plz.438.2018.07.11.14.00.04; Wed, 11 Jul 2018 14:00:19 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733067AbeGKOzK (ORCPT + 99 others); Wed, 11 Jul 2018 10:55:10 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41030 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732321AbeGKOzK (ORCPT ); Wed, 11 Jul 2018 10:55:10 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 00DE08182D28; Wed, 11 Jul 2018 14:50:27 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FED216876; Wed, 11 Jul 2018 14:50:25 +0000 (UTC) Subject: Re: [PATCH][scsi-next] scsi: lpfc: fix null pointer dereference on nvmebuf To: Colin King , James Smart , Dick Kennedy , "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org References: <20180711134436.21963-1-colin.king@canonical.com> From: Tomas Henzl Message-ID: <8d54503c-93c4-4e1c-f6dc-6c41e6a3a80a@redhat.com> Date: Wed, 11 Jul 2018 16:50:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180711134436.21963-1-colin.king@canonical.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-MW X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 11 Jul 2018 14:50:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 11 Jul 2018 14:50:27 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thenzl@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/11/2018 03:44 PM, Colin King wrote: > From: Colin Ian King > > The check of nvmebuf suggests that it can be null, however a recent > change dereferences it to determine oxid before it is null checked, > hence there is a potential null deference on the pointer. Fix this > by performing the null check first. Also remove the oxid from the > debug log message as this is no longer valid. I considered an early > fetch of oxid if nvmebuf was valid, however, what oxid should be set > to if nvembuf is null could lead to an ambiguous logging of an invalid > oxid, so I thought just removing it from the logging was the least > confusion solution. I think that the 'if (!nvmebuf)' test is not needed and it would be better to remove the tests (it is tested for the second time later in the function). Tomas > > Detected by CoverityScan, CID#1471753 ("Dereference before null check") > > Fixes: 68c9b55deea5 ("scsi: lpfc: Fix abort error path for NVMET") > Signed-off-by: Colin Ian King > --- > drivers/scsi/lpfc/lpfc_nvmet.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/scsi/lpfc/lpfc_nvmet.c b/drivers/scsi/lpfc/lpfc_nvmet.c > index 22f8a204b69f..01652d9ac619 100644 > --- a/drivers/scsi/lpfc/lpfc_nvmet.c > +++ b/drivers/scsi/lpfc/lpfc_nvmet.c > @@ -1742,12 +1742,9 @@ lpfc_nvmet_unsol_ls_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, > uint32_t *payload; > uint32_t size, oxid, sid, rc; > > - fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt); > - oxid = be16_to_cpu(fc_hdr->fh_ox_id); > - > if (!nvmebuf || !phba->targetport) { > lpfc_printf_log(phba, KERN_ERR, LOG_NVME_IOERR, > - "6154 LS Drop IO x%x\n", oxid); > + "6154 LS Drop IO\n"); > oxid = 0; > size = 0; > sid = 0; > @@ -1755,6 +1752,9 @@ lpfc_nvmet_unsol_ls_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, > goto dropit; > } > > + fc_hdr = (struct fc_frame_header *)(nvmebuf->hbuf.virt); > + oxid = be16_to_cpu(fc_hdr->fh_ox_id); > + > tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; > payload = (uint32_t *)(nvmebuf->dbuf.virt); > size = bf_get(lpfc_rcqe_length, &nvmebuf->cq_event.cqe.rcqe_cmpl);