efi: efivars: prevent double registration
authorJohan Hovold <johan+linaro@kernel.org>
Thu, 19 Jan 2023 16:42:55 +0000 (17:42 +0100)
committerArd Biesheuvel <ardb@kernel.org>
Thu, 26 Jan 2023 20:32:01 +0000 (21:32 +0100)
Add the missing sanity check to efivars_register() so that it is no
longer possible to override an already registered set of efivar ops
(without first deregistering them).

This can help debug initialisation ordering issues where drivers have so
far unknowingly been relying on overriding the generic ops.

Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/vars.c

index f34e774..bd75b87 100644 (file)
@@ -62,18 +62,27 @@ EXPORT_SYMBOL_GPL(efivar_is_available);
 int efivars_register(struct efivars *efivars,
                     const struct efivar_operations *ops)
 {
+       int rv;
+
        if (down_interruptible(&efivars_lock))
                return -EINTR;
 
+       if (__efivars) {
+               pr_warn("efivars already registered\n");
+               rv = -EBUSY;
+               goto out;
+       }
+
        efivars->ops = ops;
 
        __efivars = efivars;
 
        pr_info("Registered efivars operations\n");
-
+       rv = 0;
+out:
        up(&efivars_lock);
 
-       return 0;
+       return rv;
 }
 EXPORT_SYMBOL_GPL(efivars_register);