bpf: Add config to allow loading modules with BTF mismatches
authorConnor O'Brien <connoro@google.com>
Wed, 23 Feb 2022 01:28:14 +0000 (01:28 +0000)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 28 Feb 2022 13:17:10 +0000 (14:17 +0100)
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 <yhs@fb.com>
Suggested-by: Michal Suchánek <msuchanek@suse.de>
Signed-off-by: Connor O'Brien <connoro@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/CAADnVQJ+OVPnBz8z3vNu8gKXX42jCUqfuvhWAyCQDu8N_yqqwQ@mail.gmail.com
Link: https://lore.kernel.org/bpf/20220223012814.1898677-1-connoro@google.com
kernel/bpf/btf.c
lib/Kconfig.debug

index 0890e56e8b084325b97dceb6e9c0ffa4c3470c5d..b472cf0c8fdbe6e0355c733ab137b4fa37c253f0 100644 (file)
@@ -6398,7 +6398,8 @@ static int btf_module_notify(struct notifier_block *nb, unsigned long op,
                        pr_warn("failed to validate module [%s] BTF: %ld\n",
                                mod->name, PTR_ERR(btf));
                        kfree(btf_mod);
-                       err = PTR_ERR(btf);
+                       if (!IS_ENABLED(CONFIG_MODULE_ALLOW_BTF_MISMATCH))
+                               err = PTR_ERR(btf);
                        goto out;
                }
                err = btf_alloc_id(btf);
index 1555da672275c2ce197e452cdc25c67dbf83b822..72ca4684bedadef8e3e195a37fc8aff29e5db611 100644 (file)
@@ -339,6 +339,16 @@ config DEBUG_INFO_BTF_MODULES
        help
          Generate compact split BTF type information for kernel modules.
 
+config MODULE_ALLOW_BTF_MISMATCH
+       bool "Allow loading modules with non-matching BTF type info"
+       depends on DEBUG_INFO_BTF_MODULES
+       help
+         For modules whose split BTF does not match vmlinux, load without
+         BTF rather than refusing to load. The default behavior with
+         module BTF enabled is to reject modules with such mismatches;
+         this option will still load module BTF where possible but ignore
+         it when a mismatch is found.
+
 config GDB_SCRIPTS
        bool "Provide GDB scripts for kernel debugging"
        help