Skip to content

Commit 607c543

Browse files
anakryikoborkmann
authored andcommitted
bpf: Sanitize BTF data pointer after module is loaded
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: 36e6844 ("bpf: Load and verify kernel module BTFs") Suggested-by: Jessica Yu <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Jessica Yu <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent e732b53 commit 607c543

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

kernel/module.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3709,6 +3709,11 @@ static noinline int do_init_module(struct module *mod)
37093709
mod->init_layout.ro_size = 0;
37103710
mod->init_layout.ro_after_init_size = 0;
37113711
mod->init_layout.text_size = 0;
3712+
#ifdef CONFIG_DEBUG_INFO_BTF_MODULES
3713+
/* .BTF is not SHF_ALLOC and will get removed, so sanitize pointer */
3714+
mod->btf_data = NULL;
3715+
mod->btf_data_size = 0;
3716+
#endif
37123717
/*
37133718
* We want to free module_init, but be aware that kallsyms may be
37143719
* walking this with preempt disabled. In all the failure paths, we

0 commit comments

Comments
 (0)