mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-08 20:07:46 +09:00
add support for clang Control Flow Integrity (CFI)
This change adds the CONFIG_CFI_CLANG option, CFI error handling, and a faster look-up table for cross module CFI checks. Bug: 67506682 Change-Id: Ic009f0a629b552a0eb16e6d89808c7029e91447d Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
This commit is contained in:
@@ -2085,6 +2085,8 @@ void __weak module_arch_freeing_init(struct module *mod)
|
||||
{
|
||||
}
|
||||
|
||||
static void cfi_cleanup(struct module *mod);
|
||||
|
||||
/* Free a module, remove from lists, etc. */
|
||||
static void free_module(struct module *mod)
|
||||
{
|
||||
@@ -2126,6 +2128,10 @@ static void free_module(struct module *mod)
|
||||
|
||||
/* This may be empty, but that's OK */
|
||||
disable_ro_nx(&mod->init_layout);
|
||||
|
||||
/* Clean up CFI for the module. */
|
||||
cfi_cleanup(mod);
|
||||
|
||||
module_arch_freeing_init(mod);
|
||||
module_memfree(mod->init_layout.base);
|
||||
kfree(mod->args);
|
||||
@@ -3307,6 +3313,8 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cfi_init(struct module *mod);
|
||||
|
||||
static int post_relocation(struct module *mod, const struct load_info *info)
|
||||
{
|
||||
/* Sort exception table now relocations are done. */
|
||||
@@ -3319,6 +3327,9 @@ static int post_relocation(struct module *mod, const struct load_info *info)
|
||||
/* Setup kallsyms-specific fields. */
|
||||
add_kallsyms(mod, info);
|
||||
|
||||
/* Setup CFI for the module. */
|
||||
cfi_init(mod);
|
||||
|
||||
/* Arch-specific module finalizing. */
|
||||
return module_finalize(info->hdr, info->sechdrs, mod);
|
||||
}
|
||||
@@ -4053,6 +4064,22 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
|
||||
}
|
||||
#endif /* CONFIG_KALLSYMS */
|
||||
|
||||
static void cfi_init(struct module *mod)
|
||||
{
|
||||
#ifdef CONFIG_CFI_CLANG
|
||||
mod->cfi_check =
|
||||
(cfi_check_fn)mod_find_symname(mod, CFI_CHECK_FN_NAME);
|
||||
cfi_module_add(mod, module_addr_min, module_addr_max);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void cfi_cleanup(struct module *mod)
|
||||
{
|
||||
#ifdef CONFIG_CFI_CLANG
|
||||
cfi_module_remove(mod, module_addr_min, module_addr_max);
|
||||
#endif
|
||||
}
|
||||
|
||||
static char *module_flags(struct module *mod, char *buf)
|
||||
{
|
||||
int bx = 0;
|
||||
|
||||
Reference in New Issue
Block a user