Skip to content

Commit 78c0499

Browse files
Ard Biesheuvelgregkh
authored andcommitted
mm: don't dereference struct page fields of invalid pages
[ Upstream commit f073bdc51771f5a5c7a8d1191bfc3ae371d44de7 ] The VM_BUG_ON() check in move_freepages() checks whether the node id of a page matches the node id of its zone. However, it does this before having checked whether the struct page pointer refers to a valid struct page to begin with. This is guaranteed in most cases, but may not be the case if CONFIG_HOLES_IN_ZONE=y. So reorder the VM_BUG_ON() with the pfn_valid_within() check. Link: http://lkml.kernel.org/r/1481706707-6211-2-git-send-email-ard.biesheuvel@linaro.org Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Acked-by: Will Deacon <will.deacon@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Hanjun Guo <hanjun.guo@linaro.org> Cc: Yisheng Xie <xieyisheng1@huawei.com> Cc: Robert Richter <rrichter@cavium.com> Cc: James Morse <james.morse@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent bbe660d commit 78c0499

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

mm/page_alloc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,14 +1527,14 @@ int move_freepages(struct zone *zone,
15271527
#endif
15281528

15291529
for (page = start_page; page <= end_page;) {
1530-
/* Make sure we are not inadvertently changing nodes */
1531-
VM_BUG_ON_PAGE(page_to_nid(page) != zone_to_nid(zone), page);
1532-
15331530
if (!pfn_valid_within(page_to_pfn(page))) {
15341531
page++;
15351532
continue;
15361533
}
15371534

1535+
/* Make sure we are not inadvertently changing nodes */
1536+
VM_BUG_ON_PAGE(page_to_nid(page) != zone_to_nid(zone), page);
1537+
15381538
if (!PageBuddy(page)) {
15391539
page++;
15401540
continue;

0 commit comments

Comments
 (0)