Skip to content

Commit 76f2653

Browse files
Hyesoo Yuakpm00
authored andcommitted
mm: page_alloc: check the order of compound page even when the order is zero
For compound pages, the head sets the PG_head flag and the tail sets the compound_head to indicate the head page. If a user allocates a compound page and frees it with a different order, the compound page information will not be properly initialized. To detect this problem, compound_order(page) and the order argument are compared, but this is not checked when the order argument is zero. That error should be checked regardless of the order. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Hyesoo Yu <[email protected]> Reviewed-by: Vishal Moola (Oracle) <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent be16dd7 commit 76f2653

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

mm/page_alloc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,7 @@ static __always_inline bool free_pages_prepare(struct page *page,
10791079
int bad = 0;
10801080
bool skip_kasan_poison = should_skip_kasan_poison(page, fpi_flags);
10811081
bool init = want_init_on_free();
1082+
bool compound = PageCompound(page);
10821083

10831084
VM_BUG_ON_PAGE(PageTail(page), page);
10841085

@@ -1097,16 +1098,15 @@ static __always_inline bool free_pages_prepare(struct page *page,
10971098
return false;
10981099
}
10991100

1101+
VM_BUG_ON_PAGE(compound && compound_order(page) != order, page);
1102+
11001103
/*
11011104
* Check tail pages before head page information is cleared to
11021105
* avoid checking PageCompound for order-0 pages.
11031106
*/
11041107
if (unlikely(order)) {
1105-
bool compound = PageCompound(page);
11061108
int i;
11071109

1108-
VM_BUG_ON_PAGE(compound && compound_order(page) != order, page);
1109-
11101110
if (compound)
11111111
page[1].flags &= ~PAGE_FLAGS_SECOND;
11121112
for (i = 1; i < (1 << order); i++) {

0 commit comments

Comments
 (0)