Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

objtool: Check that module init/exit function is an indirect call target

Some out-of-tree modules still do not use module_init() / module_exit()
macros and simply create functions with magic names init_module() and
cleanup_module() instead. As a result, these functions are not recognized
as indirect call targets by objtool and such module fails to load into an
IBT enabled kernel.

This old way is not even documented any more but it is cleaner to issue
a warning than to let the module fail on load without obvious reason.

Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20230118105215.B9DA960514@lion.mk-sys.cz

authored by

Michal Kubecek and committed by
Peter Zijlstra
03d7a105 3da73f10

+15
+8
tools/objtool/Documentation/objtool.txt
··· 410 410 can remove this warning by putting the ANNOTATE_INTRA_FUNCTION_CALL 411 411 directive right before the call. 412 412 413 + 12. file.o: warning: func(): not an indirect call target 414 + 415 + This means that objtool is running with --ibt and a function expected 416 + to be an indirect call target is not. In particular, this happens for 417 + init_module() or cleanup_module() if a module relies on these special 418 + names and does not use module_init() / module_exit() macros to create 419 + them. 420 + 413 421 414 422 If the error doesn't seem to make sense, it could be a bug in objtool. 415 423 Feel free to ask the objtool maintainer for help.
+7
tools/objtool/check.c
··· 847 847 list_for_each_entry(insn, &file->endbr_list, call_node) { 848 848 849 849 int *site = (int *)sec->data->d_buf + idx; 850 + struct symbol *sym = insn->sym; 850 851 *site = 0; 852 + 853 + if (opts.module && sym && sym->type == STT_FUNC && 854 + insn->offset == sym->offset && 855 + (!strcmp(sym->name, "init_module") || 856 + !strcmp(sym->name, "cleanup_module"))) 857 + WARN("%s(): not an indirect call target", sym->name); 851 858 852 859 if (elf_add_reloc_to_insn(file->elf, sec, 853 860 idx * sizeof(int),