Skip to content

Commit ceb1813

Browse files
mcgrofgregkh
authored andcommitted
firmware: enable run time change of forcing fallback loader
Currently one requires to test four kernel configurations to test the firmware API completely: 0) CONFIG_FW_LOADER=y 1) o CONFIG_FW_LOADER=y o CONFIG_FW_LOADER_USER_HELPER=y 2) o CONFIG_FW_LOADER=y o CONFIG_FW_LOADER_USER_HELPER=y o CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y 3) When CONFIG_FW_LOADER=m the built-in stuff is disabled, we have no current tests for this. We can reduce the requirements to three kernel configurations by making fw_config.force_sysfs_fallback a proc knob we flip on off. For kernels that disable CONFIG_IKCONFIG_PROC this can also enable one to inspect if CONFIG_FW_LOADER_USER_HELPER_FALLBACK was enabled at build time by checking the proc value at boot time. Acked-by: Kees Cook <keescook@chromium.org> Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5d6d1dd commit ceb1813

4 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎drivers/base/firmware_loader/fallback.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/security.h>
88
#include <linux/highmem.h>
99
#include <linux/umh.h>
10+
#include <linux/sysctl.h>
1011

1112
#include "fallback.h"
1213
#include "firmware.h"

‎drivers/base/firmware_loader/fallback.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
*
1313
* @force_sysfs_fallback: force the sysfs fallback mechanism to be used
1414
* as if one had enabled CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y.
15+
* Useful to help debug a CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y
16+
* functionality on a kernel where that config entry has been disabled.
1517
* @old_timeout: for internal use
1618
* @loading_timeout: the timeout to wait for the fallback mechanism before
1719
* giving up, in seconds.
1820
*/
1921
struct firmware_fallback_config {
20-
const bool force_sysfs_fallback;
22+
unsigned int force_sysfs_fallback;
2123
int old_timeout;
2224
int loading_timeout;
2325
};

‎drivers/base/firmware_loader/fallback_table.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,28 @@
1919
/* Module or buit-in */
2020
#ifdef CONFIG_FW_LOADER_USER_HELPER
2121

22+
static unsigned int zero;
23+
static unsigned int one = 1;
24+
2225
struct firmware_fallback_config fw_fallback_config = {
2326
.force_sysfs_fallback = IS_ENABLED(CONFIG_FW_LOADER_USER_HELPER_FALLBACK),
2427
.loading_timeout = 60,
2528
.old_timeout = 60,
2629
};
2730
EXPORT_SYMBOL_GPL(fw_fallback_config);
2831

32+
struct ctl_table firmware_config_table[] = {
33+
{
34+
.procname = "force_sysfs_fallback",
35+
.data = &fw_fallback_config.force_sysfs_fallback,
36+
.maxlen = sizeof(unsigned int),
37+
.mode = 0644,
38+
.proc_handler = proc_douintvec_minmax,
39+
.extra1 = &zero,
40+
.extra2 = &one,
41+
},
42+
{ }
43+
};
44+
EXPORT_SYMBOL_GPL(firmware_config_table);
45+
2946
#endif

‎kernel/sysctl.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ extern struct ctl_table random_table[];
253253
extern struct ctl_table epoll_table[];
254254
#endif
255255

256+
#ifdef CONFIG_FW_LOADER_USER_HELPER
257+
extern struct ctl_table firmware_config_table[];
258+
#endif
259+
256260
#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
257261
int sysctl_legacy_va_layout;
258262
#endif
@@ -748,6 +752,13 @@ static struct ctl_table kern_table[] = {
748752
.mode = 0555,
749753
.child = usermodehelper_table,
750754
},
755+
#ifdef CONFIG_FW_LOADER_USER_HELPER
756+
{
757+
.procname = "firmware_config",
758+
.mode = 0555,
759+
.child = firmware_config_table,
760+
},
761+
#endif
751762
{
752763
.procname = "overflowuid",
753764
.data = &overflowuid,

0 commit comments

Comments
 (0)