From: <miles.chen@mediatek.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Michal Hocko <mhocko@suse.com>, Joe Perches <joe@perches.com>,
Matthew Wilcox <willy@infradead.org>
Cc: <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-mediatek@lists.infradead.org>, <wsd_upstream@mediatek.com>,
Miles Chen <miles.chen@mediatek.com>,
Michal Hocko <mhocko@kernel.org>
Subject: [PATCH v4] mm/page_owner: clamp read count to PAGE_SIZE
Date: Fri, 2 Nov 2018 01:00:07 +0800 [thread overview]
Message-ID: <1541091607-27402-1-git-send-email-miles.chen@mediatek.com> (raw)
From: Miles Chen <miles.chen@mediatek.com>
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 <miles.chen@mediatek.com>
Cc: Joe Perches <joe@perches.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Michal Hocko <mhocko@kernel.org>
---
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
next reply other threads:[~2018-11-01 17:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-01 17:00 miles.chen [this message]
2018-11-01 17:09 ` [PATCH v4] mm/page_owner: clamp read count to PAGE_SIZE Michal Hocko
2018-11-01 21:47 ` Andrew Morton
2018-11-01 23:30 ` Joe Perches
2018-11-02 0:03 ` Matthew Wilcox
2018-11-02 0:41 ` William Kucharski
2018-11-06 21:51 ` Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1541091607-27402-1-git-send-email-miles.chen@mediatek.com \
--to=miles.chen@mediatek.com \
--cc=akpm@linux-foundation.org \
--cc=joe@perches.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=mhocko@suse.com \
--cc=willy@infradead.org \
--cc=wsd_upstream@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).