From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 066B3C282C8 for ; Mon, 28 Jan 2019 16:26:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CD3AE2171F for ; Mon, 28 Jan 2019 16:26:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548692773; bh=wcKouzECdD6zHg5fTlK0U9Q/4g/hq/VirLNmAMCDGZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Qjkpgi01yo09NVv/bqvsg30k2vdS9YblzhM1s7rn0DFyjXVKwqQ2ENZqxdvDmwr1/ 5UMYtVsty9zGNfTNaug+IBAm4Muq3Kw308W8+y/FijWRcUJ5i5uZnF4j4E8Rwmb1zS +eqafKL7oSXfDyOcRV8XN185AAH8NodiJqiOcU1E= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390133AbfA1Q0M (ORCPT ); Mon, 28 Jan 2019 11:26:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:35280 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390117AbfA1Q0J (ORCPT ); Mon, 28 Jan 2019 11:26:09 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 BDE152171F; Mon, 28 Jan 2019 16:26:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548692768; bh=wcKouzECdD6zHg5fTlK0U9Q/4g/hq/VirLNmAMCDGZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KJBdvbCRVwtMT8bUfJP9U9wXd3JecD9sL3K2lIg2vmtPheZFzuCEus9OidZ3eiN8B baXQvwzN9x0SHJUadBBe4XtV9YbwlNeYyDxHz5vfA/EwyJ7/JyoF5YDbi8289sfWzO ApDRyOP64/2mUHP8+h0FzWzKTDzNJI3PLzOyOfaY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Miles Chen , Joe Perches , Matthew Wilcox , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.4 72/80] mm/page_owner: clamp read count to PAGE_SIZE Date: Mon, 28 Jan 2019 11:23:53 -0500 Message-Id: <20190128162401.58841-72-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128162401.58841-1-sashal@kernel.org> References: <20190128162401.58841-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miles Chen [ Upstream commit c8f61cfc871fadfb73ad3eacd64fda457279e911 ] The (root-only) 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. [akpm@linux-foundation.org: use min_t()] Link: http://lkml.kernel.org/r/1541091607-27402-1-git-send-email-miles.chen@mediatek.com Signed-off-by: Miles Chen Acked-by: Michal Hocko Cc: Joe Perches Cc: Matthew Wilcox Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/page_owner.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/page_owner.c b/mm/page_owner.c index dd6b9cebf981..9c9f32fa70fa 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -107,6 +107,7 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn, .entries = &page_ext->trace_entries[0], }; + count = min_t(size_t, count, PAGE_SIZE); kbuf = kmalloc(count, GFP_KERNEL); if (!kbuf) return -ENOMEM; -- 2.19.1