Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1469398imd; Thu, 1 Nov 2018 16:30:55 -0700 (PDT) X-Google-Smtp-Source: AJdET5cniSkfEg5iW+e42FwEHBngXboRGeY/V53G/d7GtZcCQ/7FrnFW6lYs7Q6hW5fvo1CteVo1 X-Received: by 2002:a63:1157:: with SMTP id 23mr8967330pgr.245.1541115055440; Thu, 01 Nov 2018 16:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541115055; cv=none; d=google.com; s=arc-20160816; b=NMp0eRg94guHxpDygd5XSEzhxvOO0HH85GxEjoI2XzFncJbLoXBDnMi2N8P0VQmFNk 2FNQb3JDss8255QkYC1Hx8shRIRKnES3mX9pZ0POtCPMXdbqODCvHTOv/Kw7oCMjp1cc kH32M9jlA3Solu5pdhtNY+pds7t2PnKY1Lh8gX7DFN2BxEx4D7OVs1iZ9YX5yBw4/rIT kiIgkSOeZ0kQKdIaFzR82oJi5Kuv4TtnMu55bdvE8foKogxyyJwXonmB4ndW8qHE9p1o gu0AlmDaW9uvJD81KUzmGScEX50MTqOjc4uIVaip6BQvwm+8FvU7slOrOceUZu1wUZ8W 7I7w== 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:date:cc:to:from:subject :message-id; bh=oshc8K+2zibfc9IFmHuzQLlArlT6pB0Kpqnb9SgqqSo=; b=kgtC6jhOOHo5nTCMjfZSZyNQajiKEWb0PJar5xK/jAWk052L4PX0QWaJfo1xzznYs8 FEcfIpOKAlMTXaN25FmGjOqj5BMfTbqlRZdRHXCaHZHgKashaGH0ausmV5fglA7tQgRK IAsx56XH5quTukcNQCd0NdFpWEkBuY2QgfWo505pp9vvZac8oWfIZLh5qIhlyasMwaWq oIZVIk+Hrw97/VYGWRgl8ddFNPqAXNe1t2AYTn1maHdd4hadaFCV9qSUq0pDw2DWR10s Xf9raL2cZTNUz170ThDU6LJF8O6UacIaFrEF8FqegwfMp1SvlXvyY2He9nL2738qGuJY 0W2w== ARC-Authentication-Results: i=1; mx.google.com; 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 x2-v6si31626506pgr.432.2018.11.01.16.30.39; Thu, 01 Nov 2018 16:30:55 -0700 (PDT) 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; 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 S1728169AbeKBIfU (ORCPT + 99 others); Fri, 2 Nov 2018 04:35:20 -0400 Received: from smtprelay0221.hostedemail.com ([216.40.44.221]:58186 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727749AbeKBIfU (ORCPT ); Fri, 2 Nov 2018 04:35:20 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay04.hostedemail.com (Postfix) with ESMTP id D04A5180A8145; Thu, 1 Nov 2018 23:30:15 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::,RULES_HIT:41:355:379:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2198:2199:2393:2553:2559:2562:2731:2828:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3874:4321:5007:7576:8603:10004:10400:10848:10967:11026:11232:11658:11914:12043:12296:12740:12760:12895:13069:13311:13357:13439:14181:14659:14721:21080:21627:30051:30054:30090:30091,0,RBL:47.151.153.53:@perches.com:.lbl8.mailshell.net-62.14.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:28,LUA_SUMMARY:none X-HE-Tag: clam17_20c6b73b5135 X-Filterd-Recvd-Size: 2470 Received: from XPS-9350.home (unknown [47.151.153.53]) (Authenticated sender: joe@perches.com) by omf07.hostedemail.com (Postfix) with ESMTPA; Thu, 1 Nov 2018 23:30:13 +0000 (UTC) Message-ID: <3c81f60ac1ff270df972ded4128a7dbf41a91113.camel@perches.com> Subject: Re: [PATCH v4] mm/page_owner: clamp read count to PAGE_SIZE From: Joe Perches To: Andrew Morton , miles.chen@mediatek.com Cc: Michal Hocko , Matthew Wilcox , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, wsd_upstream@mediatek.com, Michal Hocko Date: Thu, 01 Nov 2018 16:30:12 -0700 In-Reply-To: <20181101144723.3ddc1fa1ab7f81184bc2fdb8@linux-foundation.org> References: <1541091607-27402-1-git-send-email-miles.chen@mediatek.com> <20181101144723.3ddc1fa1ab7f81184bc2fdb8@linux-foundation.org> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.30.1-1build1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2018-11-01 at 14:47 -0700, Andrew Morton wrote: > On Fri, 2 Nov 2018 01:00:07 +0800 wrote: > > > From: Miles Chen > > > > The page owner read might allocate a large size of memory with > > a large read count. Allocation fails can easily occur when doing > > high order allocations. > > > > Clamp buffer size to PAGE_SIZE to avoid arbitrary size allocation > > and avoid allocation fails due to high order allocation. > > > > ... > > > > --- a/mm/page_owner.c > > +++ b/mm/page_owner.c > > @@ -351,6 +351,7 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn, > > .skip = 0 > > }; > > > > + count = count > PAGE_SIZE ? PAGE_SIZE : count; > > kbuf = kmalloc(count, GFP_KERNEL); > > if (!kbuf) > > return -ENOMEM; > > A bit tidier: > > --- a/mm/page_owner.c~mm-page_owner-clamp-read-count-to-page_size-fix > +++ a/mm/page_owner.c > @@ -351,7 +351,7 @@ print_page_owner(char __user *buf, size_ > .skip = 0 > }; > > - count = count > PAGE_SIZE ? PAGE_SIZE : count; > + count = min_t(size_t, count, PAGE_SIZE); > kbuf = kmalloc(count, GFP_KERNEL); > if (!kbuf) > return -ENOMEM; A bit tidier still might be if (count > PAGE_SIZE) count = PAGE_SIZE; as that would not always cause a write back to count.