From patchwork Tue Nov 13 05:49:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 10679557 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA1F413BB for ; Tue, 13 Nov 2018 05:50:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A5812A1E4 for ; Tue, 13 Nov 2018 05:50:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8ECB22A26E; Tue, 13 Nov 2018 05:50:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4B652A278 for ; Tue, 13 Nov 2018 05:50:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF30A6B000D; Tue, 13 Nov 2018 00:50:25 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CA3B26B000E; Tue, 13 Nov 2018 00:50:25 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBE2A6B0010; Tue, 13 Nov 2018 00:50:25 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 757CE6B000D for ; Tue, 13 Nov 2018 00:50:25 -0500 (EST) Received: by mail-pg1-f197.google.com with SMTP id 18-v6so7386048pgn.4 for ; Mon, 12 Nov 2018 21:50:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=T/FexRWnLKADXhFxi2gzLlqktSrjQHqWaORBypfakLg=; b=FmYrp5DdltkZgtDTabMcaSkl9RYe4bn51SllrBxtC/lPQhLwh37SN+JgB1rrBpYVuz +JVPB4Sf3DKV7BL1N2GyUxjuvcdbsyBH4yZtwcez3I8Ruf83ddv5GaUaAr2irs9GJL21 ClRXEHOmd/St7Q/oLZIVzcqqazXGEi4tkRvMl6GBvje+/86DIoqyGL3JFlQIJjTGVSh1 vsLkOBQUTfx45zKO9MRH0euDjcZ5QMz3TNWgSK5cDMSUeWhxjaXbCopwkdboA56SRcjk ActAvBJHg20gZkufY//o1MWZB62bRj63UeoRswDxdSKrgXPM5QRGS/CROB6P6TAy94a2 xV9w== X-Gm-Message-State: AGRZ1gIzQ7XHsFrL601L/V4KpM9zGU4aDdzZc5k8AscHz32SvJXu9kPK qTlr1NtZGLjzkqCaFdLysHNkRJIn2ipq8Tz9mEbYjTf2gerGsZTAq5v4NQFSAIu9veVUmJPL0YR pnJ1qIj3ktgax9B+gE/l6gPRYyUveAX7zLJJmhBuA6rgGiYh6SB7m162SROifB2PN5A== X-Received: by 2002:a63:b81a:: with SMTP id p26mr3574177pge.433.1542088225163; Mon, 12 Nov 2018 21:50:25 -0800 (PST) X-Google-Smtp-Source: AJdET5fwHVHF4TAZdAVXd9EYNqv0Iq5EHuRvt4ljHCFGOUEYTh0JMaup927rNBCVFSTR+jXTtNzd X-Received: by 2002:a63:b81a:: with SMTP id p26mr3574153pge.433.1542088224281; Mon, 12 Nov 2018 21:50:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542088224; cv=none; d=google.com; s=arc-20160816; b=wIRAWAaZTQlFqoKOLqRhPXySdhcdQZz002cUGrcOn1+j2pJ9zV/zAyw5jdVbPqZzfp +2BSg7QDE57CWAysgUKF6NhawdnPUzpgYkdJpa/uNR4Oz0cnCpX6uju0iwHXIjD7iZ0h fSYY3XSlgwcgLqyGvPzHIViVWgsj1iW8H34efiZPxbY9bvNVaJKxXt6L0rlnQzHWAUhR yyVG/it7zfeDO6FYv2MsEo7SsfljrzTaUx3o6Y8D3meWgHFPuvgFMs+CShGQbDl994T+ 4KM6TadCmZwbNbiuzE0NLJ33nxvLj/yWP9QK1sscozZFJ6p5NMFMer1zDTNEVl2RHDD9 lpKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=T/FexRWnLKADXhFxi2gzLlqktSrjQHqWaORBypfakLg=; b=xdV58SYoDzwmIRsLOQeDrngI8FK0HWdlc16bHjHADB5bu1PJbyZydbZAOlZ8e1oZ0l e5IppfMdC6ABhLapixLx/4MOtYOy2OMGAR9YACrqQZsJG8NmFVHC1XKYgi6FDe6ghiBB flJhWM6ApN8kHtCHW+nrUFc9W+uSkvqy62A7wpUY5Ggtr6S8cBSJna2qAtnd5d/aurua IxJYoy3/VZWGKqRU74KfYHTRR0TmvSLt1RLezdJ7cldUnQErzc6dM5ZnZ1ucEV8HfnDe nsyD44u6XO4CPDPVT55S43wRNP3qNR53HrIpyISZpp1HiBQL+wLN3/8AlV3KIHfHwq54 e9GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mnsDi7Gt; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id z6si18392570pgl.109.2018.11.12.21.50.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Nov 2018 21:50:24 -0800 (PST) Received-SPF: pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) client-ip=198.145.29.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mnsDi7Gt; spf=pass (google.com: domain of sashal@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sashal@kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sasha-vm.mshome.net (unknown [64.114.255.114]) (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 D000A22510; Tue, 13 Nov 2018 05:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542088224; bh=7mQEjIV2IFnljtef90NPlS5B4LarDbNuW7HZDt0nVlo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mnsDi7GtpgGTmrhDTQX6T5j9Gx5DDt1Ijgq1ajOci6g/oA7TWUw5eQat9zoOidIvN Fn0YTimNycRl2qjhef9/LOb0LSsD2ff8eIjltsB2UIU2bB/3fqhfAfUdP9SligkKYr iWlzP4KGeP87nr0cK0sTExR0RahAbohG2T+Likx8= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Dan Carpenter , Stephen Rothwell , Keith Busch , "Michael S. Tsirkin" , Kees Cook , YueHaibing , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.19 18/44] mm/gup_benchmark.c: prevent integer overflow in ioctl Date: Tue, 13 Nov 2018 00:49:24 -0500 Message-Id: <20181113054950.77898-18-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181113054950.77898-1-sashal@kernel.org> References: <20181113054950.77898-1-sashal@kernel.org> 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: X-Virus-Scanned: ClamAV using ClamSMTP 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 7405c9d89d65..7e6f2d2dafb5 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)