Skip to content

Commit 4da07c9

Browse files
anakryikokernel-patches-bot
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. Suggested-by: Jessica Yu <jeyu@kernel.org> Fixes: 36e6844 ("bpf: Load and verify kernel module BTFs") Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Jessica Yu <jeyu@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
1 parent b924148 commit 4da07c9

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)