Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6016960ybc; Wed, 27 Nov 2019 13:28:20 -0800 (PST) X-Google-Smtp-Source: APXvYqx1nocGjcvVsytG0sWIsccABwEqlF+EW/G4o9uYqnoBW/VMizbOPAa3O3ol6mp1NxVZVmNm X-Received: by 2002:a17:906:4d89:: with SMTP id s9mr11064307eju.268.1574890100120; Wed, 27 Nov 2019 13:28:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574890100; cv=none; d=google.com; s=arc-20160816; b=Y6P8NgbeKpKunUHHVmTHxPPkPYsUs7+on8ZiFav/oibc49GioizI3HMvZqzeLkIBVs +h2LaoQ58FymOsTk9DX53aoHs0XnIJvEqTuWXWOJCTlQRYE29hSTGZj6sripsfEemaWG NU4LzHDvPeoPAN/PALzzVuVBvDd117B6QtZYDO5Vhxr0PtNaPswSt5QHhg7f6NV2iA5O FbvoDkxil4Nmr5yICir1yqpMeQT9lWFwPFZHCIqqNXNQDm3o5Z3Y/OI72p7FWfPx9EEp s+KRFZR/Kly2EmlGUfLTRzLBd0hnKkTgsrb267cTfjYBL5/NRH9IxcLevAVm00zZYv8I 61ww== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BeNF1DEkgFgIahDQjB5lfes3vT9oBROmsZ391gODmgk=; b=Tck8/pEiCdGkeYIEvc2oLgmQm1aVxcty37HJhG6Q0hh8QmbEYmGhP2clrY0jLjJbTQ S4BcPNhW/WZKpyt8HTzEfbzgnQEt2npnlMdTPCOGKi6qHhMqsIcMqWQFdTggelQQbLFR AApR2cEOi/HZI3cPCDmlrYI0NkD2KxwgP0mTICBISg18SuA1HkLbTymEVQgBA0Lf1Heg JdqT/3cD4WWJ79G5aJKu0gyZS6OkWedsRv9gsM+aimmWG/b/HNxgHpiRJ8yVz1EbDhx2 hZSL4UC5Ol51U63vdINwWoCjqOeYFphY43o7zCT6PWFsJESjx3LVm2ZKH1Dn1MpnBb9A sG7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="G6XG/lJS"; 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 g21si201375ejr.195.2019.11.27.13.27.56; Wed, 27 Nov 2019 13:28:20 -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="G6XG/lJS"; 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 S1731806AbfK0VCD (ORCPT + 99 others); Wed, 27 Nov 2019 16:02:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:54502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727340AbfK0VCB (ORCPT ); Wed, 27 Nov 2019 16:02:01 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4D2F82084B; Wed, 27 Nov 2019 21:02:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888520; bh=/X42qqck8nkLc0mAmS/qSEjM3OBOAqD15gc7gZhyWjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G6XG/lJSz/201uNsHqwYHhzu+0G0jpERtkVwlPmhYxHbyPkDUUOloPW7C9lQd/ZwH uc9TrwhNFAa+3O7d36LHiRDE199XCqpVnW/vicIe90gfRNI7VjvwpzaQ18StY4RyYw JSCRhyIUeUq/ME3xaTL3zyhkcVadtkX4dMeoSndA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , "Kirill A. Shutemov" , Andrew Morton , Stephen Rothwell , Keith Busch , "Michael S. Tsirkin" , Kees Cook , YueHaibing , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 166/306] mm/gup_benchmark.c: prevent integer overflow in ioctl Date: Wed, 27 Nov 2019 21:30:16 +0100 Message-Id: <20191127203127.552874142@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.mountain Fixes: 64c349f4ae78 ("mm: add infrastructure for get_user_pages_fast() benchmarking") 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; + if (gup->size > ULONG_MAX) + return -EINVAL; + nr_pages = gup->size / PAGE_SIZE; pages = kvcalloc(nr_pages, sizeof(void *), GFP_KERNEL); if (!pages) -- 2.20.1