Skip to contentSkip to conversation

efi: fix NULL-deref in init error path

PATCH In review Johan Hovold 2 participants 2 messages Dec 19, 2022 – Dec 23, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi: fix NULL-deref in init error path

In case runtime services are not supported or have been disabled the runtime services workqueue will never have been allocated.

Do not try to destroy the workqueue unconditionally in the unlikely event that EFI initialisation fails to avoid dereferencing a NULL pointer.

Fixes 98086df8b70c ("efi: add missed destroy_workqueue when efisubsys_init fails")
Cc Li Heng <[email protected]>
---
 drivers/firmware/efi/efi.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/firmware/efi/efi.c +6 -3
index 09716eebe8ac..a2b0cbc8741c 100644
@@ -394,8 +394,8 @@ static int __init efisubsys_init(void)
 	efi_kobj = kobject_create_and_add("efi", firmware_kobj);
 	if (!efi_kobj) {
 		pr_err("efi: Firmware registration failed.\n");
-		destroy_workqueue(efi_rts_wq);
-		return -ENOMEM;
+		error = -ENOMEM;
+		goto err_destroy_wq;
 	}
 
 	if (efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE |
@@ -443,7 +443,10 @@ static int __init efisubsys_init(void)
 err_put:
 	kobject_put(efi_kobj);
 	efi_kobj = NULL;
-	destroy_workqueue(efi_rts_wq);
+err_destroy_wq:
+	if (efi_rts_wq)
+		destroy_workqueue(efi_rts_wq);
+
 	return error;
 }
 
Signature · 1 line
2.37.4
maintainer
#1 lore raw
Quoted 4 lines · Johan Hovold

In case runtime services are not supported or have been disabled the runtime services workqueue will never have been allocated.

Quoted 8 lines

Do not try to destroy the workqueue unconditionally in the unlikely event that EFI initialisation fails to avoid dereferencing a NULL pointer.

Fixes 98086df8b70c ("efi: add missed destroy_workqueue when efisubsys_init fails")
Cc Li Heng <[email protected]>

Thanks for the fix - I will queue it up after -rc1

Quoted 34 lines
---
 drivers/firmware/efi/efi.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/firmware/efi/efi.c +6 -4
index 09716eebe8ac..a2b0cbc8741c 100644
@@ -394,8 +394,8 @@ static int __init efisubsys_init(void)
        efi_kobj = kobject_create_and_add("efi", firmware_kobj);
        if (!efi_kobj) {
                pr_err("efi: Firmware registration failed.\n");
-               destroy_workqueue(efi_rts_wq);
-               return -ENOMEM;
+               error = -ENOMEM;
+               goto err_destroy_wq;
        }
 
        if (efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE |
@@ -443,7 +443,10 @@ static int __init efisubsys_init(void)
 err_put:
        kobject_put(efi_kobj);
        efi_kobj = NULL;
-       destroy_workqueue(efi_rts_wq);
+err_destroy_wq:
+       if (efi_rts_wq)
+               destroy_workqueue(efi_rts_wq);
+
        return error;
 }
 
--

2.37.4