From patchwork Thu Nov 1 17:00:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miles Chen X-Patchwork-Id: 10664361 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 2B56514BD for ; Thu, 1 Nov 2018 17:00:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 162D92C23F for ; Thu, 1 Nov 2018 17:00:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13DA32C24D; Thu, 1 Nov 2018 17:00:36 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B66A12C228 for ; Thu, 1 Nov 2018 17:00:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=oDRN2MHSDS314Av+39q3+4j6KNYjETb5ycU0g8EfmQo=; b=hzw/j23CdZtkbB abCN0VK90R5Xx0pWFadBUERWgIZ8hCEsYj7kyoWzhbfolEJomApi1fsoxXaZmIFPda3w6HgU+i/85 bq0y7ZF69cFwiTerybo9HH+h04pb1U4g8gs5LutHZGvl3XVj6BNUgkvyhccDQn5IZ314rhZXonBNv slkmHktWg/L91UafxGDfAs/vxCT5SV5ATqKbnoRW0OrKmg/WErRTyqDziH33o0rMg6x+9ftke42Ob arxunacerJLVwQL2RjN5FiVaIj0FyziaPKXd0l3mpoNcoPnIEZvi2znohwGo7lT2NPLmipgg1xUCO Q+3e10jT+ojobcS8dzSg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gIGKh-00022j-1i for patchwork-linux-mediatek@patchwork.kernel.org; Thu, 01 Nov 2018 17:00:35 +0000 Received: from [210.61.82.183] (helo=mailgw01.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gIGKe-0001xq-JZ; Thu, 01 Nov 2018 17:00:34 +0000 X-UUID: 3963096f438c4c29b4b5f2f4c69d258f-20181102 X-UUID: 3963096f438c4c29b4b5f2f4c69d258f-20181102 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1551470932; Fri, 02 Nov 2018 01:00:16 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 2 Nov 2018 01:00:09 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 2 Nov 2018 01:00:08 +0800 From: To: Andrew Morton , Michal Hocko , Joe Perches , Matthew Wilcox Subject: [PATCH v4] mm/page_owner: clamp read count to PAGE_SIZE Date: Fri, 2 Nov 2018 01:00:07 +0800 Message-ID: <1541091607-27402-1-git-send-email-miles.chen@mediatek.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181101_100032_777118_6B80F015 X-CRM114-Status: UNSURE ( 9.92 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wsd_upstream@mediatek.com, linux-kernel@vger.kernel.org, Michal Hocko , linux-mm@kvack.org, Miles Chen , linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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. 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 --- 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;