* [PATCH 0/2] efi: Fix pstore runtime en/disable @ 2026-11-20 13:18 Ard Biesheuvel 2026-11-20 13:18 ` [PATCH 1/2] efi: pstore: Make pstore_disable parameter read-only again Ard Biesheuvel 2026-11-20 13:18 ` [PATCH 2/2] efi: pstore: Convert into a platform driver for 'efivars' Ard Biesheuvel 0 siblings, 2 replies; 5+ messages in thread From: Ard Biesheuvel @ 2026-11-20 13:18 UTC (permalink / raw) To: linux-efi; +Cc: Ard Biesheuvel, Kees Cook, Guilherme G. Piccoli From: Ard Biesheuvel <ardb@kernel.org> Fix buggy use of /sys/mode/efi-pstore/params to control the module at runtime Cc: Kees Cook <kees@kernel.org> Cc: "Guilherme G. Piccoli" <gpiccoli@igalia.com> Link: https://lore.kernel.org/all/20260906235838.2928815-1-gpiccoli@igalia.com/ Ard Biesheuvel (2): efi: pstore: Make pstore_disable parameter read-only again efi: pstore: Convert into a platform driver for 'efivars' drivers/firmware/efi/efi-pstore.c | 84 ++++++++++---------- drivers/firmware/efi/efi.c | 3 +- 2 files changed, 46 insertions(+), 41 deletions(-) base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 -- 2.56.1.750.gf70dc682cf-goog ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] efi: pstore: Make pstore_disable parameter read-only again 2026-11-20 13:18 [PATCH 0/2] efi: Fix pstore runtime en/disable Ard Biesheuvel @ 2026-11-20 13:18 ` Ard Biesheuvel 2026-11-20 13:18 ` [PATCH 2/2] efi: pstore: Convert into a platform driver for 'efivars' Ard Biesheuvel 1 sibling, 0 replies; 5+ messages in thread From: Ard Biesheuvel @ 2026-11-20 13:18 UTC (permalink / raw) To: linux-efi; +Cc: Ard Biesheuvel, Kees Cook, Guilherme G. Piccoli, 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.750.gf70dc682cf-goog ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] efi: pstore: Convert into a platform driver for 'efivars' 2026-11-20 13:18 [PATCH 0/2] efi: Fix pstore runtime en/disable Ard Biesheuvel 2026-11-20 13:18 ` [PATCH 1/2] efi: pstore: Make pstore_disable parameter read-only again Ard Biesheuvel @ 2026-11-20 13:18 ` Ard Biesheuvel 2026-11-20 13:39 ` sashiko-bot 2026-11-23 9:04 ` Uwe Kleine-König 1 sibling, 2 replies; 5+ messages in thread From: Ard Biesheuvel @ 2026-11-20 13:18 UTC (permalink / raw) To: linux-efi; +Cc: Ard Biesheuvel, Kees Cook, Guilherme G. Piccoli From: Ard Biesheuvel <ardb@kernel.org> efi-pstore already carries MODULE_ALIAS("platform:efivars") to match the "efivars" platform device registered by efisubsys_init(), but never registered an actual platform_driver for it. Convert efi-pstore into a proper platform_driver, and only register the "efivars" platform device when EFI_RT_SUPPORTED_SET_VARIABLE is advertised so udev does not auto-load efi-pstore on platforms with read-only runtime variable services. When pstore_disable is set (via CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE=y or efi_pstore.pstore_disable=Y), skip the initial automatic probe while keeping the platform driver registered. This allows userspace to enable or disable efi-pstore at runtime without rebooting via the standard driver model sysfs interface: echo efivars.0 > /sys/bus/platform/drivers/efi-pstore/bind echo efivars.0 > /sys/bus/platform/drivers/efi-pstore/unbind Signed-off-by: Ard Biesheuvel <ardb@kernel.org> --- drivers/firmware/efi/efi-pstore.c | 51 ++++++++++++++++---- drivers/firmware/efi/efi.c | 3 +- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c index 19a7e4fe5b52..44571fa1dd88 100644 --- a/drivers/firmware/efi/efi-pstore.c +++ b/drivers/firmware/efi/efi-pstore.c @@ -1,7 +1,9 @@ // SPDX-License-Identifier: GPL-2.0+ #include <linux/efi.h> +#include <linux/mod_devicetable.h> #include <linux/module.h> +#include <linux/platform_device.h> #include <linux/pstore.h> #include <linux/slab.h> #include <linux/ucs2_string.h> @@ -21,6 +23,7 @@ MODULE_PARM_DESC(record_size, "size of each pstore UEFI var (in bytes, min/defau static bool efivars_pstore_disable = IS_ENABLED(CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE); +static bool efivars_pstore_autoprobe_disable; module_param_named(pstore_disable, efivars_pstore_disable, bool, 0444); @@ -228,13 +231,17 @@ static struct pstore_info efi_pstore_info = { .erase = efi_pstore_erase, }; -static __init int efivars_pstore_init(void) +static int efi_pstore_probe(struct platform_device *pdev) { + int ret; + if (!efivar_supports_writes()) - return 0; + return -ENODEV; - if (efivars_pstore_disable) - return 0; + if (efivars_pstore_autoprobe_disable) { + efivars_pstore_autoprobe_disable = false; + return -ENODEV; + } /* * Notice that 1024 is the minimum here to prevent issues with @@ -251,29 +258,53 @@ static __init int efivars_pstore_init(void) efi_pstore_info.bufsize = record_size; - if (pstore_register(&efi_pstore_info)) { + ret = pstore_register(&efi_pstore_info); + if (ret) { kfree(efi_pstore_info.buf); efi_pstore_info.buf = NULL; efi_pstore_info.bufsize = 0; + return ret; } return 0; } -static __exit void efivars_pstore_exit(void) +static void efi_pstore_remove(struct platform_device *pdev) { - if (!efi_pstore_info.bufsize) - return; - pstore_unregister(&efi_pstore_info); kfree(efi_pstore_info.buf); efi_pstore_info.buf = NULL; efi_pstore_info.bufsize = 0; } +static const struct platform_device_id efi_pstore_ids[] = { + { "efivars", 0 }, + { } +}; +MODULE_DEVICE_TABLE(platform, efi_pstore_ids); + +static struct platform_driver efi_pstore_driver = { + .probe = efi_pstore_probe, + .remove = efi_pstore_remove, + .id_table = efi_pstore_ids, + .driver = { + .name = "efi-pstore", + }, +}; + +static __init int efivars_pstore_init(void) +{ + efivars_pstore_autoprobe_disable = efivars_pstore_disable; + return platform_driver_register(&efi_pstore_driver); +} + +static __exit void efivars_pstore_exit(void) +{ + platform_driver_unregister(&efi_pstore_driver); +} + module_init(efivars_pstore_init); module_exit(efivars_pstore_exit); MODULE_DESCRIPTION("EFI variable backend for pstore"); MODULE_LICENSE("GPL"); -MODULE_ALIAS("platform:efivars"); diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 9bc22de0d67e..e98436a9bb9b 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -483,7 +483,8 @@ static int __init efisubsys_init(void) error = efivar_ssdt_load(); if (error) pr_err("efi: failed to load SSDT, error %d.\n", error); - platform_device_register_simple("efivars", 0, NULL, 0); + if (efi_rt_services_supported(EFI_RT_SUPPORTED_SET_VARIABLE)) + platform_device_register_simple("efivars", 0, NULL, 0); } BLOCKING_INIT_NOTIFIER_HEAD(&efivar_ops_nh); -- 2.56.1.750.gf70dc682cf-goog ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] efi: pstore: Convert into a platform driver for 'efivars' 2026-11-20 13:18 ` [PATCH 2/2] efi: pstore: Convert into a platform driver for 'efivars' Ard Biesheuvel @ 2026-11-20 13:39 ` sashiko-bot 2026-11-23 9:04 ` Uwe Kleine-König 1 sibling, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-11-20 13:39 UTC (permalink / raw) To: Ard Biesheuvel, linux-efi; +Cc: Ard Biesheuvel, Kees Cook, Guilherme G. Piccoli Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] efi: pstore: missing efivars device for non-generic efivars backends - [Medium] efi: pstore: stale efivars_pstore_autoprobe_disable breaks manual bind It also noticed 1 related pre-existing issue this patch does not introduce: - [Critical] efi: use-after-free in __efi_queue_work() [1] -- commit ff714ad400a8da4c7c0e25c05fa514c713686cad Author: Ard Biesheuvel <ardb@kernel.org> efi: pstore: Convert into a platform driver for 'efivars' This commit converts efi-pstore into a platform driver matching the "efivars" platform device and only registers that device when EFI_RT_SUPPORTED_SET_VARIABLE is advertised. > diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c > index 19a7e4fe5b524..44571fa1dd885 100644 > --- a/drivers/firmware/efi/efi-pstore.c > +++ b/drivers/firmware/efi/efi-pstore.c [ ... ] > @@ -228,13 +231,17 @@ static struct pstore_info efi_pstore_info = { > .erase = efi_pstore_erase, > }; > > -static __init int efivars_pstore_init(void) > +static int efi_pstore_probe(struct platform_device *pdev) > { > + int ret; > + > if (!efivar_supports_writes()) > - return 0; > + return -ENODEV; > > - if (efivars_pstore_disable) > - return 0; > + if (efivars_pstore_autoprobe_disable) { > + efivars_pstore_autoprobe_disable = false; > + return -ENODEV; > + } [ ... ] > +static __init int efivars_pstore_init(void) > +{ > + efivars_pstore_autoprobe_disable = efivars_pstore_disable; > + return platform_driver_register(&efi_pstore_driver); > +} [Severity: Medium] Can efivars_pstore_autoprobe_disable stay true after efivars_pstore_init() returns, causing the first manual bind via sysfs to fail with -ENODEV? If pstore_disable is set and platform_driver_register() does not reach the efivars_pstore_autoprobe_disable check in efi_pstore_probe() (for example when drivers_autoprobe is disabled on the platform bus, or when efivar_supports_writes() is false during initial registration before a late efivars provider registers), efivars_pstore_autoprobe_disable is not cleared. Resetting efivars_pstore_autoprobe_disable to false in efivars_pstore_init() after platform_driver_register() returns would avoid leaving it set past initial registration. > diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c > index 9bc22de0d67ee..e98436a9bb9bd 100644 > --- a/drivers/firmware/efi/efi.c > +++ b/drivers/firmware/efi/efi.c > @@ -483,7 +483,8 @@ static int __init efisubsys_init(void) > error = efivar_ssdt_load(); > if (error) > pr_err("efi: failed to load SSDT, error %d.\n", error); > - platform_device_register_simple("efivars", 0, NULL, 0); > + if (efi_rt_services_supported(EFI_RT_SUPPORTED_SET_VARIABLE)) > + platform_device_register_simple("efivars", 0, NULL, 0); > } > > BLOCKING_INIT_NOTIFIER_HEAD(&efivar_ops_nh); [Severity: High] Does gating efi-pstore on the "efivars" platform device registered here prevent efi-pstore from probing on platforms that provide writable variables through non-generic efivars_register() backends? Before this change, efivars_pstore_init() checked efivar_supports_writes() and registered with pstore directly without requiring the "efivars" platform device. With this change, platforms where generic EFI runtime services do not advertise EFI_RT_SUPPORTED_SET_VARIABLE at boot, or where EFI_BOOT is not set (such as Coreboot GSMI in drivers/firmware/coreboot/gsmi.c, OP-TEE StandaloneMM in drivers/firmware/efi/stmm/tee_stmm_efi.c, or Qualcomm UEFI Secure App in drivers/firmware/qcom/qcom_qseecom_uefisecapp.c), never register the "efivars" platform device, so efi-pstore cannot probe or be bound via sysfs. Conversely, if EFI_RT_SUPPORTED_SET_VARIABLE is set in efi.runtime_supported_mask but generic_ops_supported() returns false in generic_ops_register() (such as on Qualcomm systems where efi.get_next_variable() returns EFI_UNSUPPORTED), efisubsys_init() still registers the "efivars" platform device while __efivars is NULL, causing efi_pstore_probe() to see !efivar_supports_writes() and fail with -ENODEV before the platform-specific efivars driver probes. [Severity: Critical] This problem wasn't introduced by this patch, but if efisubsys_init() fails [1], can destroying efi_rts_wq without clearing EFI_RUNTIME_SERVICES in efi.flags cause a use-after-free in __efi_queue_work()? drivers/firmware/efi/efi.c:efisubsys_init() { ... err_destroy_wq: if (efi_rts_wq) destroy_workqueue(efi_rts_wq); return error; } When a failure in efisubsys_init() reaches err_destroy_wq, efi_rts_wq is destroyed while EFI_RUNTIME_SERVICES remains set, so a later runtime service call through __efi_queue_work() passes efi_enabled(EFI_RUNTIME_SERVICES) and passes the freed efi_rts_wq pointer to queue_work(). [1] https://sashiko.dev/#/bug/linux-a1f302ad-3fdd-4e74-a0f8-c73ca89f1ff3 -- Sashiko AI review · https://sashiko.dev/#/patchset/20261120131827.480055-4-ardb+git@google.com?part=2 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] efi: pstore: Convert into a platform driver for 'efivars' 2026-11-20 13:18 ` [PATCH 2/2] efi: pstore: Convert into a platform driver for 'efivars' Ard Biesheuvel 2026-11-20 13:39 ` sashiko-bot @ 2026-11-23 9:04 ` Uwe Kleine-König 1 sibling, 0 replies; 5+ messages in thread From: Uwe Kleine-König @ 2026-11-23 9:04 UTC (permalink / raw) To: Ard Biesheuvel; +Cc: linux-efi, Ard Biesheuvel, Kees Cook, Guilherme G. Piccoli [-- Attachment #1: Type: text/plain, Size: 2043 bytes --] Hello Ard, On Fri, Nov 20, 2026 at 02:18:30PM +0100, Ard Biesheuvel wrote: > diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c > index 19a7e4fe5b52..44571fa1dd88 100644 > --- a/drivers/firmware/efi/efi-pstore.c > +++ b/drivers/firmware/efi/efi-pstore.c > @@ -1,7 +1,9 @@ > // SPDX-License-Identifier: GPL-2.0+ > > #include <linux/efi.h> > +#include <linux/mod_devicetable.h> please don't add new users for <linux/mod_devicetable.h>. <linux/platform_device.h> already provides platform_device_id without introducing a big number of unneeded build dependencies. > #include <linux/module.h> > +#include <linux/platform_device.h> > #include <linux/pstore.h> > #include <linux/slab.h> > #include <linux/ucs2_string.h> > @@ -251,29 +258,53 @@ static __init int efivars_pstore_init(void) > > efi_pstore_info.bufsize = record_size; > > - if (pstore_register(&efi_pstore_info)) { > + ret = pstore_register(&efi_pstore_info); > + if (ret) { > kfree(efi_pstore_info.buf); > efi_pstore_info.buf = NULL; > efi_pstore_info.bufsize = 0; > + return ret; > } > > return 0; this can be simplified: kfree(efi_pstore_info.buf); efi_pstore_info.buf = NULL; efi_pstore_info.bufsize = 0; - return ret; } - return 0; + return ret; (though I think it's subjective if you like that or not.) > } > > -static __exit void efivars_pstore_exit(void) > +static void efi_pstore_remove(struct platform_device *pdev) > { > - if (!efi_pstore_info.bufsize) > - return; > - > pstore_unregister(&efi_pstore_info); > kfree(efi_pstore_info.buf); > efi_pstore_info.buf = NULL; > efi_pstore_info.bufsize = 0; > } > > +static const struct platform_device_id efi_pstore_ids[] = { > + { "efivars", 0 }, Please don't initialize .driver_data unless you use it. Also ideally use a designated initializer: { .name = "efivars" }, > + { } > +}; > +MODULE_DEVICE_TABLE(platform, efi_pstore_ids); Best regards Uwe [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-23 9:04 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-20 13:18 [PATCH 0/2] efi: Fix pstore runtime en/disable Ard Biesheuvel 2026-11-20 13:18 ` [PATCH 1/2] efi: pstore: Make pstore_disable parameter read-only again Ard Biesheuvel 2026-11-20 13:18 ` [PATCH 2/2] efi: pstore: Convert into a platform driver for 'efivars' Ard Biesheuvel 2026-11-20 13:39 ` sashiko-bot 2026-11-23 9:04 ` Uwe Kleine-König
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox