summaryrefslogtreecommitdiff
path: root/kernel/module/strict_rwx.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/module/strict_rwx.c')
-rw-r--r--kernel/module/strict_rwx.c51
1 files changed, 36 insertions, 15 deletions
diff --git a/kernel/module/strict_rwx.c b/kernel/module/strict_rwx.c
index b36d93983465..c45caa4690e5 100644
--- a/kernel/module/strict_rwx.c
+++ b/kernel/module/strict_rwx.c
@@ -11,13 +11,16 @@
#include <linux/set_memory.h>
#include "internal.h"
-static void module_set_memory(const struct module *mod, enum mod_mem_type type,
- int (*set_memory)(unsigned long start, int num_pages))
+static int module_set_memory(const struct module *mod, enum mod_mem_type type,
+ int (*set_memory)(unsigned long start, int num_pages))
{
const struct module_memory *mod_mem = &mod->mem[type];
+ if (!mod_mem->base)
+ return 0;
+
set_vm_flush_reset_perms(mod_mem->base);
- set_memory((unsigned long)mod_mem->base, mod_mem->size >> PAGE_SHIFT);
+ return set_memory((unsigned long)mod_mem->base, mod_mem->size >> PAGE_SHIFT);
}
/*
@@ -26,35 +29,53 @@ static void module_set_memory(const struct module *mod, enum mod_mem_type type,
* CONFIG_STRICT_MODULE_RWX because they are needed regardless of whether we
* are strict.
*/
-void module_enable_text_rox(const struct module *mod)
+int module_enable_text_rox(const struct module *mod)
{
for_class_mod_mem_type(type, text) {
+ int ret;
+
if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX))
- module_set_memory(mod, type, set_memory_rox);
+ ret = module_set_memory(mod, type, set_memory_rox);
else
- module_set_memory(mod, type, set_memory_x);
+ ret = module_set_memory(mod, type, set_memory_x);
+ if (ret)
+ return ret;
}
+ return 0;
}
-void module_enable_rodata_ro(const struct module *mod, bool after_init)
+int module_enable_rodata_ro(const struct module *mod, bool after_init)
{
+ int ret;
+
if (!IS_ENABLED(CONFIG_STRICT_MODULE_RWX) || !rodata_enabled)
- return;
+ return 0;
- module_set_memory(mod, MOD_RODATA, set_memory_ro);
- module_set_memory(mod, MOD_INIT_RODATA, set_memory_ro);
+ ret = module_set_memory(mod, MOD_RODATA, set_memory_ro);
+ if (ret)
+ return ret;
+ ret = module_set_memory(mod, MOD_INIT_RODATA, set_memory_ro);
+ if (ret)
+ return ret;
if (after_init)
- module_set_memory(mod, MOD_RO_AFTER_INIT, set_memory_ro);
+ return module_set_memory(mod, MOD_RO_AFTER_INIT, set_memory_ro);
+
+ return 0;
}
-void module_enable_data_nx(const struct module *mod)
+int module_enable_data_nx(const struct module *mod)
{
if (!IS_ENABLED(CONFIG_STRICT_MODULE_RWX))
- return;
+ return 0;
- for_class_mod_mem_type(type, data)
- module_set_memory(mod, type, set_memory_nx);
+ for_class_mod_mem_type(type, data) {
+ int ret = module_set_memory(mod, type, set_memory_nx);
+
+ if (ret)
+ return ret;
+ }
+ return 0;
}
int module_enforce_rwx_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,