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=unavailable 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 0F9C3C282C8 for ; Mon, 28 Jan 2019 17:32:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CA13D2148E for ; Mon, 28 Jan 2019 17:32:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548696735; bh=egtrxuTDIdsMrWXjlfGnnLruwQgaXadpfPw93jZnMYY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=hsNrpeG2KO80fqLRLWU0vg/6vcfhtt0N58G4cgehOCD5Tb3ylkDlPbGGV8cxDf39K ZeUkibuKHvO2N5iEW1+gYOg9HEFD+6LQqd0ycfO/4V365Fx5Fw4/arYb55scbpjnxo Obwt4pxzEOOmoSeTjXr32BR/PtBXGHF8523+TFYI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729988AbfA1P5v (ORCPT ); Mon, 28 Jan 2019 10:57:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:43222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730283AbfA1P5s (ORCPT ); Mon, 28 Jan 2019 10:57:48 -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 229A421783; Mon, 28 Jan 2019 15:57:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691067; bh=egtrxuTDIdsMrWXjlfGnnLruwQgaXadpfPw93jZnMYY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2p4e5d8LwiV+q661sute+a1NJkmpA67mTiGUX/QUTdPTyoYO9eVNJBYgchU5OkEX/ tuAxhV3Ds2AN+k7Y/CgLNlkAcRJ/ni3XwcO++ThYiKZcqMf8ciVWVChypsmR7vRLt7 5lLeOBoHubYvCnqf6m1jL22SXE4NVYhjVeOmSBNc= 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.20 278/304] mm/page_owner: clamp read count to PAGE_SIZE Date: Mon, 28 Jan 2019 10:43:15 -0500 Message-Id: <20190128154341.47195-278-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128154341.47195-1-sashal@kernel.org> References: <20190128154341.47195-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 87bc0dfdb52b..28b06524939f 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 = min_t(size_t, count, PAGE_SIZE); kbuf = kmalloc(count, GFP_KERNEL); if (!kbuf) return -ENOMEM; -- 2.19.1