diff mbox series

[v3] module: Add CONFIG_MODULE_DISABLE_INIT_FREE option

Message ID 20231012014012.9030-1-quic_jiangenj@quicinc.com (mailing list archive)
State New, archived
Headers show
Series [v3] module: Add CONFIG_MODULE_DISABLE_INIT_FREE option | expand

Commit Message

Joey Jiao Oct. 12, 2023, 1:40 a.m. UTC
To facilitate syzkaller test, it's essential for the module to retain the same
address across reboots. In userspace, the execution of modprobe commands must
occur sequentially. In the kernel, selecting the CONFIG_MODULE_DISABLE_INIT_FREE
option disables the asynchronous freeing of init sections.

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

Comments

Luis Chamberlain Oct. 12, 2023, 4:50 p.m. UTC | #1
On Thu, Oct 12, 2023 at 07:10:11AM +0530, Joey Jiao wrote:
> To facilitate syzkaller test, it's essential for the module to retain the same
> address across reboots.

Why?

> In userspace, the execution of modprobe commands must
> occur sequentially.

Why?

> In the kernel, selecting the CONFIG_MODULE_DISABLE_INIT_FREE
> option disables the asynchronous freeing of init sections.

No it does not.

> Signed-off-by: Joey Jiao <quic_jiangenj@quicinc.com>
> ---
>  kernel/module/Kconfig | 8 ++++++++
>  kernel/module/main.c  | 5 +++--
>  2 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/module/Kconfig b/kernel/module/Kconfig
> index 33a2e991f608..1cdbee4c51de 100644
> --- a/kernel/module/Kconfig
> +++ b/kernel/module/Kconfig
> @@ -389,4 +389,12 @@ config MODULES_TREE_LOOKUP
>  	def_bool y
>  	depends on PERF_EVENTS || TRACING || CFI_CLANG
>  
> +config MODULE_DISABLE_INIT_FREE
> +	bool "Disable freeing of init sections"
> +	default n
> +	help
> +	  Allows users to prevent the freeing of init sections. This option is
> +	  particularly helpful for syzkaller fuzzing, ensuring that the module
> +	  consistently loads into the same address across reboots.
> +
>  endif # MODULES
> diff --git a/kernel/module/main.c b/kernel/module/main.c
> index 98fedfdb8db5..a5210b90c078 100644
> --- a/kernel/module/main.c
> +++ b/kernel/module/main.c
> @@ -2593,8 +2593,9 @@ static noinline int do_init_module(struct module *mod)
>  	 * be cleaned up needs to sync with the queued work - ie
>  	 * rcu_barrier()
>  	 */
> -	if (llist_add(&freeinit->node, &init_free_list))
> -		schedule_work(&init_free_wq);
> +	if (llist_add(&freeinit->node, &init_free_list) &&
> +		!IS_ENABLED(CONFIG_MODULE_DISABLE_INIT_FREE))
> +			schedule_work(&init_free_wq);

llist_add() returns true if the list was empty prior to adding the
entry, so the functionality you are adding makes no sense with the
commit log in any way shape or form.

  Luis
Luis Chamberlain Oct. 12, 2023, 5:03 p.m. UTC | #2
On Thu, Oct 12, 2023 at 09:50:27AM -0700, Luis Chamberlain wrote:
> > In the kernel, selecting the CONFIG_MODULE_DISABLE_INIT_FREE
> > option disables the asynchronous freeing of init sections.
> 
> No it does not.

I take it back, your patch effectively only does this.

  Luis
diff mbox series

Patch

diff --git a/kernel/module/Kconfig b/kernel/module/Kconfig
index 33a2e991f608..1cdbee4c51de 100644
--- a/kernel/module/Kconfig
+++ b/kernel/module/Kconfig
@@ -389,4 +389,12 @@  config MODULES_TREE_LOOKUP
 	def_bool y
 	depends on PERF_EVENTS || TRACING || CFI_CLANG
 
+config MODULE_DISABLE_INIT_FREE
+	bool "Disable freeing of init sections"
+	default n
+	help
+	  Allows users to prevent the freeing of init sections. This option is
+	  particularly helpful for syzkaller fuzzing, ensuring that the module
+	  consistently loads into the same address across reboots.
+
 endif # MODULES
diff --git a/kernel/module/main.c b/kernel/module/main.c
index 98fedfdb8db5..a5210b90c078 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -2593,8 +2593,9 @@  static noinline int do_init_module(struct module *mod)
 	 * be cleaned up needs to sync with the queued work - ie
 	 * rcu_barrier()
 	 */
-	if (llist_add(&freeinit->node, &init_free_list))
-		schedule_work(&init_free_wq);
+	if (llist_add(&freeinit->node, &init_free_list) &&
+		!IS_ENABLED(CONFIG_MODULE_DISABLE_INIT_FREE))
+			schedule_work(&init_free_wq);
 
 	mutex_unlock(&module_mutex);
 	wake_up_all(&module_wq);