Skip to content

Commit 5f5ec37

Browse files
Matthew Wilcox (Oracle)mehmetb0
Matthew Wilcox (Oracle)
authored andcommitted
mm: open-code PageTail in folio_flags() and const_folio_flags()
BugLink: https://bugs.launchpad.net/bugs/2096827 commit 4de22b2a6a7477d84d9a01eb6b62a9117309d722 upstream. It is unsafe to call PageTail() in dump_page() as page_is_fake_head() will almost certainly return true when called on a head page that is copied to the stack. That will cause the VM_BUG_ON_PGFLAGS() in const_folio_flags() to trigger when it shouldn't. Fortunately, we don't need to call PageTail() here; it's fine to have a pointer to a virtual alias of the page's flag word rather than the real page's flag word. Link: https://lkml.kernel.org/r/[email protected] Fixes: fae7d83 ("mm: add __dump_folio()") Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Cc: Kees Cook <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Koichiro Den <[email protected]>
1 parent b2f5f60 commit 5f5ec37

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/linux/page-flags.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ static const unsigned long *const_folio_flags(const struct folio *folio,
304304
{
305305
const struct page *page = &folio->page;
306306

307-
VM_BUG_ON_PGFLAGS(PageTail(page), page);
307+
VM_BUG_ON_PGFLAGS(page->compound_head & 1, page);
308308
VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags), page);
309309
return &page[n].flags;
310310
}
@@ -313,7 +313,7 @@ static unsigned long *folio_flags(struct folio *folio, unsigned n)
313313
{
314314
struct page *page = &folio->page;
315315

316-
VM_BUG_ON_PGFLAGS(PageTail(page), page);
316+
VM_BUG_ON_PGFLAGS(page->compound_head & 1, page);
317317
VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags), page);
318318
return &page[n].flags;
319319
}

0 commit comments

Comments
 (0)