@@ -59,6 +59,7 @@
#include <linux/codetag.h>
#include <linux/debugfs.h>
#include <linux/execmem.h>
+#include <linux/bpf.h>
#include <uapi/linux/module.h>
#include "internal.h"
@@ -3089,6 +3090,7 @@ static noinline int do_init_module(struct module *mod)
return ret;
}
+ALLOW_ERROR_INJECTION(do_init_module, ERRNO);
static int may_init_module(void)
{
@@ -3225,6 +3227,7 @@ static int complete_formation(struct module *mod, struct load_info *info)
mutex_unlock(&module_mutex);
return err;
}
+ALLOW_ERROR_INJECTION(complete_formation, ERRNO);
static int prepare_coming_module(struct module *mod)
{
@@ -9,6 +9,7 @@
#include <linux/mm.h>
#include <linux/vmalloc.h>
#include <linux/set_memory.h>
+#include <linux/bpf.h>
#include "internal.h"
static int module_set_memory(const struct module *mod, enum mod_mem_type type,
@@ -71,6 +72,7 @@ int module_enable_rodata_ro_after_init(const struct module *mod)
return module_set_memory(mod, MOD_RO_AFTER_INIT, set_memory_ro);
}
+ALLOW_ERROR_INJECTION(module_enable_rodata_ro_after_init, ERRNO);
int module_enable_data_nx(const struct module *mod)
{
Allow to test kernel module initialization with eBPF error injection by forcing errors when any of the below annotated functions with ALLOW_ERROR_INJECTION() return. Allow to debug and test module load error behaviour when: complete_formation(): when module initialization switches from MODULE_STATE_UNFORMED to MODULE_STATE_COMING stage. do_init_module(): when an error occurs during module initialization and before we switch from MODULE_STATE_COMING to MODULE_STATE_LIVE stage. module_enable_rodata_ro_after_init(): when an error occurs while setting memory to RO after module initialization. This is when module initialization reaches MODULE_STATE_LIVE stage. Signed-off-by: Daniel Gomez <da.gomez@samsung.com> --- kernel/module/main.c | 3 +++ kernel/module/strict_rwx.c | 2 ++ 2 files changed, 5 insertions(+)