Skip to content

Commit a26ee56

Browse files
Qian Caitorvalds
authored andcommitted
mm/page_owner: don't access uninitialized memmaps when reading /proc/pagetypeinfo
Uninitialized memmaps contain garbage and in the worst case trigger kernel BUGs, especially with CONFIG_PAGE_POISONING. They should not get touched. For example, when not onlining a memory block that is spanned by a zone and reading /proc/pagetypeinfo with CONFIG_DEBUG_VM_PGFLAGS and CONFIG_PAGE_POISONING, we can trigger a kernel BUG: :/# echo 1 > /sys/devices/system/memory/memory40/online :/# echo 1 > /sys/devices/system/memory/memory42/online :/# cat /proc/pagetypeinfo > test.file page:fffff2c585200000 is uninitialized and poisoned raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p)) There is not page extension available. ------------[ cut here ]------------ kernel BUG at include/linux/mm.h:1107! invalid opcode: 0000 [raspberrypi#1] SMP NOPTI Please note that this change does not affect ZONE_DEVICE, because pagetypeinfo_showmixedcount_print() is called from mm/vmstat.c:pagetypeinfo_showmixedcount() only for populated zones, and ZONE_DEVICE is never populated (zone->present_pages always 0). [david@redhat.com: move check to outer loop, add comment, rephrase description] Link: http://lkml.kernel.org/r/20191011140638.8160-1-david@redhat.com Fixes: f1dd2cd ("mm, memory_hotplug: do not associate hotadded memory to zones until online") # visible after d0dc12e Signed-off-by: Qian Cai <cai@lca.pw> Signed-off-by: David Hildenbrand <david@redhat.com> Acked-by: Michal Hocko <mhocko@suse.com> Acked-by: Vlastimil Babka <vbabka@suse.cz> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org> Cc: Miles Chen <miles.chen@mediatek.com> Cc: Mike Rapoport <rppt@linux.vnet.ibm.com> Cc: Qian Cai <cai@lca.pw> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: <stable@vger.kernel.org> [4.13+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ca210ba commit a26ee56

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎mm/page_owner.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,21 +271,22 @@ void pagetypeinfo_showmixedcount_print(struct seq_file *m,
271271
* not matter as the mixed block count will still be correct
272272
*/
273273
for (; pfn < end_pfn; ) {
274-
if (!pfn_valid(pfn)) {
274+
page = pfn_to_online_page(pfn);
275+
if (!page) {
275276
pfn = ALIGN(pfn + 1, MAX_ORDER_NR_PAGES);
276277
continue;
277278
}
278279

279280
block_end_pfn = ALIGN(pfn + 1, pageblock_nr_pages);
280281
block_end_pfn = min(block_end_pfn, end_pfn);
281282

282-
page = pfn_to_page(pfn);
283283
pageblock_mt = get_pageblock_migratetype(page);
284284

285285
for (; pfn < block_end_pfn; pfn++) {
286286
if (!pfn_valid_within(pfn))
287287
continue;
288288

289+
/* The pageblock is online, no need to recheck. */
289290
page = pfn_to_page(pfn);
290291

291292
if (page_zone(page) != zone)

0 commit comments

Comments
 (0)