Received: by 10.223.176.5 with SMTP id f5csp989352wra; Fri, 2 Feb 2018 09:19:18 -0800 (PST) X-Google-Smtp-Source: AH8x226WYakyi78qACVZDFNPVWCJViamI6z8UjB4QCjnj2TOdxg7KGCDriZEKuzqbaR1Dn9hPn6B X-Received: by 10.98.103.83 with SMTP id b80mr40484939pfc.223.1517591958109; Fri, 02 Feb 2018 09:19:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517591958; cv=none; d=google.com; s=arc-20160816; b=r70NoLlJG7/B/xjzcOKlTry075N1WsT3cUkPPzGL7AQPa59P/8en4j6YKFEwHlaHZv kZRw3LkHvJpRr7OFSk3VJ3gZQ4gf3v/DSVCDq0rbjtYv8MolMftkyFo4e47oyXwb7RxS TUgaCsK983BtebzpXT2y5rl/YMLFVDe/00YmKRHc5mcP06+HbNJOnalPo456RwyUE6cM GCYXLLh4a8ffBoBjjpuBN7/2frFb/JYTHLJvdviMfWt+reAWMx72qs/RW1oTWtahTvJ4 vph9V80mu6swHvlFZjHxNjk/vN9eKuLgusBPIiL+epRm7EMZVvl6iFYEui3pDnGdK5hK Xq1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=dQS7uZqbbMwupFoLN9fkGwUAlWXxdvVz4jWwxa1aN6c=; b=zuKhHbSqS52ecm0jhtB2eXuqvsKQqKcqugr+8jEEUR6yWX8pte5vArSqJFg7WAIA4m jUoJzsGjTTjMmwccMNr2IEcsriOGwgf96UQxCuyHddbgO1/dZGAQ6EjvcqmTS7JiYznx clg67unS8vRcZ/CMBLE0QgSZjsB28qouVEks798eoTu2sGQ3W4xzSkRaeJQrqCaOwKLZ cu7DS2W9f7Ys1IuTyXcUBFX6fWOZN7L7QIJCIRtUS+/KhF+6/Mioui1dwU09o9Ofzo0z zfS+8/M4m7ZLNKA/ye5CwCgKDs5oBtSIZU5NdOpzYx4p1IiCd2hDiTts+bqR3ZJTGL64 cyvA== 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 w2si1695775pgp.680.2018.02.02.09.19.03; Fri, 02 Feb 2018 09:19:18 -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; 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 S1752542AbeBBRSe (ORCPT + 99 others); Fri, 2 Feb 2018 12:18:34 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:38670 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753031AbeBBRLc (ORCPT ); Fri, 2 Feb 2018 12:11:32 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B878BF09; Fri, 2 Feb 2018 17:11:31 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Minwoo Im , Christoph Hellwig , Sasha Levin Subject: [PATCH 4.14 097/156] nvme-pci: fix NULL pointer dereference in nvme_free_host_mem() Date: Fri, 2 Feb 2018 17:57:58 +0100 Message-Id: <20180202140844.607338782@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140840.242829545@linuxfoundation.org> References: <20180202140840.242829545@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Minwoo Im [ Upstream commit 7e5dd57ef3081ff6c03908d786ed5087f6fbb7ae ] Following condition which will cause NULL pointer dereference will occur in nvme_free_host_mem() when it tries to remove pci device via nvme_remove() especially after a failure of host memory allocation for HMB. "(host_mem_descs == NULL) && (nr_host_mem_descs != 0)" It's because __nr_host_mem_descs__ is not cleared to 0 unlike __host_mem_descs__ is so. Signed-off-by: Minwoo Im Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/nvme/host/pci.c | 1 + 1 file changed, 1 insertion(+) --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -1617,6 +1617,7 @@ static void nvme_free_host_mem(struct nv dev->nr_host_mem_descs * sizeof(*dev->host_mem_descs), dev->host_mem_descs, dev->host_mem_descs_dma); dev->host_mem_descs = NULL; + dev->nr_host_mem_descs = 0; } static int __nvme_alloc_host_mem(struct nvme_dev *dev, u64 preferred,