Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1086742imd; Thu, 1 Nov 2018 10:01:46 -0700 (PDT) X-Google-Smtp-Source: AJdET5eXu4Fk+bnk8oYvwfkhUYuat3YxxdW7hnlaYosEegLS4s5lDwXOnr4tmIUnB1MWdE7fjds+ X-Received: by 2002:a17:902:47:: with SMTP id 65-v6mr8431363pla.112.1541091706004; Thu, 01 Nov 2018 10:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541091705; cv=none; d=google.com; s=arc-20160816; b=JUQQLZlqyY02RURuw1z3d/vheuJUGv/xCGQUas430+pzZuZolkUSdxjV02qz07ipag RjiOGNO2ZIGiLnsq42JxopHYKZ85ATBkZ1T67iPo2DkL98bdUlsaR6gSRoTT8x/0+9V8 rq6bgvcLh0FgI0VoyGmoczMAH8UpTufYfmhiz+Pq7kCnk9ZI9s+bL1O8znVi3SM478nT Ca47RtBDfbfiAEGOP0hFBcuZOFoSs4sS1EY0PEkhtDku14ZsWhJDCOuQMlfSBaOC4VvO QhuGTjbngvDrEI4bz2bEbjKxjOdwSpCmXyrOA8Rtjne+PRLkIDeoiPDvNNXp+F3HTWKz +YMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=CDF7FYy4rlNQMGOvMncvouifq/s14UY8pOfZQ1ESpQs=; b=OficwMuCccG5wzFuq4V8tPL3CqrwBPSgIzdyXRa8T0W/1uJiVG9MRvwdLnWfRgsry5 +rWQeOPX4vUJrPVD9Uj1AeE+QqmcdNjvc6mwryAtdCCSoNP/SvwuWKW7XYkk2lYtdLTi 6xNVCzICBBIgL3s+04hFEh6hVFhsOuCO73JH0Jee1kWKEQf8AxRHTbQK1CQzhmJa2Qhi VIdM2+P6HJUToWmE7G1wDGhHMtNyCxiFF6TJWoPnzv3tqYpz/z4tdtKyftSJg1WAGFDu /SpqBvSHScRlb6KUZgu+lbelNpmJedcCTMUkAyWgg1QyNnhQVI0ToWHYY/KumxXN231F 2VFg== 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 c75-v6si12074270pga.34.2018.11.01.10.01.28; Thu, 01 Nov 2018 10:01:45 -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 S1727514AbeKBCEP (ORCPT + 99 others); Thu, 1 Nov 2018 22:04:15 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:62587 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725982AbeKBCEP (ORCPT ); Thu, 1 Nov 2018 22:04:15 -0400 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 CC: , , , , , Miles Chen , Michal Hocko 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 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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