Skip to contentSkip to conversation

efi: random: fix NULL-deref when refreshing seed

PATCH Superseded Johan Hovold 4 participants 4 messages Dec 16, 2022 – Dec 19, 2022 EFI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

Fixes e7b813b32a42 ("efi: random: refresh non-volatile random seed when RNG is initialized")
---
 drivers/firmware/efi/efi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/firmware/efi/efi.c +3 -1
index 2e168e5b97de..1a9e2f70c550 100644
@@ -432,7 +432,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
Tested-by on v1 1/1
#1 lore raw
Quoted 10 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.

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

Thanks Johan, this fixes the boot issue I was blindly fighting yesterday.

Quoted 22 lines
---
 drivers/firmware/efi/efi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/firmware/efi/efi.c +3 -1
index 2e168e5b97de..1a9e2f70c550 100644
@@ -432,7 +432,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
#2 lore raw
In reply to Johan Hovold
Quoted 11 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.

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

---

Thanks very much for this, and sorry for the breakage. I'll try to get this in before rc1 is cut, as I've got some other changes scheduled for late in the merge window to send anyway.

Jason

#3 lore raw
Quoted 13 lines · Jason A. Donenfeld
Quoted 11 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.

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

---

Quoted 3 lines

Thanks very much for this, and sorry for the breakage. I'll try to get this in before rc1 is cut, as I've got some other changes scheduled for late in the merge window to send anyway.

In case this one hasn't been picked up yet (it's not in linux-next), I just sent a v2 with an amended commit message with an explicit mention that as this is needed whenever the runtime services have been disabled (e.g. with PREEMPT_RT):

	https://lore.kernel.org/lkml/[email protected]/

Johan