From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C40E8C432C3 for ; Sat, 16 Nov 2019 15:44:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 86B0620733 for ; Sat, 16 Nov 2019 15:44:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ue3wTW4b" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 86B0620733 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 292E86B0010; Sat, 16 Nov 2019 10:44:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 26A896B0266; Sat, 16 Nov 2019 10:44:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 180806B0269; Sat, 16 Nov 2019 10:44:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0035.hostedemail.com [216.40.44.35]) by kanga.kvack.org (Postfix) with ESMTP id 01D286B0010 for ; Sat, 16 Nov 2019 10:44:48 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id A730C8249980 for ; Sat, 16 Nov 2019 15:44:48 +0000 (UTC) X-FDA: 76162563456.21.wind13_cdc07af39b18 X-HE-Tag: wind13_cdc07af39b18 X-Filterd-Recvd-Size: 3333 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Sat, 16 Nov 2019 15:44:48 +0000 (UTC) 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 BB405207FA; Sat, 16 Nov 2019 15:44:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573919087; bh=/X42qqck8nkLc0mAmS/qSEjM3OBOAqD15gc7gZhyWjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ue3wTW4bGDhHFAl9i7h2KsOf0DL2XOD9FxydrFnJyTLMWSbbnzwemvB4ZpL8cbVIT KhR4xBB2tLr1URar4G4MAkU5bAoT7tAaeuWpWCzen7NzDu89gPpQUXV2fMWClYpKA5 +4aUMv0IlQTg70zxLxKNSE+K5RAdMa2Zns8D1Y+Q= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dan Carpenter , "Kirill A . Shutemov" , Andrew Morton , Stephen Rothwell , Keith Busch , "Michael S. Tsirkin" , Kees Cook , YueHaibing , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.19 149/237] mm/gup_benchmark.c: prevent integer overflow in ioctl Date: Sat, 16 Nov 2019 10:39:44 -0500 Message-Id: <20191116154113.7417-149-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: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Dan Carpenter [ Upstream commit 4b408c74ee5a0b74fc9265c2fe39b0e7dec7c056 ] The concern here is that "gup->size" is a u64 and "nr_pages" is unsigned long. On 32 bit systems we could trick the kernel into allocating fewer pages than expected. Link: http://lkml.kernel.org/r/20181025061546.hnhkv33diogf2uis@kili.mount= ain Fixes: 64c349f4ae78 ("mm: add infrastructure for get_user_pages_fast() be= nchmarking") Signed-off-by: Dan Carpenter Acked-by: Kirill A. Shutemov Reviewed-by: Andrew Morton Cc: Stephen Rothwell Cc: Keith Busch Cc: "Michael S. Tsirkin" Cc: Kees Cook Cc: YueHaibing Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/gup_benchmark.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c index 7405c9d89d651..7e6f2d2dafb55 100644 --- a/mm/gup_benchmark.c +++ b/mm/gup_benchmark.c @@ -23,6 +23,9 @@ static int __gup_benchmark_ioctl(unsigned int cmd, int nr; struct page **pages; =20 + if (gup->size > ULONG_MAX) + return -EINVAL; + nr_pages =3D gup->size / PAGE_SIZE; pages =3D kvcalloc(nr_pages, sizeof(void *), GFP_KERNEL); if (!pages) --=20 2.20.1