module: Move strict rwx support to a separate file

No functional change.

This patch migrates code that makes module text
and rodata memory read-only and non-text memory
non-executable from core module code into
kernel/module/strict_rwx.c.

Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Aaron Tomlin <atomlin@redhat.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
This commit is contained in:
Aaron Tomlin
2022-03-22 14:03:36 +00:00
committed by Luis Chamberlain
parent 58d208de3e
commit b33465fe9c
4 changed files with 120 additions and 97 deletions

View File

@@ -20,6 +20,17 @@
/* Maximum number of characters written by module_flags() */
#define MODULE_FLAGS_BUF_SIZE (TAINT_FLAGS_COUNT + 4)
/*
* Modules' sections will be aligned on page boundaries
* to ensure complete separation of code and data, but
* only when CONFIG_ARCH_HAS_STRICT_MODULE_RWX=y
*/
#ifdef CONFIG_ARCH_HAS_STRICT_MODULE_RWX
# define debug_align(X) PAGE_ALIGN(X)
#else
# define debug_align(X) (X)
#endif
extern struct mutex module_mutex;
extern struct list_head modules;
@@ -126,3 +137,24 @@ static inline struct module *mod_find(unsigned long addr)
return NULL;
}
#endif /* CONFIG_MODULES_TREE_LOOKUP */
#ifdef CONFIG_ARCH_HAS_STRICT_MODULE_RWX
void frob_text(const struct module_layout *layout, int (*set_memory)(unsigned long start,
int num_pages));
#endif /* CONFIG_ARCH_HAS_STRICT_MODULE_RWX */
#ifdef CONFIG_STRICT_MODULE_RWX
void module_enable_ro(const struct module *mod, bool after_init);
void module_enable_nx(const struct module *mod);
int module_enforce_rwx_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
char *secstrings, struct module *mod);
#else /* !CONFIG_STRICT_MODULE_RWX */
static inline void module_enable_nx(const struct module *mod) { }
static inline void module_enable_ro(const struct module *mod, bool after_init) {}
static inline int module_enforce_rwx_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
char *secstrings, struct module *mod)
{
return 0;
}
#endif /* CONFIG_STRICT_MODULE_RWX */