From patchwork Thu Oct 25 06:15:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 10655465 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 7EE6014BB for ; Thu, 25 Oct 2018 06:16:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 660932B346 for ; Thu, 25 Oct 2018 06:16:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59E182B34D; Thu, 25 Oct 2018 06:16:14 +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, UNPARSEABLE_RELAY 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 EEDAA2B34B for ; Thu, 25 Oct 2018 06:16:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71D706B0003; Thu, 25 Oct 2018 02:16:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6A6B06B0005; Thu, 25 Oct 2018 02:16:12 -0400 (EDT) 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 56F066B0007; Thu, 25 Oct 2018 02:16:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) by kanga.kvack.org (Postfix) with ESMTP id 257CC6B0003 for ; Thu, 25 Oct 2018 02:16:12 -0400 (EDT) Received: by mail-yb1-f197.google.com with SMTP id 186-v6so5024140ybt.9 for ; Wed, 24 Oct 2018 23:16:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:from:to:cc:subject :message-id:mime-version:content-disposition:user-agent; bh=1wpn0OFTIkb+XO6TH2jeHAaKOknvJKZwlvZi4uRSKxg=; b=WoSdopcVkGdSVq79Fh7opSqQ2c5rEhh4FAEPn2xvLWdsWQiRbOO4P1Bl0ZF17nWeia odzvadILhlYZrVKWSP3FRQqdsuMbqkUZLfH2aWmKjUEI/N0mw9PTeE64FyZSodMW54Ij msshmIE6nAGvMBMsOJT0hUzCdTB/WXPMbXQ7qtK8RtXhfSm5NQ3ot7L6YhamWmbw+WGO m1gTFBrjzqwlXNs/ftFvBSGjkEDAJvebv9bbg4xSqbc1/3gGY2lo33fYrt7BsQxv/sfz +Eg4roDCgRGcWotNDLwE2WlDhSZjtwTMz6pawS3IYlv07WHVAmavJmb355YUQZWyYF+4 UktQ== X-Gm-Message-State: AGRZ1gILIcjLyQcglL2VdEPTvgrXjaSWn+4ag7FiYsBNx83MXP+2Pya4 j6c4iiEQoPapLrckNhJbnUkzzrgmw6ukhunng5+D1cOcscdHg1DWvnh84lsLDfu3a1FZ7kkjiEs Y04f/uzZm7gFq6kkd5u5oKlZTypiTEDAovRyvZVRpsnSWalEOLAinbbRuGfFHqQczzA== X-Received: by 2002:a25:c346:: with SMTP id t67-v6mr190878ybf.273.1540448171828; Wed, 24 Oct 2018 23:16:11 -0700 (PDT) X-Google-Smtp-Source: AJdET5fuj5+eKeHJSzmLjUD+YJGI4hVRNa49F2YFzaYbWO/JPwNcFlPXtmjdEM2SnNd40uZ+yNxu X-Received: by 2002:a25:c346:: with SMTP id t67-v6mr190860ybf.273.1540448171167; Wed, 24 Oct 2018 23:16:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540448171; cv=none; d=google.com; s=arc-20160816; b=z8JCWQ0Y8PoTApDA25+TDlop4J2dlVQwWMa3eh/xjj3ZPX4SeB98TzuWO30DNppV2r edLq2FbuY3hvUBDfGXHP2GXWLPQl/yL8dCmz9o0x8C6SncSl2eFNdvfAfaL1mPxqz63v 8R9X0bfiVuOIRHzJ+KKRt7SILMwvmouFaULGC339wjzrVb49sJCVQ/NAlt4H5RW7PR9H Q2vgtyjlBVFjGb3ZcE8D9/oM/iHRyXXWz+FhHB6Tc++LQhHrgVBWVle7xy+xYSB01lUh U5dE720/kx2pgrx2oT1Oc2hBGi/+pahyrXG6zPsy/qB/1GsQtBh2pFbtvsvhZbQLNSHY UY8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:dkim-signature; bh=1wpn0OFTIkb+XO6TH2jeHAaKOknvJKZwlvZi4uRSKxg=; b=K9daMSysvHRkLcbmzXe+LGxYo+9J4V7NClMepEYVWBVF0ScQgSbk5U6WWlB0ZY3i7w stSqO3IiQPxT/itO6xD34qPiIMZADCgqinT2Mw1uAr4FjcFukDzXDpvATymzQ8Ar+sMb jHNc9aEYfeR06HAkZOAzjVQjqB50Czzv7yiLSUmBOq2kAVl31hYeAu4IFSyOyAU+xxpu c0tqB9zr7rnKKhVuHsSKEMguvGEAIDJPMHngPOTe3JbNGV+AZZtQvx7pEE2oXH2HUvhn cIdOE12zuImqNymh0VmfMQmW2y1PN4LvoATTLuxpJ9TucHEPgnbnxfQ5RRohMVhSCbIE g7DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=NrNHkSUy; spf=pass (google.com: domain of dan.carpenter@oracle.com designates 156.151.31.85 as permitted sender) smtp.mailfrom=dan.carpenter@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2120.oracle.com (userp2120.oracle.com. [156.151.31.85]) by mx.google.com with ESMTPS id c124-v6si4397728ywd.212.2018.10.24.23.16.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Oct 2018 23:16:11 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.carpenter@oracle.com designates 156.151.31.85 as permitted sender) client-ip=156.151.31.85; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=NrNHkSUy; spf=pass (google.com: domain of dan.carpenter@oracle.com designates 156.151.31.85 as permitted sender) smtp.mailfrom=dan.carpenter@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9P6DdJu105957; Thu, 25 Oct 2018 06:15:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2018-07-02; bh=1wpn0OFTIkb+XO6TH2jeHAaKOknvJKZwlvZi4uRSKxg=; b=NrNHkSUyUB27y66OdENAe+XM2+MOsJezVbKkirr9Ukppgr7N4eUTN1YofsCUFsPmwcDQ nEh0fkbYtnYcqIzy/HZfk/bQyMc5YoubrwGtp44F6cQNtGL2CXl5NCuo7LXxME8hFl6q LC09pBYDwbzMwXAu1mcUO01pSFEGmWuFLm7CMUsyGlh5iUVTMtvqg502y0pmjj5FXm4R ocGDKC2Te9rZTV8F2ZGoyGvJ0GUa4clB4jXZs3itVtYIWe2bXDFMeoTkQt2NHnxecbvL m2RJYdJEsnE82bXurO07RBACsRBSgBFG4VHXCa88u3lKd1pa1o9wodTnsWSTsbxAZ4zU 6g== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2n7w0qyev0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Oct 2018 06:15:59 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9P6Fw4T025863 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Oct 2018 06:15:58 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9P6Fu2r015661; Thu, 25 Oct 2018 06:15:57 GMT Received: from kili.mountain (/129.205.6.86) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 24 Oct 2018 23:15:56 -0700 Date: Thu, 25 Oct 2018 09:15:46 +0300 From: Dan Carpenter To: Andrew Morton , "Kirill A. Shutemov" Cc: Stephen Rothwell , Keith Busch , "Michael S. Tsirkin" , Kees Cook , YueHaibing , linux-mm@kvack.org, kernel-janitors@vger.kernel.org Subject: [PATCH] mm/gup_benchmark: prevent integer overflow in ioctl Message-ID: <20181025061546.hnhkv33diogf2uis@kili.mountain> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding User-Agent: NeoMutt/20170113 (1.7.2) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9056 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810250057 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 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. Fixes: 64c349f4ae78 ("mm: add infrastructure for get_user_pages_fast() benchmarking") Signed-off-by: Dan Carpenter Acked-by: Kirill A. Shutemov --- mm/gup_benchmark.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c index debf11388a60..5b42d3d4b60a 100644 --- a/mm/gup_benchmark.c +++ b/mm/gup_benchmark.c @@ -27,6 +27,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)