Skip to content

Commit fc36def

Browse files
Pavel Tatashintorvalds
authored andcommitted
mm: teach dump_page() to correctly output poisoned struct pages
If struct page is poisoned, and uninitialized access is detected via PF_POISONED_CHECK(page) dump_page() is called to output the page. But, the dump_page() itself accesses struct page to determine how to print it, and therefore gets into a recursive loop. For example: dump_page() __dump_page() PageSlab(page) PF_POISONED_CHECK(page) VM_BUG_ON_PGFLAGS(PagePoisoned(page), page) dump_page() recursion loop. Link: http://lkml.kernel.org/r/[email protected] Fixes: f165b37 ("mm: uninitialized struct page poisoning sanity checking") Signed-off-by: Pavel Tatashin <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 5e4e290 commit fc36def

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

mm/debug.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,25 @@ const struct trace_print_flags vmaflag_names[] = {
4343

4444
void __dump_page(struct page *page, const char *reason)
4545
{
46+
bool page_poisoned = PagePoisoned(page);
47+
int mapcount;
48+
49+
/*
50+
* If struct page is poisoned don't access Page*() functions as that
51+
* leads to recursive loop. Page*() check for poisoned pages, and calls
52+
* dump_page() when detected.
53+
*/
54+
if (page_poisoned) {
55+
pr_emerg("page:%px is uninitialized and poisoned", page);
56+
goto hex_only;
57+
}
58+
4659
/*
4760
* Avoid VM_BUG_ON() in page_mapcount().
4861
* page->_mapcount space in struct page is used by sl[aou]b pages to
4962
* encode own info.
5063
*/
51-
int mapcount = PageSlab(page) ? 0 : page_mapcount(page);
64+
mapcount = PageSlab(page) ? 0 : page_mapcount(page);
5265

5366
pr_emerg("page:%px count:%d mapcount:%d mapping:%px index:%#lx",
5467
page, page_ref_count(page), mapcount,
@@ -60,6 +73,7 @@ void __dump_page(struct page *page, const char *reason)
6073

6174
pr_emerg("flags: %#lx(%pGp)\n", page->flags, &page->flags);
6275

76+
hex_only:
6377
print_hex_dump(KERN_ALERT, "raw: ", DUMP_PREFIX_NONE, 32,
6478
sizeof(unsigned long), page,
6579
sizeof(struct page), false);
@@ -68,7 +82,7 @@ void __dump_page(struct page *page, const char *reason)
6882
pr_alert("page dumped because: %s\n", reason);
6983

7084
#ifdef CONFIG_MEMCG
71-
if (page->mem_cgroup)
85+
if (!page_poisoned && page->mem_cgroup)
7286
pr_alert("page->mem_cgroup:%px\n", page->mem_cgroup);
7387
#endif
7488
}

0 commit comments

Comments
 (0)