Skip to content

Commit 5e214f2

Browse files
cobrien7borkmann
authored andcommitted
bpf: Add config to allow loading modules with BTF mismatches
BTF mismatch can occur for a separately-built module even when the ABI is otherwise compatible and nothing else would prevent successfully loading. Add a new Kconfig to control how mismatches are handled. By default, preserve the current behavior of refusing to load the module. If MODULE_ALLOW_BTF_MISMATCH is enabled, load the module but ignore its BTF information. Suggested-by: Yonghong Song <[email protected]> Suggested-by: Michal Suchánek <[email protected]> Signed-off-by: Connor O'Brien <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Shung-Hsi Yu <[email protected]> Acked-by: Song Liu <[email protected]> Link: https://lore.kernel.org/bpf/CAADnVQJ+OVPnBz8z3vNu8gKXX42jCUqfuvhWAyCQDu8N_yqqwQ@mail.gmail.com Link: https://lore.kernel.org/bpf/[email protected]
1 parent dda7596 commit 5e214f2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

kernel/bpf/btf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6398,7 +6398,8 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,
63986398
pr_warn("failed to validate module [%s] BTF: %ld\n",
63996399
mod->name, PTR_ERR(btf));
64006400
kfree(btf_mod);
6401-
err = PTR_ERR(btf);
6401+
if (!IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH))
6402+
err = PTR_ERR(btf);
64026403
goto out;
64036404
}
64046405
err = btf_alloc_id(btf);

lib/Kconfig.debug

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,16 @@ config DEBUG_INFO_BTF_MODULES
339339
help
340340
Generate compact split BTF type information for kernel modules.
341341

342+
config MODULE_ALLOW_BTF_MISMATCH
343+
bool "Allow loading modules with non-matching BTF type info"
344+
depends on DEBUG_INFO_BTF_MODULES
345+
help
346+
For modules whose split BTF does not match vmlinux, load without
347+
BTF rather than refusing to load. The default behavior with
348+
module BTF enabled is to reject modules with such mismatches;
349+
this option will still load module BTF where possible but ignore
350+
it when a mismatch is found.
351+
342352
config GDB_SCRIPTS
343353
bool "Provide GDB scripts for kernel debugging"
344354
help

0 commit comments

Comments
 (0)