From: Andrii Nakryiko andrii@kernel.org
mainline inclusion from mainline-5.11-rc1 commit 607c543f939d8ca6fed7afe90b3a8d6f6684dd17 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD CVE: NA
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
-------------------------------------------------
Given .BTF section is not allocatable, it will get trimmed after module is loaded. BPF system handles that properly by creating an independent copy of data. But prevent any accidental misused by resetting the pointer to BTF data.
Fixes: 36e68442d1af ("bpf: Load and verify kernel module BTFs") Suggested-by: Jessica Yu jeyu@kernel.org Signed-off-by: Andrii Nakryiko andrii@kernel.org Signed-off-by: Daniel Borkmann daniel@iogearbox.net Acked-by: Jessica Yu jeyu@kernel.org Cc: Greg Kroah-Hartman gregkh@linuxfoundation.org Link: https://lore.kernel.org/bpf/20201121070829.2612884-2-andrii@kernel.org (cherry picked from commit 607c543f939d8ca6fed7afe90b3a8d6f6684dd17) Signed-off-by: Wang Yufen wangyufen@huawei.com --- kernel/module.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/kernel/module.c b/kernel/module.c index f9a419443a29..131162d94ccb 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -3826,6 +3826,11 @@ static noinline int do_init_module(struct module *mod) mod->init_layout.ro_size = 0; mod->init_layout.ro_after_init_size = 0; mod->init_layout.text_size = 0; +#ifdef CONFIG_DEBUG_INFO_BTF_MODULES + /* .BTF is not SHF_ALLOC and will get removed, so sanitize pointer */ + mod->btf_data = NULL; + mod->btf_data_size = 0; +#endif /* * We want to free module_init, but be aware that kallsyms may be * walking this with preempt disabled. In all the failure paths, we