Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1099020imd; Thu, 1 Nov 2018 10:11:03 -0700 (PDT) X-Google-Smtp-Source: AJdET5eiohXlCLIvenbxq3juzvdMOwvKBdkLPPEmqvgZnmZK7BvM7R5k6DSKPQUL2STGQFnyytUp X-Received: by 2002:a62:250:: with SMTP id 77-v6mr8747282pfc.16.1541092263310; Thu, 01 Nov 2018 10:11:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541092263; cv=none; d=google.com; s=arc-20160816; b=ybtkuyrHUyLZbD7tAk0YGRWstWjNFdhlsiPX7WQwctwS0nRluTdYPJI7r8dcSJ/tBX 4HEECd9bPNhwq3Az/RHk+TckPqExK/KdABoNW0+0S8kAm0mFtefTyM02U+iI0aiEHyn4 2CXfXhaTiFO4K4SY+DHlBm0JDWO92l+I7qt/vwmVO4R/pjJDvoGh4uSo1/H6EvZt3VWv nQazWK8VMqVgZ2KakorhVQaWAbLQRdBYGGjdFz8sRkWXcBNOBA+RRQPPEHiHtCFMmU/E 54MHJftvJpA4kh4vHs430/ug/qOE5dDcjP37wr5wOX19SqKnwM2KTCBCQkByN2MhTdeg iJKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=1QvsGvTC8hEigxSTkj2tgd9jAoAUsHKRYXn/enT8Npc=; b=mInKPdrhNoVpdyjZpWwiWJ+4fxD0TVKuXxzpB8mxgCgFe8VaY79g09VUKanlExOdfA L9FaWTY9R7/B/rXBSA6fqSsZI2Wl6rk7wWY1+NcjbEUW1y4wQvHNmeKFDLqys4JY2nLT iQLcDt6g79LhR47jOTmlG2Qj+7Y8+Dj3zewRcZXTBscfCjb0S34kNa4PCQwkvlzSoQm1 5F31CramS4x+LmSEC8r0tG0gSdFiO1LxnbZIEuF4dJYfhIs5mBrLKoNHUuIsKMBRytIg Nk04CC/4WC1h+Sn6utZHmhmhzJKQw92BNnvTY0rYE9mqcVpM64U6vAKbTZz23b/nqyh7 yqOQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v19-v6si13983951pfn.26.2018.11.01.10.10.47; Thu, 01 Nov 2018 10:11:03 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727532AbeKBCNl (ORCPT + 99 others); Thu, 1 Nov 2018 22:13:41 -0400 Received: from mx2.suse.de ([195.135.220.15]:36488 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725843AbeKBCNl (ORCPT ); Thu, 1 Nov 2018 22:13:41 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id CB3DBAE61; Thu, 1 Nov 2018 17:09:49 +0000 (UTC) Date: Thu, 1 Nov 2018 18:09:48 +0100 From: Michal Hocko To: miles.chen@mediatek.com Cc: Andrew Morton , Joe Perches , 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 Subject: Re: [PATCH v4] mm/page_owner: clamp read count to PAGE_SIZE Message-ID: <20181101170948.GN23921@dhcp22.suse.cz> References: <1541091607-27402-1-git-send-email-miles.chen@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1541091607-27402-1-git-send-email-miles.chen@mediatek.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 02-11-18 01:00:07, miles.chen@mediatek.com 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. It is good to mention that interface is root only so the harm due to unbounded allocation request is somehow reduced. I believe we want to use seq_file infrastructure in the long term solution. > Change since v3: > - remove the change in kvmalloc > - keep kmalloc in page_owner.c > > Change since v2: > - improve kvmalloc, allow sub page allocations fallback to > vmalloc when CONFIG_HIGHMEM=y > > Change since v1: > - use kvmalloc() > - clamp buffer size to PAGE_SIZE > > Signed-off-by: Miles Chen > Cc: Joe Perches > Cc: Matthew Wilcox > Cc: Michal Hocko Acked-by: Michal Hocko Thanks! > --- > mm/page_owner.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/mm/page_owner.c b/mm/page_owner.c > index 87bc0dfdb52b..b83f295e4eca 100644 > --- 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; > -- > 2.18.0 > -- Michal Hocko SUSE Labs