Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp774932ybc; Sat, 16 Nov 2019 08:28:03 -0800 (PST) X-Google-Smtp-Source: APXvYqy5p2co4qdAsiMDEl6WI9xm3njhJVIsuiWsxwjACUsFsdJdKaW0aOiHnFL5bVlGxzOphugz X-Received: by 2002:a17:906:d210:: with SMTP id w16mr11068127ejz.86.1573921683655; Sat, 16 Nov 2019 08:28:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573921683; cv=none; d=google.com; s=arc-20160816; b=ZaIDjiSgEuPG6iirC6vJjisRa+bkxF2vduPr1fl2GoUiWA4n8dV/JnEV2bgE4tAHuf awOQ4E5KrvELOaPSaCwFljsorYdeaKzzeqhCrzDA3MxjbmJyQfPP/caDUvS7rNBgBd7R ht6QsG98oKhuXr2U0mYUfO/qwLowvFxOnc/OhYkiQrRY8pTvnJO4qF7TE7KxuyqM8V7U yD7ByZ4UnGYMi2yFAzUtJTaUCeXFFuYkDYplHYWYa7BBCU79V7ZurkhJ+3GDqY6zRb4q lXvJcfSkkpA54c0rHXSfPfjkDod6cb+AVhrobnuy519IqnWbPYsr8BJQioQ86LbRJOYA lRcw== 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=FN01Mg9fDjjjfiEQTC9znI92n5PGCvZ4Mq/Odtt66Sw=; b=p5DtlSExDzYQLu8eG7/aMyv6mNko9KGnsrPml8HHXk9SNTJRZuNY9+Ie4MEeUCZh6T SXjQ25AEJQ7SV066h4t+w4gx/vszayOUbD6oTFr8t7hbJCMbYaYYYd4xe82yFp1XjtMf vmj6Lp/QGt83Aa9uA9MH+ovfnvVNsUBbGMEPtcjsshN04LcdAA8+cjj7dPZtO6/vo6gE LnbUVKt9X203s0/dVkENeUM+UtqeXTPjRZsccqhcSFn77efEJvP9u8jSN1UCdx/oQnQU JDAt8AfihQJF5yMlZwoNgXkYbKPn5CFjsDxCgcbLUE5wcT190Y4CbvjIx4L7pIDr5Yl7 F2sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="RHe3//EQ"; 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 p16si7949925ejb.191.2019.11.16.08.27.38; Sat, 16 Nov 2019 08:28:03 -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="RHe3//EQ"; 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 S1729429AbfKPQZP (ORCPT + 99 others); Sat, 16 Nov 2019 11:25:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:45664 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728194AbfKPPmK (ORCPT ); Sat, 16 Nov 2019 10:42:10 -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 29F89207FA; Sat, 16 Nov 2019 15:42:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573918929; bh=bPTlPH2rYRCi56/K0e6IaVB93IuksRjPjxYZGiewy/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RHe3//EQ/1SNGxor22kzmam5vcOebnSrY53VSA3jDRG98+BywzvSxuexnX2ehur45 2FGbvA493+wfDfcxBmP8jbjqWPrxN8n4EKZa1M8iSGbjtbLl4/qptficvKyzAkdL5P nz+z0hJtmJBogyWb1sVtBG+kkILnkkotpOS/0BFY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Bart Van Assche , Chaitanya Kulkarni , Christoph Hellwig , Sasha Levin , linux-nvme@lists.infradead.org Subject: [PATCH AUTOSEL 4.19 056/237] nvmet: avoid integer overflow in the discard code Date: Sat, 16 Nov 2019 10:38:11 -0500 Message-Id: <20191116154113.7417-56-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: Bart Van Assche [ Upstream commit 8eacd1bd21d6913ec27e6120e9a8733352e191d3 ] Although I'm not sure whether it is a good idea to support large discard commands, I think integer overflow for discard ranges larger than 4 GB should be avoided. This patch avoids that smatch reports the following: drivers/nvme/target/io-cmd-file.c:249:1 nvmet_file_execute_discard() warn: should '((range.nlb)) << req->ns->blksize_shift' be a 64 bit type? Fixes: d5eff33ee6f8 ("nvmet: add simple file backed ns support") Signed-off-by: Bart Van Assche Reviewed-by: Chaitanya Kulkarni Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- drivers/nvme/target/io-cmd-file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c index 81a9dc5290a87..39d972e2595f0 100644 --- a/drivers/nvme/target/io-cmd-file.c +++ b/drivers/nvme/target/io-cmd-file.c @@ -246,7 +246,8 @@ static void nvmet_file_execute_discard(struct nvmet_req *req) break; offset = le64_to_cpu(range.slba) << req->ns->blksize_shift; - len = le32_to_cpu(range.nlb) << req->ns->blksize_shift; + len = le32_to_cpu(range.nlb); + len <<= req->ns->blksize_shift; if (offset + len > req->ns->size) { ret = NVME_SC_LBA_RANGE | NVME_SC_DNR; break; -- 2.20.1