From abde7478ab5dfd32c520fcc7db5b4e5557e6b2cb Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Thu, 18 May 2023 21:38:14 +0800 Subject: [PATCH] kernel: backport an upstream commit to allow loading modules with BTF mismatches Signed-off-by: Tianling Shen --- ...ow-loading-modules-with-BTF-mismatch.patch | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 target/linux/generic/backport-5.15/051-v5.18-bpf-Add-config-to-allow-loading-modules-with-BTF-mismatch.patch diff --git a/target/linux/generic/backport-5.15/051-v5.18-bpf-Add-config-to-allow-loading-modules-with-BTF-mismatch.patch b/target/linux/generic/backport-5.15/051-v5.18-bpf-Add-config-to-allow-loading-modules-with-BTF-mismatch.patch new file mode 100644 index 0000000000..00ef880bf2 --- /dev/null +++ b/target/linux/generic/backport-5.15/051-v5.18-bpf-Add-config-to-allow-loading-modules-with-BTF-mismatch.patch @@ -0,0 +1,59 @@ +From 5e214f2e43e453d862ebbbd2a4f7ee3fe650f209 Mon Sep 17 00:00:00 2001 +From: Connor O'Brien +Date: Wed, 23 Feb 2022 01:28:14 +0000 +Subject: [PATCH] bpf: Add config to allow loading modules with BTF mismatches +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +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 +Suggested-by: Michal Suchánek +Signed-off-by: Connor O'Brien +Signed-off-by: Daniel Borkmann +Acked-by: Shung-Hsi Yu +Acked-by: Song Liu +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 | 3 ++- + lib/Kconfig.debug | 10 ++++++++++ + 2 files changed, 12 insertions(+), 1 deletion(-) + +--- a/kernel/bpf/btf.c ++++ b/kernel/bpf/btf.c +@@ -6076,7 +6076,8 @@ static int btf_module_notify(struct noti + 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); +--- a/lib/Kconfig.debug ++++ b/lib/Kconfig.debug +@@ -336,6 +336,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