Skip to content

Commit a28655c

Browse files
guilhermepiccolikees
authored andcommitted
efi: pstore: Allow dynamic initialization based on module parameter
The efi-pstore module parameter "pstore_disable" warrants that users are able to deactivate such backend. There is also a Kconfig option for the default value of this parameter. It was originally added due to some bad UEFI FW implementations that could break with many variables written. Some distros (such as Arch Linux) set this in their config file still nowadays. And once it is set, even being a writable module parameter, there is effectively no way to make use of efi-pstore anymore. If "pstore_disable" is set to true, the init function of the module exits early and is never called again after the initcall processing. Let's switch this module parameter to have a callback and perform the pstore backend registration again each time it's set from Y->N (and vice-versa). With this, the writable nature of the parameter starts to make sense, given that users now can switch back to using efi-pstore or not during runtime by writing into it. Signed-off-by: Guilherme G. Piccoli <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 77a6557 commit a28655c

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

drivers/firmware/efi/efi-pstore.c

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,43 @@ static unsigned int record_size = 1024;
1414
module_param(record_size, uint, 0444);
1515
MODULE_PARM_DESC(record_size, "size of each pstore UEFI var (in bytes, min/default=1024)");
1616

17-
static bool efivars_pstore_disable =
18-
IS_ENABLED(CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE);
19-
20-
module_param_named(pstore_disable, efivars_pstore_disable, bool, 0644);
21-
2217
#define PSTORE_EFI_ATTRIBUTES \
2318
(EFI_VARIABLE_NON_VOLATILE | \
2419
EFI_VARIABLE_BOOTSERVICE_ACCESS | \
2520
EFI_VARIABLE_RUNTIME_ACCESS)
2621

22+
static bool pstore_disable = IS_ENABLED(CONFIG_EFI_VARS_PSTORE_DEFAULT_DISABLE);
23+
24+
static int efivars_pstore_init(void);
25+
static void efivars_pstore_exit(void);
26+
27+
static int efi_pstore_disable_set(const char *val, const struct kernel_param *kp)
28+
{
29+
int err;
30+
bool old_pstore_disable = pstore_disable;
31+
32+
err = param_set_bool(val, kp);
33+
if (err)
34+
return err;
35+
36+
if (old_pstore_disable != pstore_disable) {
37+
if (pstore_disable)
38+
efivars_pstore_exit();
39+
else
40+
efivars_pstore_init();
41+
}
42+
43+
return 0;
44+
}
45+
46+
static const struct kernel_param_ops pstore_disable_ops = {
47+
.set = efi_pstore_disable_set,
48+
.get = param_get_bool,
49+
};
50+
51+
module_param_cb(pstore_disable, &pstore_disable_ops, &pstore_disable, 0644);
52+
__MODULE_PARM_TYPE(pstore_disable, "bool");
53+
2754
static int efi_pstore_open(struct pstore_info *psi)
2855
{
2956
int err;
@@ -218,12 +245,12 @@ static struct pstore_info efi_pstore_info = {
218245
.erase = efi_pstore_erase,
219246
};
220247

221-
static __init int efivars_pstore_init(void)
248+
static int efivars_pstore_init(void)
222249
{
223250
if (!efivar_supports_writes())
224251
return 0;
225252

226-
if (efivars_pstore_disable)
253+
if (pstore_disable)
227254
return 0;
228255

229256
/*
@@ -250,7 +277,7 @@ static __init int efivars_pstore_init(void)
250277
return 0;
251278
}
252279

253-
static __exit void efivars_pstore_exit(void)
280+
static void efivars_pstore_exit(void)
254281
{
255282
if (!efi_pstore_info.bufsize)
256283
return;

0 commit comments

Comments
 (0)