All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/slab: Initialise random_kmalloc_seed after initcalls
@ 2025-02-12 14:16 Huacai Chen
  2025-02-12 15:39 ` Harry (Hyeonggon) Yoo
  2025-02-18  9:33 ` [PATCH] mm/slab: Initialise random_kmalloc_seed after initcalls WangYuli
  0 siblings, 2 replies; 17+ messages in thread
From: Huacai Chen @ 2025-02-12 14:16 UTC (permalink / raw)
  To: Huacai Chen, Andrew Morton
  Cc: linux-mm, Rafael J . Wysocki, Pavel Machek, linux-pm, GONG Ruiqi,
	Xiu Jianfeng, Huacai Chen, stable, Yuli Wang

Hibernation assumes the memory layout after resume be the same as that
before sleep, but CONFIG_RANDOM_KMALLOC_CACHES breaks this assumption.
At least on LoongArch and ARM64 we observed failures of resuming from
hibernation (on LoongArch non-boot CPUs fail to bringup, on ARM64 some
devices are unusable).

software_resume_initcall(), the function which resume the target kernel
is a initcall function. So, move the random_kmalloc_seed initialisation
after all initcalls.

Cc: stable@vger.kernel.org
Fixes: 3c6152940584290668 ("Randomized slab caches for kmalloc()")
Reported-by: Yuli Wang <wangyuli@uniontech.com>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
 init/main.c      | 3 +++
 mm/slab_common.c | 3 ---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/init/main.c b/init/main.c
index 2a1757826397..1362957bdbe4 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1458,6 +1458,9 @@ static int __ref kernel_init(void *unused)
 	/* need to finish all async __init code before freeing the memory */
 	async_synchronize_full();
 
+#ifdef CONFIG_RANDOM_KMALLOC_CACHES
+	random_kmalloc_seed = get_random_u64();
+#endif
 	system_state = SYSTEM_FREEING_INITMEM;
 	kprobe_free_init_mem();
 	ftrace_free_init_mem();
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 4030907b6b7d..23e324aee218 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -971,9 +971,6 @@ void __init create_kmalloc_caches(void)
 		for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++)
 			new_kmalloc_cache(i, type);
 	}
-#ifdef CONFIG_RANDOM_KMALLOC_CACHES
-	random_kmalloc_seed = get_random_u64();
-#endif
 
 	/* Kmalloc array is now usable */
 	slab_state = UP;
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2025-02-27  2:53 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-12 14:16 [PATCH] mm/slab: Initialise random_kmalloc_seed after initcalls Huacai Chen
2025-02-12 15:39 ` Harry (Hyeonggon) Yoo
2025-02-13  3:20   ` Huacai Chen
2025-02-14  9:33     ` How does swsusp work with randomization features? (was: mm/slab: Initialise random_kmalloc_seed after initcalls) Harry (Hyeonggon) Yoo
2025-02-14 10:02       ` Huacai Chen
2025-02-14 12:44         ` Harry (Hyeonggon) Yoo
2025-02-15  9:53           ` Huacai Chen
2025-02-15 14:05             ` Harry (Hyeonggon) Yoo
2025-02-16  5:08               ` Huacai Chen
2025-02-19 14:10                 ` How does swsusp work with randomization features? Vlastimil Babka
2025-02-19 17:25           ` How does swsusp work with randomization features? (was: mm/slab: Initialise random_kmalloc_seed after initcalls) Kees Cook
2025-02-19 18:09             ` Rafael J. Wysocki
2025-02-25 11:35               ` Huacai Chen
2025-02-25 20:41                 ` Kees Cook
2025-02-26  7:31                   ` Huacai Chen
2025-02-27  2:50                     ` ARM64 crashes when resuming from hibernation (randomization features enabled) Harry Yoo
2025-02-18  9:33 ` [PATCH] mm/slab: Initialise random_kmalloc_seed after initcalls WangYuli

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.