Linux Kernels

mm: don't dereference struct page fields of invalid pages

This change “mm: don't dereference struct page fields of invalid pages” (commit f073bdc) in Linux kernel is authored by Ard Biesheuvel <ard.biesheuvel [at] linaro.org> on Tue Jan 10 16:58:00 2017 -0800.

Description of "mm: don't dereference struct page fields of invalid pages"

The change “mm: don't dereference struct page fields of invalid pages” introduces changes as follows.

mm: don't dereference struct page fields of invalid pages

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>

Linux kernel releases containing commit f073bdc

The Linux kernel releases containing this commit are as follows.

Linux kernel code changes from "mm: don't dereference struct page fields of invalid pages"

There are 6 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 mm/page_alloc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
 
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 872caae544ef..74afdb4177cb 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1864,14 +1864,14 @@ int move_freepages(struct zone *zone,
 #endif
 
 	for (page = start_page; page <= end_page;) {
-		/* Make sure we are not inadvertently changing nodes */
-		VM_BUG_ON_PAGE(page_to_nid(page) != zone_to_nid(zone), page);
-
 		if (!pfn_valid_within(page_to_pfn(page))) {
 			page++;
 			continue;
 		}
 
+		/* Make sure we are not inadvertently changing nodes */
+		VM_BUG_ON_PAGE(page_to_nid(page) != zone_to_nid(zone), page);
+
 		if (!PageBuddy(page)) {
 			page++;
 			continue;

The commit for this change in Linux stable tree is f073bdc (patch).

Last modified: 2020/01/11 06:55