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