Skip to content

Commit 18451f9

Browse files
ramosian-gliderrafaeljw
authored andcommitted
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: 6471384 ("mm: security: introduce init_on_alloc=1 and init_on_free=1 boot options") Reported-by: Johannes Stezenbach <js@sig21.net> Signed-off-by: Alexander Potapenko <glider@google.com> Cc: 5.3+ <stable@vger.kernel.org> # 5.3+ Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent b3a987b commit 18451f9

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

kernel/power/snapshot.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,24 +1147,24 @@ void free_basic_memory_bitmaps(void)
11471147

11481148
void clear_free_pages(void)
11491149
{
1150-
#ifdef CONFIG_PAGE_POISONING_ZERO
11511150
struct memory_bitmap *bm = free_pages_map;
11521151
unsigned long pfn;
11531152

11541153
if (WARN_ON(!(free_pages_map)))
11551154
return;
11561155

1157-
memory_bm_position_reset(bm);
1158-
pfn = memory_bm_next_pfn(bm);
1159-
while (pfn != BM_END_OF_MAP) {
1160-
if (pfn_valid(pfn))
1161-
clear_highpage(pfn_to_page(pfn));
1162-
1156+
if (IS_ENABLED(CONFIG_PAGE_POISONING_ZERO) || want_init_on_free()) {
1157+
memory_bm_position_reset(bm);
11631158
pfn = memory_bm_next_pfn(bm);
1159+
while (pfn != BM_END_OF_MAP) {
1160+
if (pfn_valid(pfn))
1161+
clear_highpage(pfn_to_page(pfn));
1162+
1163+
pfn = memory_bm_next_pfn(bm);
1164+
}
1165+
memory_bm_position_reset(bm);
1166+
pr_info("free pages cleared after restore\n");
11641167
}
1165-
memory_bm_position_reset(bm);
1166-
pr_info("free pages cleared after restore\n");
1167-
#endif /* PAGE_POISONING_ZERO */
11681168
}
11691169

11701170
/**

0 commit comments

Comments
 (0)