1 From 641fe2e9387a36f9ee01d7c69382d1fe147a5e98 Mon Sep 17 00:00:00 2001
2 From: David Hildenbrand <david@redhat.com>
3 Date: Fri, 18 Oct 2019 20:19:16 -0700
4 Subject: drivers/base/memory.c: don't access uninitialized memmaps in soft_offline_page_store()
6 From: David Hildenbrand <david@redhat.com>
8 commit 641fe2e9387a36f9ee01d7c69382d1fe147a5e98 upstream.
10 Uninitialized memmaps contain garbage and in the worst case trigger kernel
11 BUGs, especially with CONFIG_PAGE_POISONING. They should not get touched.
13 Right now, when trying to soft-offline a PFN that resides on a memory
14 block that was never onlined, one gets a misleading error with
15 CONFIG_PAGE_POISONING:
17 :/# echo 5637144576 > /sys/devices/system/memory/soft_offline_page
18 [ 23.097167] soft offline: 0x150000 page already poisoned
20 But the actual result depends on the garbage in the memmap.
22 soft_offline_page() can only work with online pages, it returns -EIO in
23 case of ZONE_DEVICE. Make sure to only forward pages that are online
24 (iow, managed by the buddy) and, therefore, have an initialized memmap.
26 Add a check against pfn_to_online_page() and similarly return -EIO.
28 Link: http://lkml.kernel.org/r/20191010141200.8985-1-david@redhat.com
29 Fixes: f1dd2cd13c4b ("mm, memory_hotplug: do not associate hotadded memory to zones until online") [visible after d0dc12e86b319]
30 Signed-off-by: David Hildenbrand <david@redhat.com>
31 Acked-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
32 Acked-by: Michal Hocko <mhocko@suse.com>
33 Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
34 Cc: "Rafael J. Wysocki" <rafael@kernel.org>
35 Cc: <stable@vger.kernel.org> [4.13+]
36 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
37 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
38 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
41 drivers/base/memory.c | 3 +++
42 1 file changed, 3 insertions(+)
44 --- a/drivers/base/memory.c
45 +++ b/drivers/base/memory.c
46 @@ -554,6 +554,9 @@ store_soft_offline_page(struct device *d
50 + /* Only online pages can be soft-offlined (esp., not ZONE_DEVICE). */
51 + if (!pfn_to_online_page(pfn))
53 ret = soft_offline_page(pfn_to_page(pfn), 0);
54 return ret == 0 ? count : ret;