Commit 18451f9f authored by Alexander Potapenko's avatar Alexander Potapenko Committed by Rafael J. Wysocki
Browse files

PM: hibernate: fix crashes with init_on_free=1



Upon resuming from hibernation, free pages may contain stale data from
the kernel that initiated the resume. This breaks the invariant
inflicted by init_on_free=1 that freed pages must be zeroed.

To deal with this problem, make clear_free_pages() also clear the free
pages when init_on_free is enabled.

Fixes: 6471384a ("mm: security: introduce init_on_alloc=1 and init_on_free=1 boot options")
Reported-by: default avatarJohannes Stezenbach <js@sig21.net>
Signed-off-by: default avatarAlexander Potapenko <glider@google.com>
Cc: 5.3+ <stable@vger.kernel.org> # 5.3+
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent b3a987b0
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -1147,13 +1147,13 @@ void free_basic_memory_bitmaps(void)

void clear_free_pages(void)
{
#ifdef CONFIG_PAGE_POISONING_ZERO
	struct memory_bitmap *bm = free_pages_map;
	unsigned long pfn;

	if (WARN_ON(!(free_pages_map)))
		return;

	if (IS_ENABLED(CONFIG_PAGE_POISONING_ZERO) || want_init_on_free()) {
		memory_bm_position_reset(bm);
		pfn = memory_bm_next_pfn(bm);
		while (pfn != BM_END_OF_MAP) {
@@ -1164,7 +1164,7 @@ void clear_free_pages(void)
		}
		memory_bm_position_reset(bm);
		pr_info("free pages cleared after restore\n");
#endif /* PAGE_POISONING_ZERO */
	}
}

/**