Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH v2 1/5] efi: pstore: Make pstore_disable parameter read-only again
       [not found] <20261124172811.2580784-7-ardb+git@google.com>
@ 2026-11-24 17:28 ` Ard Biesheuvel
  2026-11-24 17:28 ` [PATCH v2 2/5] efi: efivars: Don't dereference NULL __efivars in efivar_lock() Ard Biesheuvel
  1 sibling, 0 replies; 2+ messages in thread
From: Ard Biesheuvel @ 2026-11-24 17:28 UTC (permalink / raw)
  To: linux-efi
  Cc: Ard Biesheuvel, Kees Cook, Guilherme G. Piccoli,
	Uwe Kleine-König, stable

From: Ard Biesheuvel <ardb@kernel.org>

Commit a28655c330ab ("efi: pstore: Allow dynamic initialization based on
module parameter") wired up a kernel_param_ops::set callback for
pstore_disable that invokes efivars_pstore_init() directly.

Because parse_args() runs before module initialization (and before
mm_core_init() during early boot when built-in), calling
efivars_pstore_init() from the parameter setter is fundamentally broken:

 - Loading efi-pstore as a module with pstore_disable=N initializes and
   registers efi_pstore_info during parse_args(), and then runs
   efivars_pstore_init() a second time from do_init_module(), leaking
   the first buffer, failing pstore_register() with -EBUSY, and zeroing
   efi_pstore_info.buf/bufsize while leaving efi_pstore_info registered
   with pstore.
 - If load_module() fails after parse_args() (e.g., due to a subsequent
   unknown parameter), the module is freed without calling module_exit,
   leaving pstore with a dangling backend pointer.
 - Passing pstore_disable=N before record_size=<N> initializes the
   buffer using the default record_size before record_size is parsed.

Module parameters are meant for boot/load-time configuration rather than
runtime driver state control via sysfs. Revert the dynamic parameter
callback changes and tighten the sysfs permissions of pstore_disable from
0644 to 0444 (matching record_size) so it is no longer misleadingly
writable at runtime.

Fixes: a28655c330ab ("efi: pstore: Allow dynamic initialization based on module parameter")
Cc: stable@vger.kernel.org
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 drivers/firmware/efi/efi-pstore.c | 39 +++-----------------
 1 file changed, 6 insertions(+), 33 deletions(-)

diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c
index a5db3534f0a6..19a7e4fe5b52 100644
--- a/drivers/firmware/efi/efi-pstore.c
+++ b/drivers/firmware/efi/efi-pstore.c
@@ -19,37 +19,10 @@ MODULE_PARM_DESC(record_size, "size of each pstore UEFI var (in bytes, min/defau
 	 EFI_VARIABLE_BOOTSERVICE_ACCESS | \
 	 EFI_VARIABLE_RUNTIME_ACCESS)
 
-static bool pstore_disable = IS_ENABLED(CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE);
+static bool efivars_pstore_disable =
+	IS_ENABLED(CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE);
 
-static int efivars_pstore_init(void);
-static void efivars_pstore_exit(void);
-
-static int efi_pstore_disable_set(const char *val, const struct kernel_param *kp)
-{
-	int err;
-	bool old_pstore_disable = pstore_disable;
-
-	err = param_set_bool(val, kp);
-	if (err)
-		return err;
-
-	if (old_pstore_disable != pstore_disable) {
-		if (pstore_disable)
-			efivars_pstore_exit();
-		else
-			efivars_pstore_init();
-	}
-
-	return 0;
-}
-
-static const struct kernel_param_ops pstore_disable_ops = {
-	.set	= efi_pstore_disable_set,
-	.get	= param_get_bool,
-};
-
-module_param_cb(pstore_disable, &pstore_disable_ops, &pstore_disable, 0644);
-__MODULE_PARM_TYPE(pstore_disable, "bool");
+module_param_named(pstore_disable, efivars_pstore_disable, bool, 0444);
 
 static int efi_pstore_open(struct pstore_info *psi)
 {
@@ -255,12 +228,12 @@ static struct pstore_info efi_pstore_info = {
 	.erase		= efi_pstore_erase,
 };
 
-static int efivars_pstore_init(void)
+static __init int efivars_pstore_init(void)
 {
 	if (!efivar_supports_writes())
 		return 0;
 
-	if (pstore_disable)
+	if (efivars_pstore_disable)
 		return 0;
 
 	/*
@@ -287,7 +260,7 @@ static int efivars_pstore_init(void)
 	return 0;
 }
 
-static void efivars_pstore_exit(void)
+static __exit void efivars_pstore_exit(void)
 {
 	if (!efi_pstore_info.bufsize)
 		return;
-- 
2.56.1.831.g720f3f5937-goog


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

* [PATCH v2 2/5] efi: efivars: Don't dereference NULL __efivars in efivar_lock()
       [not found] <20261124172811.2580784-7-ardb+git@google.com>
  2026-11-24 17:28 ` [PATCH v2 1/5] efi: pstore: Make pstore_disable parameter read-only again Ard Biesheuvel
@ 2026-11-24 17:28 ` Ard Biesheuvel
  1 sibling, 0 replies; 2+ messages in thread
From: Ard Biesheuvel @ 2026-11-24 17:28 UTC (permalink / raw)
  To: linux-efi
  Cc: Ard Biesheuvel, Kees Cook, Guilherme G. Piccoli,
	Uwe Kleine-König, stable

From: Ard Biesheuvel <ardb@kernel.org>

efivar_lock() and efivar_trylock() check __efivars->ops after taking
efivars_lock, but __efivars itself is NULL whenever no efivars
implementation is registered.

That happens at runtime, not only before efivars is set up. For example,
tee_stmm_efi_probe() unregisters the generic efivars ops before
registering its own, and qcom_uefisecapp_remove() and gsmi_exit()
unregister efivars outright. A concurrent or subsequent efivarfs
access, or a write from a pstore backend that is still registered, then
dereferences a NULL pointer instead of failing with -ENODEV.

Check __efivars itself as well as __efivars->ops.

Fixes: 472831d4c4b2 ("efi: vars: Add thin wrapper around EFI get/set variable interface")
Cc: stable@vger.kernel.org
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 drivers/firmware/efi/vars.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/efi/vars.c b/drivers/firmware/efi/vars.c
index 3700e9869767..f9c28fbdb26d 100644
--- a/drivers/firmware/efi/vars.c
+++ b/drivers/firmware/efi/vars.c
@@ -143,7 +143,7 @@ int efivar_lock(void)
 {
 	if (down_interruptible(&efivars_lock))
 		return -EINTR;
-	if (!__efivars->ops) {
+	if (!__efivars || !__efivars->ops) {
 		up(&efivars_lock);
 		return -ENODEV;
 	}
@@ -159,7 +159,7 @@ int efivar_trylock(void)
 {
 	if (down_trylock(&efivars_lock))
 		 return -EBUSY;
-	if (!__efivars->ops) {
+	if (!__efivars || !__efivars->ops) {
 		up(&efivars_lock);
 		return -ENODEV;
 	}
-- 
2.56.1.831.g720f3f5937-goog


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

end of thread, other threads:[~2026-11-24 17:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261124172811.2580784-7-ardb+git@google.com>
2026-11-24 17:28 ` [PATCH v2 1/5] efi: pstore: Make pstore_disable parameter read-only again Ard Biesheuvel
2026-11-24 17:28 ` [PATCH v2 2/5] efi: efivars: Don't dereference NULL __efivars in efivar_lock() Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox