Linux Modules
 help / color / mirror / Atom feed
From: Daniel Gomez <da.gomez@samsung.com>
To: Luis Chamberlain <mcgrof@kernel.org>,
	Petr Pavlu <petr.pavlu@suse.com>,
	Sami Tolvanen <samitolvanen@google.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	"KP Singh" <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	"Bill Wendling" <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>
Cc: <linux-modules@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<bpf@vger.kernel.org>, <llvm@lists.linux.dev>,
	<iovisor-dev@lists.iovisor.org>, <gost.dev@samsung.com>,
	Daniel Gomez <da.gomez@samsung.com>
Subject: [PATCH 1/2] module: allow for module error injection
Date: Wed, 22 Jan 2025 14:11:13 +0100	[thread overview]
Message-ID: <20250122-modules-error-injection-v1-1-910590a04fd5@samsung.com> (raw)
In-Reply-To: <20250122-modules-error-injection-v1-0-910590a04fd5@samsung.com>

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(+)

diff --git a/kernel/module/main.c b/kernel/module/main.c
index 1fb9ad289a6f8f328fc37c6d93730882d0e6e613..54e6c4d0aab23ae5001a52c26417e7e7957ea3fd 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -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)
 {
diff --git a/kernel/module/strict_rwx.c b/kernel/module/strict_rwx.c
index 74834ba15615fa02d1fa72b913feedd7400af779..21936f5cc1e679e4de90331ef4920597d9093f35 100644
--- a/kernel/module/strict_rwx.c
+++ b/kernel/module/strict_rwx.c
@@ -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)
 {

-- 
2.39.5


  reply	other threads:[~2025-01-22 13:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20250122131157eucas1p14bc56b73e8598908574aab12ecdfc245@eucas1p1.samsung.com>
2025-01-22 13:11 ` [PATCH 0/2] modules: allow error injection Daniel Gomez
2025-01-22 13:11   ` Daniel Gomez [this message]
2025-01-28 21:44     ` [PATCH 1/2] module: allow for module " Thomas Weißschuh
2025-01-22 13:11   ` [PATCH 2/2] moderr: add module error injection tool Daniel Gomez
2025-01-22 17:02     ` Alexei Starovoitov
2025-01-28 20:57       ` Luis Chamberlain
2025-02-19 20:17         ` Lucas De Marchi
2025-02-21 20:15           ` Luis Chamberlain
2025-02-22 21:35             ` Daniel Gomez
2025-02-24 14:43               ` Lucas De Marchi
2025-02-28  9:27                 ` Daniel Gomez
2025-02-28 18:48                   ` Lucas De Marchi
2025-03-05 10:06                     ` Daniel Gomez
2025-03-05 21:08                       ` Lucas De Marchi
2025-03-06 13:30                         ` Francois Dugast
2025-02-22 21:29           ` Daniel Gomez
2025-02-04 13:30       ` Daniel Gomez
2025-02-04 15:28         ` Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250122-modules-error-injection-v1-1-910590a04fd5@samsung.com \
    --to=da.gomez@samsung.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=gost.dev@samsung.com \
    --cc=haoluo@google.com \
    --cc=iovisor-dev@lists.iovisor.org \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=justinstitt@google.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=martin.lau@linux.dev \
    --cc=mcgrof@kernel.org \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=petr.pavlu@suse.com \
    --cc=samitolvanen@google.com \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox