History

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.

Connor O'Brien committed 4 years ago

Commit 5e214f21 parent dda75962 files · +12 −1Browse files

Unified · Split

2 files
  1. kernel/bpf/btf.c +2 −1
  2. lib/Kconfig.debug +10 −0
kernel/bpf/btf.c+2−1
@@ -6398,7 +6398,8 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op, · 6397 unmodified lines
6398 pr_warn("failed to validate module [%s] BTF: %ld\n",6398 pr_warn("failed to validate module [%s] BTF: %ld\n",
6399 mod->name, PTR_ERR(btf));6399 mod->name, PTR_ERR(btf));
6400 kfree(btf_mod);6400 kfree(btf_mod);
6401 err = PTR_ERR(btf);6401 if (!IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH))
6402 err = PTR_ERR(btf);
6402 goto out;6403 goto out;
6403 }6404 }
6404 err = btf_alloc_id(btf);6405 err = btf_alloc_id(btf);
lib/Kconfig.debug+10−0
@@ -339,6 +339,16 @@ config DEBUG_INFO_BTF_MODULES · 338 unmodified lines
339 help339 help
340 Generate compact split BTF type information for kernel modules.340 Generate compact split BTF type information for kernel modules.
341 341
342config 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
342config GDB_SCRIPTS352config GDB_SCRIPTS
343 bool "Provide GDB scripts for kernel debugging"353 bool "Provide GDB scripts for kernel debugging"
344 help354 help