Received: by 10.223.176.46 with SMTP id f43csp277127wra; Tue, 23 Jan 2018 20:53:18 -0800 (PST) X-Google-Smtp-Source: AH8x225IkZKNvX/LK/nDPMLQlqGf3fu0SKJSC7s8oh/pOVu4VyNUMqbJ6rUkVZDlqY8gOoA2wR++ X-Received: by 10.99.176.15 with SMTP id h15mr10140026pgf.374.1516769598721; Tue, 23 Jan 2018 20:53:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516769598; cv=none; d=google.com; s=arc-20160816; b=oOg5QKwDxrxg/k4Zb6uZW9NokiMTktKshE1KQk54zyVr6g+nOymNTx5Xy5goIXX1YX pfdK4Ac8tTmQY2cThTQK/zABnG4sR3TYBXGBqkFzksLCcBQk9hqyLvqyBP1QEoeC1YM+ 8Mxd+vEjxc1PJmxt2MVofVgfIz/cCWRkqpKY7lfzexiLX7nglyGLwM2VniCZ9WzEdDJo auWdYihdTv3CX7uAmfGt1mGxBIkukiL8AP8E2bFxiW0J1XSIyUDzyCm9BDWr5o0Oqx0L gWQZYJtAzSMczC//nX6UKHWdyhgx9IPIeM8u4Du6lJwcLUamX91As2HzzeW3aHqbc1+s jOmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=c5PXFHTIJVC31w0tXI4wg91d14lWW4xIeWsPmnTfKzM=; b=vai1u6+wifE+nEDtpnkeAQNcxbiWI8Aq4ouhmwCxUARQJXRYuYVy4PjI0kHPvhPQGJ NcF7ouo7HRoQED5Gqgk2X422Aj40Z7KnQiffZ1GBOZg5HV1WXIra6p22Yn/IoRopmqSS XnJxJPFvvJzj4vY8jM3HfeQqgAcFmO+gED/pF8ommsjdG94oXaAtHMi42w6ZLVWnngDq 7aT86ok8t3iM/F8cwiFj8ak9AGGxDOM91NSlLE6cQnrYx/By8qJvG83G9e7i9Fl3Jxaq qSNUHniGEcS+7EodsNgu8Zkqdcqgvz4qM92S2JZPrP6l8Mt79bhZppW1NmzGwMPzpoY1 lH3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=ZJrE4yjC; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 205si2267395pfw.227.2018.01.23.20.53.05; Tue, 23 Jan 2018 20:53: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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=ZJrE4yjC; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932711AbeAXEwh (ORCPT + 99 others); Tue, 23 Jan 2018 23:52:37 -0500 Received: from mail-by2nam03on0132.outbound.protection.outlook.com ([104.47.42.132]:45413 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932438AbeAXEQB (ORCPT ); Tue, 23 Jan 2018 23:16:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=c5PXFHTIJVC31w0tXI4wg91d14lWW4xIeWsPmnTfKzM=; b=ZJrE4yjCUkXkH/qfbJMl8SqYOeSByi6Y7YynXTCwNMMe/pML2kAVVcp1UlMaDeX/IXK8k/oSPHrW17gJieR6b1EUs0nN9je/9B/we6hD5lOV+TesCQS7tYvkiTPeF1tpRaIVf4UDhSJHN/pyr2ATKD4CJc0GDoPlzlz94X9gCVo= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1078.namprd21.prod.outlook.com (52.132.130.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.464.1; Wed, 24 Jan 2018 04:15:56 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7%2]) with mapi id 15.20.0464.000; Wed, 24 Jan 2018 04:15:56 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Minwoo Im , Christoph Hellwig , "Sasha Levin" Subject: [PATCH AUTOSEL for 4.14 070/100] nvme-pci: fix NULL pointer dereference in nvme_free_host_mem() Thread-Topic: [PATCH AUTOSEL for 4.14 070/100] nvme-pci: fix NULL pointer dereference in nvme_free_host_mem() Thread-Index: AQHTlMnmkfzuohULN0imAnuOqttBzQ== Date: Wed, 24 Jan 2018 04:15:00 +0000 Message-ID: <20180124041414.32065-70-alexander.levin@microsoft.com> References: <20180124041414.32065-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041414.32065-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1078;6:SrVYDFw3No1hhgcyOl/iMSTN2LG2OltupgMyDQM3gKXt9MNkMePZVSckYt5G/wiij4T4Dn+MfQfqMiJBhsdoybM5zA3TD8DMBE1NftQE8yvA36LWldjqyPWffV1sPQ00Jf0qakpjZue04kz1b7CLWKUfccjTYQmL8HOAbzB0QQt3QjdwyUhb3Au3YJUkyJ8HqRczTOrwjtasNAf30HjdI5v5pjEF87uoTLh2IFAK0dM+esB14Sta0Nbq0f5S7LceJeVgCs2TcydDj+y7FITGmir/UgBUCTC1nLH7cGiAr5NNjczt2vg7ivmrQ3TKf3Q79vjp1rFuQDyCwoa1e+9Yq09H+5GFzyD3rHPn+prgT+XDR38QZg9BtwD5qhtwjOix;5:DPilauHt5UkpwTt3n8ZFfc7DYIIzL6qWp8dBgyT37sVvZeVarvJ6gzWmxVfiKE+miNnLcOGhfqDgrAAh1hMxqiwt7qkByBLo81tP6ZtdUoyjDM3lhHJJvq5q90OMJaUO+fYQdJUmX0t/jBPSbmVlxaXBoweHvlmyVSTtpvaT9Pw=;24:aNAVZgvoyr8LtLZnk7jri+HjcBXHcJAQIyCzt/x+AehuGbj3zaHBnvO1Arwl8kAWfQ2z7aTtWGHdD9ryI/Sc+nAfnTX9jEttfJjzkdgE9LE=;7:RLUfpzwGOlRe/Cni3YR5tW3KcGe6Bc5IlPZWvpWf0SozIXj4CjnPw3F9j9RikgZKqKpI2Kp+UtDZZBV+b8BDAroyChhO18u9zrXFqtOQhJJUboE+uF2ppboAgM+UCB6etN9tGEVNskmKtYTgL/s7wM9txcQQPrwR9oWw2dplcNemMyVmU31CTuMZ8l3OtqD1wja6t1uszUuZH1HcyxmgXiKA1Fgklr7LlK1NW8DWe0Zo77lZJQFwRo7LJXX21Rjl x-ms-office365-filtering-correlation-id: 6736f817-a9ab-43e6-6f90-08d562e12ad8 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7193020);SRVR:DM5PR2101MB1078; x-ms-traffictypediagnostic: DM5PR2101MB1078: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(85827821059158); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(3231046)(2400081)(944501161)(6055026)(61426038)(61427038)(6041288)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1078;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1078; x-forefront-prvs: 056297E276 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(346002)(39860400002)(366004)(396003)(39380400002)(199004)(189003)(86612001)(22452003)(6436002)(106356001)(107886003)(102836004)(105586002)(305945005)(5250100002)(2501003)(14454004)(3280700002)(4326008)(7736002)(97736004)(59450400001)(6512007)(39060400002)(36756003)(8936002)(2950100002)(3846002)(6116002)(6506007)(86362001)(54906003)(76176011)(110136005)(2906002)(6666003)(53936002)(66066001)(72206003)(6346003)(5660300001)(8676002)(478600001)(10290500003)(68736007)(81156014)(10090500001)(1076002)(3660700001)(25786009)(316002)(2900100001)(99286004)(26005)(6486002)(81166006)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1078;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: R0wWet5CLeLfxjS8cHhdUjoRhmw1gmR+zdXSHMnEFRqo2o9UZ6f3jgdqExVPEeWuDLgp38NjXpr9kI4biGms1w== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6736f817-a9ab-43e6-6f90-08d562e12ad8 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2018 04:15:00.8546 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1078 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 =3D=3D NULL) && (nr_host_mem_descs !=3D 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 --- drivers/nvme/host/pci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 5dae650438c1..cdd2fd509ddc 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -1617,6 +1617,7 @@ static void nvme_free_host_mem(struct nvme_dev *dev) dev->nr_host_mem_descs * sizeof(*dev->host_mem_descs), dev->host_mem_descs, dev->host_mem_descs_dma); dev->host_mem_descs =3D NULL; + dev->nr_host_mem_descs =3D 0; } =20 static int __nvme_alloc_host_mem(struct nvme_dev *dev, u64 preferred, --=20 2.11.0