Skip to content

Commit

Permalink
mm: move call to compound_head() in release_pages()
Browse files Browse the repository at this point in the history
The function is_huge_zero_page() doesn't call compound_head() to make sure
the page pointer is a head page. The call to is_huge_zero_page() in
release_pages() is made before compound_head() is called so the test would
fail if release_pages() was called with a tail page of the huge_zero_page
and put_page_testzero() would be called releasing the page.
This is unlikely to be happening in normal use or we would be seeing all
sorts of process data corruption when accessing a THP zero page.

Looking at other places where is_huge_zero_page() is called, all seem to
only pass a head page so I think the right solution is to move the call
to compound_head() in release_pages() to a point before calling
is_huge_zero_page().

Signed-off-by: Ralph Campbell <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Reviewed-by: Andrew Morton <[email protected]>
Cc: Yu Zhao <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Ralph Campbell authored and torvalds committed Oct 14, 2020
1 parent 30d8ec7 commit a9b576f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mm/swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@ void release_pages(struct page **pages, int nr)
locked_pgdat = NULL;
}

page = compound_head(page);
if (is_huge_zero_page(page))
continue;

Expand All @@ -910,7 +911,6 @@ void release_pages(struct page **pages, int nr)
}
}

page = compound_head(page);
if (!put_page_testzero(page))
continue;

Expand Down

0 comments on commit a9b576f

Please sign in to comment.