Received: by 10.223.176.46 with SMTP id f43csp283576wra; Tue, 23 Jan 2018 21:02:07 -0800 (PST) X-Google-Smtp-Source: AH8x225KPWKtIy/QWycqe5TTDuHWgqRT8ZrWU5XlF9UFTKVknporYgoOMffx+5rdhdG/5jlA7vaH X-Received: by 10.101.88.7 with SMTP id g7mr10036490pgr.249.1516770127467; Tue, 23 Jan 2018 21:02:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516770127; cv=none; d=google.com; s=arc-20160816; b=RUoAHnBdR02+Yx7kbNxOarekT9FvV/nYATySFPdKnFs+39oN1CPYirOqDu8twU7hjB SNzd3p6S9yGUtzGYEuYuegFKwCED4LfR91wOkbQ/u5MjwjYpOMZOM7bfRX6JtzWyhGNt DGYo8iUapTyxRa6aTmLZpsA8kdiXgy0yNGZ+7i7wBA50fC4eT5OjU9N4Y6GrGc5HuGRA XVvmeeDJEb/Uc6Kfkv1jKLoEoQ5khVh1fyXZ1E1S/Ov9MNFqDOAnrKeHW4DOTQWg6lzG c6xT7pO7n8tB/NirQykhfBPdjneWfMUAIXiiCxKgLD9iOXRwOB2bWhJoBqx8VUAhzcbv iqtw== 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=UrXiGFVu3sblzYcHC2OMHOye2HmbEmKZYukBDlAsPIU=; b=VZRQ4Xq+o1cDBkmxpvuZKlpOFze3SBWWppzDrgnqKOVNi8f/zluydugr9s8if4O8Ha e1MloAaX1PebtPE5kI59graPzcmw6qXH0J5tV09A+s7YWxcuY0/bpbnBxm6lm24q2aEV 7GxywSy/MfSd2ZMBzkN8tPSMpD0LyAweMOd4CYpPBVIbaIxLCuADVYWYltkVhtY+SCPZ dEaM1m2pPw5yGOXK+pCeF+VdonlIw7L6X+WwykULZqEAf4OaJ1w3XNCAh1N/pq2tt95Q JosPAz3ZKNdwX3ONQUojVlP+lrHWQcTEv10iJHdf4F98w3NPXka6dqTY6HZrv7P0GiNN 630A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Cnducmd+; 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 61-v6si5460321plb.203.2018.01.23.21.01.53; Tue, 23 Jan 2018 21:02:07 -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=Cnducmd+; 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 S1752742AbeAXEOj (ORCPT + 99 others); Tue, 23 Jan 2018 23:14:39 -0500 Received: from mail-cys01nam02on0138.outbound.protection.outlook.com ([104.47.37.138]:25312 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752671AbeAXEOf (ORCPT ); Tue, 23 Jan 2018 23:14:35 -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=UrXiGFVu3sblzYcHC2OMHOye2HmbEmKZYukBDlAsPIU=; b=Cnducmd+rMa3h87sadqTGNr9uhzoYeNRAoDmztf0fQP70c35KIxtk565R+I1thYMfxB5SDRkSIct7/HuM1uLp+4YRESpZLQdb0ttXIEGLIWhlaSWhaNA8EaUkU0yFZYpARIw/NOirOs8+QZbsHcHKhiHyvSm5pGrvpThkiN/zCg= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1080.namprd21.prod.outlook.com (52.132.130.14) 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:14:33 +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:14:33 +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 021/100] nvme-pci: avoid hmb desc array idx out-of-bound when hmmaxd set. Thread-Topic: [PATCH AUTOSEL for 4.14 021/100] nvme-pci: avoid hmb desc array idx out-of-bound when hmmaxd set. Thread-Index: AQHTlMnWRrz/Ob90zEOQVx3ogRSQMQ== Date: Wed, 24 Jan 2018 04:14:33 +0000 Message-ID: <20180124041414.32065-21-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;DM5PR2101MB1080;6:zgdySTdbtmv1oIJHTO61l0uT7OJLJ3jhGGVxi78VaLf8e6L/rOuCKR3UFvCOz5PuoOnvyTyGK3VqSjSnxhgP1GZQNrzVm5A4odlGpwk6kaIm6dRphS3iwE6PgePXXPqKyC8m5SUlSxOZHSkiM7NKLJRooF2LsoVW86XgxmAIUSg38O105ux9YMKKIHDEkOe5hhM3/xZLQUN82iCzx4/E3YTlB/eHg4UmYJLJ4nTslvERErjhT9w0z+qdlzOdc2IT3OXfCbCf4Iw+mgcxH5yQdEU3uoW+MuApA7JI/EupAXQisrgqlwaDU6JLnWML2voT4ay/G0DPKkktG1mE06CdGQ16oIz2WkOjMng9KmrEj9HO0wcoMEIQ3M1HSRbsGq+3;5:r3HRQ018IB2OJ1Urd5vmuh48Bp35py537g3PLhN7EJ7NdiMb1o6v1D++n1ZRNNjyGeW8QHxyvGuUfZUTSuF8PmUEiZIZB43CAu4cpdgjhCCjBZM2+CnfB7Vu6LpUKKaINInHHT/JF9Zgm4zdMxHhe9l90GeF4xKuau8KUKG+wH0=;24:kI0jH/750Dw0ARyalr6H5qfeGMd0rr8rZUyAaudIturXNyGdygx17hnnNKcJXhjgqJvK7SREMuwF0YdooP9W/TFnZ3xsYy4ynTviDGAhBFc=;7:kpvmGTKxxzmy2QUJTPWUMmn2uxs9UkwqdFe/+WKMVUQ0dHMkRrMqrz24vTwxhDyAEp9VrT28fQPZOsNSaA1MDCqTilh9vM08J4Ps9rRYZjXlz1Vntrk/fU5no8hQEPxeXoy0S0RLJZaSSXzCrr3H3CQZ68Lxon0YvRhjbY1m0+1l+qJQciJ3pqb9Ix2slBIyCmv4yMM5W9du4kta+zS7bp3P4n/JqAXNDL681XlHfjPEYS6GCgeB0l9x3MTwAN32 x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-ms-office365-filtering-correlation-id: de04002f-97c0-4aab-6a35-08d562e0f905 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:DM5PR2101MB1080; x-ms-traffictypediagnostic: DM5PR2101MB1080: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(85827821059158)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(8121501046)(5005006)(3002001)(10201501046)(3231046)(2400081)(944501161)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1080;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1080; x-forefront-prvs: 056297E276 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(396003)(346002)(39860400002)(39380400002)(366004)(189003)(199004)(72206003)(110136005)(316002)(5250100002)(6346003)(2900100001)(54906003)(1076002)(6116002)(3846002)(22452003)(36756003)(53936002)(99286004)(6512007)(68736007)(2501003)(3660700001)(14454004)(3280700002)(86362001)(102836004)(7736002)(5660300001)(305945005)(575784001)(107886003)(6486002)(6506007)(2906002)(81156014)(26005)(25786009)(4326008)(81166006)(39060400002)(105586002)(8936002)(59450400001)(106356001)(230783001)(478600001)(10290500003)(6436002)(8676002)(2950100002)(86612001)(97736004)(76176011)(10090500001)(66066001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1080;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A: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: DQ0zL5vPwQQvkApKLtrF/3zO8OIHNdlCMgUsNUqq+yh9YZ29r4x1INmj9UI7phClSX+VrWduNLjgwuXoiAEPew== 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: de04002f-97c0-4aab-6a35-08d562e0f905 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2018 04:14:33.1580 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1080 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Minwoo Im [ Upstream commit 244a8fe40a09c218622eb9927b9090b0a9b73a1a ] hmb descriptor idx out-of-bound occurs in case of below conditions. preferred =3D 128MiB chunk_size =3D 4MiB hmmaxd =3D 1 Current code will not allow rmmod which will free hmb descriptors to be done successfully in above case. "descs[i]" will be set in for-loop without seeing any conditions related to "max_entries" after a single "descs" was allocated by (max_entries =3D 1) in this case. Added a condition into for-loop to check index of descriptors. Fixes: 044a9df1("nvme-pci: implement the HMB entry number and size limitati= ons") Signed-off-by: Minwoo Im Reviewed-by: Keith Busch Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/host/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 66d872b05024..5dae650438c1 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -1645,7 +1645,7 @@ static int __nvme_alloc_host_mem(struct nvme_dev *dev= , u64 preferred, if (!bufs) goto out_free_descs; =20 - for (size =3D 0; size < preferred; size +=3D len) { + for (size =3D 0; size < preferred && i < max_entries; size +=3D len) { dma_addr_t dma_addr; =20 len =3D min_t(u64, chunk_size, preferred - size); --=20 2.11.0