All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joey Jiao <quic_jiangenj@quicinc.com>
To: <linux-modules@vger.kernel.org>
Cc: <quic_jiangenj@quicinc.com>, Luis Chamberlain <mcgrof@kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH] module: Add CONFIG_MODULE_LOAD_IN_SEQUENCE option
Date: Mon, 9 Oct 2023 10:26:35 +0530	[thread overview]
Message-ID: <20231009045636.4143-1-quic_jiangenj@quicinc.com> (raw)

When modprobe cmds are executed one by one, the final loaded modules
are not in fixed sequence as expected.

Add the option to make sure modules are in fixed sequence across reboot.

Signed-off-by: Joey Jiao <quic_jiangenj@quicinc.com>
---
 kernel/module/Kconfig | 11 +++++++++++
 kernel/module/main.c  |  6 ++++++
 2 files changed, 17 insertions(+)

diff --git a/kernel/module/Kconfig b/kernel/module/Kconfig
index 33a2e991f608..b45a45f31d6d 100644
--- a/kernel/module/Kconfig
+++ b/kernel/module/Kconfig
@@ -389,4 +389,15 @@ config MODULES_TREE_LOOKUP
 	def_bool y
 	depends on PERF_EVENTS || TRACING || CFI_CLANG
 
+config MODULE_LOAD_IN_SEQUENCE
+	bool "Load module in sequence"
+	default n
+	help
+	  By default, modules are loaded in random sequence depending on when modprobe
+	  is executed.
+
+	  This option allows modules to be loaded in sequence if modprobe cmds are
+	  executed one by one in sequence. This option is helpful during syzkaller fuzzing
+	  to make sure module is loaded into fixed address across device reboot.
+
 endif # MODULES
diff --git a/kernel/module/main.c b/kernel/module/main.c
index 98fedfdb8db5..587fd84083ae 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -2593,11 +2593,17 @@ static noinline int do_init_module(struct module *mod)
 	 * be cleaned up needs to sync with the queued work - ie
 	 * rcu_barrier()
 	 */
+#ifdef CONFIG_MODULE_LOAD_IN_SEQUENCE
+	llist_add(&freeinit->node, &init_free_list);
+#else
 	if (llist_add(&freeinit->node, &init_free_list))
 		schedule_work(&init_free_wq);
+#endif
 
 	mutex_unlock(&module_mutex);
+#ifdef CONFIG_MODULE_LOAD_IN_SEQUENCE
 	wake_up_all(&module_wq);
+#endif
 
 	mod_stat_add_long(text_size, &total_text_size);
 	mod_stat_add_long(total_size, &total_mod_size);
-- 
2.42.0


             reply	other threads:[~2023-10-09  4:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-09  4:56 Joey Jiao [this message]
2023-10-10 22:36 ` [PATCH] module: Add CONFIG_MODULE_LOAD_IN_SEQUENCE option Luis Chamberlain
2023-10-11  1:57   ` Joey Jiao (QUIC)
2023-10-11  2:21     ` Luis Chamberlain
2023-10-11  6:11       ` Joey Jiao
2023-10-11  6:39 ` Christoph Hellwig

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=20231009045636.4143-1-quic_jiangenj@quicinc.com \
    --to=quic_jiangenj@quicinc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.