blob: cb96551d5c7211022802a21f79f2f9ec30ad113c [file] [log] [blame]
From 77e6daad36eca743a853370acb43690c73bf02e5 Mon Sep 17 00:00:00 2001
From: Qian Cai <>
Date: Sun, 6 Oct 2019 17:58:25 -0700
Subject: [PATCH] mm/page_alloc.c: fix a crash in free_pages_prepare()
commit 234fdce892f905cbc2674349a9eb4873e288e5b3 upstream.
On architectures like s390, arch_free_page() could mark the page unused
(set_page_unused()) and any access later would trigger a kernel panic.
Fix it by moving arch_free_page() after all possible accessing calls.
Hardware name: IBM 2964 N96 400 (z/VM 6.4.0)
Krnl PSW : 0404e00180000000 0000000026c2b96e (__free_pages_ok+0x34e/0x5d8)
R:0 T:1 IO:0 EX:0 Key:0 M:1 W:0 P:0 AS:3 CC:2 PM:0 RI:0 EA:3
Krnl GPRS: 0000000088d43af7 0000000000484000 000000000000007c 000000000000000f
000003d080012100 000003d080013fc0 0000000000000000 0000000000100000
00000000275cca48 0000000000000100 0000000000000008 000003d080010000
00000000000001d0 000003d000000000 0000000026c2b78a 000000002717fdb0
Krnl Code: 0000000026c2b95c: ec1100b30659 risbgn %r1,%r1,0,179,6
0000000026c2b962: e32014000036 pfd 2,1024(%r1)
#0000000026c2b968: d7ff10001000 xc 0(256,%r1),0(%r1)
>0000000026c2b96e: 41101100 la %r1,256(%r1)
0000000026c2b972: a737fff8 brctg %r3,26c2b962
0000000026c2b976: d7ff10001000 xc 0(256,%r1),0(%r1)
0000000026c2b97c: e31003400004 lg %r1,832
0000000026c2b982: ebff1430016a asi 5168(%r1),-1
Call Trace:
INFO: lockdep is turned off.
Last Breaking-Event-Address:
Kernel panic - not syncing: Fatal exception: panic_on_oops
00: HCPGIR450W CP entered; disabled wait PSW 00020001 80000000 00000000 26A2379C
In the past, only kernel_poison_pages() would trigger this but it needs
"page_poison=on" kernel cmdline, and I suspect nobody tested that on
s390. Recently, kernel_init_free_pages() (commit 6471384af2a6 ("mm:
security: introduce init_on_alloc=1 and init_on_free=1 boot options"))
was added and could trigger this as well.
[ add comment]
Fixes: 8823b1dbc05f ("mm/page_poison.c: enable PAGE_POISONING as a separate option")
Fixes: 6471384af2a6 ("mm: security: introduce init_on_alloc=1 and init_on_free=1 boot options")
Signed-off-by: Qian Cai <>
Reviewed-by: Heiko Carstens <>
Acked-by: Christian Borntraeger <>
Acked-by: Michal Hocko <>
Cc: "Kirill A. Shutemov" <>
Cc: Vasily Gorbik <>
Cc: Alexander Duyck <>
Cc: <> [5.3+]
Signed-off-by: Andrew Morton <>
Signed-off-by: Linus Torvalds <>
Signed-off-by: Paul Gortmaker <>
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 81177ed87a38..8b6a295fdb02 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1140,8 +1140,14 @@ static __always_inline bool free_pages_prepare(struct page *page,
PAGE_SIZE << order);
- arch_free_page(page, order);
kernel_poison_pages(page, 1 << order, 0);
+ /*
+ * arch_free_page() can make the page's contents inaccessible. s390
+ * does this. So nothing which can access the page's contents should
+ * happen after this.
+ */
+ arch_free_page(page, order);
if (debug_pagealloc_enabled())
kernel_map_pages(page, 1 << order, 0);