Skip to contentSkip to conversation

efi: random: fix NULL-deref when refreshing seed

PATCH In review Johan Hovold 4 participants 4 messages Dec 19, 2022 EFI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 efi: random: fix NULL-deref when refreshing seed

Do not try to refresh the RNG seed in case the firmware does not support setting variables.

This is specifically needed to prevent a NULL-pointer dereference on the Lenovo X13s with some firmware revisions, or more generally, whenever the runtime services have been disabled (e.g. efi=noruntime or with PREEMPT_RT).

Fixes e7b813b32a42 ("efi: random: refresh non-volatile random seed when RNG is initialized")

---

Changes in v2
- amend commit message with a comment on this being needed whenever the runtime services have been disabled

 drivers/firmware/efi/efi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/firmware/efi/efi.c +3 -1
index 31a4090c66b3..09716eebe8ac 100644
@@ -429,7 +429,9 @@ static int __init efisubsys_init(void)
 		platform_device_register_simple("efi_secret", 0, NULL, 0);
 #endif
 
-	execute_with_initialized_rng(&refresh_nv_rng_seed_nb);
+	if (efi_rt_services_supported(EFI_RT_SUPPORTED_SET_VARIABLE))
+		execute_with_initialized_rng(&refresh_nv_rng_seed_nb);
+
 	return 0;
 
 err_remove_group:
Signature · 1 line
2.37.4
#1 lore raw
Quoted 13 lines · Johan Hovold

Do not try to refresh the RNG seed in case the firmware does not support setting variables.

This is specifically needed to prevent a NULL-pointer dereference on the Lenovo X13s with some firmware revisions, or more generally, whenever the runtime services have been disabled (e.g. efi=noruntime or with PREEMPT_RT).

Fixes e7b813b32a42 ("efi: random: refresh non-volatile random seed when RNG is initialized")
Quoted 5 lines

---

Changes in v2
- amend commit message with a comment on this being needed whenever the runtime services have been disabled

I'll queue up the one with the amended commit message.

Jason

#2 lore raw
Quoted 16 lines · Jason A. Donenfeld
Quoted 15 lines · Johan Hovold

Do not try to refresh the RNG seed in case the firmware does not support setting variables.

This is specifically needed to prevent a NULL-pointer dereference on the Lenovo X13s with some firmware revisions, or more generally, whenever the runtime services have been disabled (e.g. efi=noruntime or with PREEMPT_RT).

Fixes e7b813b32a42 ("efi: random: refresh non-volatile random seed when RNG is initialized")

---

Quoted 5 lines
Quoted 3 lines

Changes in v2
- amend commit message with a comment on this being needed whenever the runtime services have been disabled

I'll queue up the one with the amended commit message.

Perfect, thanks!

Johan

Tested-by on v2 1/1
#3 lore raw
In reply to Johan Hovold
Quoted 40 lines · Johan Hovold

Do not try to refresh the RNG seed in case the firmware does not support setting variables.

This is specifically needed to prevent a NULL-pointer dereference on the Lenovo X13s with some firmware revisions, or more generally, whenever the runtime services have been disabled (e.g. efi=noruntime or with PREEMPT_RT).

Fixes e7b813b32a42 ("efi: random: refresh non-volatile random seed when RNG is initialized")

---

Changes in v2
- amend commit message with a comment on this being needed whenever the runtime services have been disabled

 drivers/firmware/efi/efi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/firmware/efi/efi.c +3 -2
index 31a4090c66b3..09716eebe8ac 100644
@@ -429,7 +429,9 @@ static int __init efisubsys_init(void)
                platform_device_register_simple("efi_secret", 0, NULL, 0);
 #endif
 
-       execute_with_initialized_rng(&refresh_nv_rng_seed_nb);
+       if (efi_rt_services_supported(EFI_RT_SUPPORTED_SET_VARIABLE))
+               execute_with_initialized_rng(&refresh_nv_rng_seed_nb);
+
        return 0;
 
 err_remove_group:
--
Quoted 2 lines

2.37.4

Andrew already sent one, but also confirming since I reported it, this fixes the issue for me as well.