Skip to contentSkip to conversation

init/main: Expose built-in initcalls and blacklist status via debugfs

PATCH In review Aaron Tomlin 3 participants 7 messages May 10 – Jun 28 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 init/main: Expose built-in initcalls and blacklist status via debugfs

At present, identifying the correct function name to supply to the "initcall_blacklist=" kernel command-line parameter requires manual inspection of the source code or kernel symbol tables. Furthermore, administrators lack a reliable runtime mechanism to verify whether a specified built-in module has been successfully blacklisted.

To resolve this, introduce a new debugfs interface at /sys/kernel/debug/modules/builtin_initcalls. This file enumerates all built-in modules alongside their corresponding initialisation callbacks (e.g., those specified by module_init()) in a simple format:
"module_name init_callback". If a built-in module has been actively blacklisted, the entry is explicitly appended with a " [blacklisted]" suffix.

To achieve this without incurring runtime overhead, the ___define_initcall macro is expanded to statically allocate a builtin_initcall_record structure (containing the module and function name strings) within a dedicated .rodata_builtin_initcall_records section.

This implementation incorporates several critical architectural safety measures:
- The custom section name deliberately begins with ".rodata" to ensure KASLR (Kernel Address Space Layout Randomisation) relocation tools process and update the string pointers correctly during boot.
- The structural alignment is explicitly forced to 8 bytes to prevent the compiler from inserting silent padding that would misalign the linker script boundaries.
- The blacklisted_initcalls list head is stripped of its __initdata_or_module annotation, ensuring the list remains safely accessible in memory when queried from user space after early boot.

The creation of the debugfs file and the associated memory allocations are strictly guarded by CONFIG_DEBUG_FS and CONFIG_KALLSYMS, as the underlying initcall blacklisting mechanism is entirely dependent on kallsyms being present.

---
 include/asm-generic/vmlinux.lds.h |  4 +++
 include/linux/init.h              | 21 ++++++++++++
 init/main.c                       | 55 ++++++++++++++++++++++++++++++-
 3 files changed, 79 insertions(+), 1 deletion(-)
include/asm-generic/vmlinux.lds.h +4 -0
index 60c8c22fd3e4..d0fb971a8d5c 100644
@@ -483,6 +483,10 @@
 		SCHED_DATA						\
 		RO_AFTER_INIT_DATA	/* Read only after init */	\
 		. = ALIGN(8);						\
+		__builtin_initcall_records_start = .;			\
+		KEEP(*(.rodata_builtin_initcall_records))		\
+		__builtin_initcall_records_end = .;			\
+		. = ALIGN(8);						\
 		BOUNDED_SECTION_BY(__tracepoints_ptrs, ___tracepoints_ptrs) \
 		*(__tracepoints_strings)/* Tracepoints: strings */	\
 	}								\
include/linux/init.h +21 -0
index 40331923b9f4..d682fe0d6064 100644
@@ -182,6 +182,16 @@ extern struct module __this_module;
 
 #ifndef __ASSEMBLY__
 
+#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_KALLSYMS)
+#ifndef KBUILD_MODNAME
+#define KBUILD_MODNAME "unknown"
+#endif
+struct builtin_initcall_record {
+	const char *modname;
+	const char *fnname;
+};
+#endif
+
 /*
  * initcalls are now grouped by functionality into separate
  * subsections. Ordering inside the subsections is determined
@@ -271,8 +281,19 @@ extern struct module __this_module;
 		__initcall_name(initcall, __iid, id),		\
 		__initcall_section(__sec, __iid))
 
+#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_KALLSYMS)
+#define ___define_initcall(fn, id, __sec)					\
+	__unique_initcall(fn, id, __sec, __initcall_id(fn));			\
+	static const struct builtin_initcall_record				\
+	__initcall_name(builtin_initcall_rec, __initcall_id(fn), id)		\
+	__used __aligned(8) __section(".rodata_builtin_initcall_records") = {	\
+		.modname = KBUILD_MODNAME,					\
+		.fnname = #fn,							\
+	};
+#else
 #define ___define_initcall(fn, id, __sec)			\
 	__unique_initcall(fn, id, __sec, __initcall_id(fn))
+#endif
 
 #define __define_initcall(fn, id) ___define_initcall(fn, id, .initcall##id)
 
init/main.c +54 -1

73 lines not on this page · raw message

Signature · 1 line
2.51.0
#1 lore raw
Quoted 20 lines · Aaron Tomlin

At present, identifying the correct function name to supply to the "initcall_blacklist=" kernel command-line parameter requires manual inspection of the source code or kernel symbol tables. Furthermore, administrators lack a reliable runtime mechanism to verify whether a specified built-in module has been successfully blacklisted.

To resolve this, introduce a new debugfs interface at /sys/kernel/debug/modules/builtin_initcalls. This file enumerates all built-in modules alongside their corresponding initialisation callbacks (e.g., those specified by module_init()) in a simple format:
"module_name init_callback". If a built-in module has been actively blacklisted, the entry is explicitly appended with a " [blacklisted]" suffix.

To achieve this without incurring runtime overhead, the ___define_initcall macro is expanded to statically allocate a builtin_initcall_record structure (containing the module and function name strings) within a dedicated .rodata_builtin_initcall_records section.

Quoted 11 lines

This implementation incorporates several critical architectural safety measures:
- The custom section name deliberately begins with ".rodata" to ensure KASLR (Kernel Address Space Layout Randomisation) relocation tools process and update the string pointers correctly during boot.
- The structural alignment is explicitly forced to 8 bytes to prevent the compiler from inserting silent padding that would misalign the linker script boundaries.
- The blacklisted_initcalls list head is stripped of its __initdata_or_module annotation, ensuring the list remains safely accessible in memory when queried from user space after early boot.

Hi Sasha, Breno,

I thought this might be of interest to you for review, given your recent work and interest on the "killswitch" proposal [1].

[1]: https://lore.kernel.org/lkml/[email protected]/

Kind regards,

Signature · 1 line
Aaron Tomlin
#2 lore raw
In reply to Aaron Tomlin
Quoted 6 lines · Aaron Tomlin

At present, identifying the correct function name to supply to the "initcall_blacklist=" kernel command-line parameter requires manual inspection of the source code or kernel symbol tables. Furthermore, administrators lack a reliable runtime mechanism to verify whether a specified built-in module has been successfully blacklisted.

Quoted 7 lines

To resolve this, introduce a new debugfs interface at /sys/kernel/debug/modules/builtin_initcalls. This file enumerates all built-in modules alongside their corresponding initialisation callbacks (e.g., those specified by module_init()) in a simple format:
"module_name init_callback". If a built-in module has been actively blacklisted, the entry is explicitly appended with a " [blacklisted]" suffix.

Dear maintainers,

I am writing to politely follow up on this patch, as it has been just over a month since its initial submission.

To briefly reiterate, this patch introduces a reliable runtime mechanism to identify built-in initcalls and verify their blacklisted status, thereby significantly improving the usability of the "initcall_blacklist=" parameter.

I would be most grateful for any feedback, or to know whether any further refinements are required for it to be considered for inclusion.

Kind regards,

Signature · 1 line
Aaron Tomlin
#3 lore raw
In reply to Aaron Tomlin
Quoted 5 lines · Aaron Tomlin

At present, identifying the correct function name to supply to the "initcall_blacklist=" kernel command-line parameter requires manual inspection of the source code or kernel symbol tables. Furthermore, administrators lack a reliable runtime mechanism to verify whether a specified built-in module has been successfully blacklisted.

My understanding is that initcall_blacklist is primarily a debugging facility. This is documented in Documentation/admin-guide/kernel-parameters.txt [1] and also outlined in the initial commit 7b0b73d76651 ("init/main.c: add initcall_blacklist kernel parameter") [2]. It is expected that to use it, one must inspect the kernel source code.

If the goal is to allow specific built-in modules to be blacklisted, I wonder whether extending module_blacklist to also cover built-in modules might be a better option. Module names are more appropriate for administrators to use, while initcall names should remain internal to the kernel. Additionally, initcalls are typically "static" and therefore are not guaranteed to have unique names + using module names avoids a dependency on CONFIG_KALLSYMS=y.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/kernel-parameters.txt?h=v7.1#n2408
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7b0b73d76651e5f88c88b76efa18d719f832bf6f

Signature · 2 lines
Thanks,
Petr
#4 lore raw
Quoted 22 lines · Petr Pavlu
Quoted 5 lines · Aaron Tomlin

At present, identifying the correct function name to supply to the "initcall_blacklist=" kernel command-line parameter requires manual inspection of the source code or kernel symbol tables. Furthermore, administrators lack a reliable runtime mechanism to verify whether a specified built-in module has been successfully blacklisted.

My understanding is that initcall_blacklist is primarily a debugging facility. This is documented in Documentation/admin-guide/kernel-parameters.txt [1] and also outlined in the initial commit 7b0b73d76651 ("init/main.c: add initcall_blacklist kernel parameter") [2]. It is expected that to use it, one must inspect the kernel source code.

If the goal is to allow specific built-in modules to be blacklisted, I wonder whether extending module_blacklist to also cover built-in modules might be a better option. Module names are more appropriate for administrators to use, while initcall names should remain internal to the kernel. Additionally, initcalls are typically "static" and therefore are not guaranteed to have unique names + using module names avoids a dependency on CONFIG_KALLSYMS=y.

Quoted 2 lines

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/kernel-parameters.txt?h=v7.1#n2408
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7b0b73d76651e5f88c88b76efa18d719f832bf6f

Hi Petr,

Thank you for your review and the excellent historical context.

Your points regarding static function name collisions and the unnecessary kallsyms dependency are correct.

Extending the module blacklist parameter to intercept built in modules makes far more architectural sense. It provides a consistent interface for administrators and aligns perfectly with existing kernel conventions.

For the forthcoming v2 patchset, I have completely dropped the original approach. Instead, I am implementing a parallel metadata section. By updating the core initcall macros, the compiler will emit the module name string into a custom ELF section directly alongside the function pointer. The core boot code can then evaluate this mapping against the module blacklist before executing the initialisation function.

This new architecture performs all the mapping at compile time. It entirely avoids the kallsyms dependency you highlighted, perfectly preserves the original function names for debugging purposes, and resides securely within the initialisation data so the memory is freed completely immediately after boot.

Kind regards,

Signature · 1 line
Aaron Tomlin
#5 lore raw
In reply to Aaron Tomlin
Quoted 5 lines · On Sun, 10 May 2026 02:13:01 -0400 Aaron Tomlin <[email protected]> wrote:

At present, identifying the correct function name to supply to the "initcall_blacklist=" kernel command-line parameter requires manual inspection of the source code or kernel symbol tables. Furthermore, administrators lack a reliable runtime mechanism to verify whether a specified built-in module has been successfully blacklisted.

I expect nobody has felt a need for this in their day-to-day work, so the interest is low.

A detailed description of the use-cases would be of benefit - help people better understand the value of this to our users. I suggest you add this info and send a v2, if motivated.

Quoted 5 lines

To resolve this, introduce a new debugfs interface at /sys/kernel/debug/modules/builtin_initcalls. This file enumerates all built-in modules alongside their corresponding initialisation callbacks (e.g., those specified by module_init()) in a simple format:
"module_name init_callback".

Isn't this information all available at build time?

Can we extract it and put it in some file somewhere which becomes part of the distributed kernel package?

Or is it possible to write some userspace application which processes the files which are typically in the kernel package and which extracts this info?

Quoted 3 lines

If a built-in module has been actively
blacklisted, the entry is explicitly appended with a " [blacklisted]" suffix.

Can this be added to the /proc/modules output in some fashion? Perhaps just add TAINT_BLACKLISTED and we get this info almost for free?

#6 lore raw
Quoted 8 lines · Andrew Morton
Quoted 5 lines · On Sun, 10 May 2026 02:13:01 -0400 Aaron Tomlin <[email protected]> wrote:

At present, identifying the correct function name to supply to the "initcall_blacklist=" kernel command-line parameter requires manual inspection of the source code or kernel symbol tables. Furthermore, administrators lack a reliable runtime mechanism to verify whether a specified built-in module has been successfully blacklisted.

Quoted 6 lines

I expect nobody has felt a need for this in their day-to-day work, so the interest is low.

A detailed description of the use-cases would be of benefit - help people better understand the value of this to our users. I suggest you add this info and send a v2, if motivated.

Hi Andrew,

Thank you for taking the time to review the patch. I appreciate the pragmatic feedback.

Quoted 10 lines
Quoted 5 lines

To resolve this, introduce a new debugfs interface at /sys/kernel/debug/modules/builtin_initcalls. This file enumerates all built-in modules alongside their corresponding initialisation callbacks (e.g., those specified by module_init()) in a simple format:
"module_name init_callback".

Isn't this information all available at build time?

Can we extract it and put it in some file somewhere which becomes part of the distributed kernel package?

It is indeed possible to extract this. We currently generate modules.builtin, but it only lists module paths, not the corresponding initcall function names. While a userspace application could theoretically parse System.map to find these relationships, this approach assumes the presence of Linux kernel packages on the target server. In some environments, these files are frequently stripped or omitted entirely.

Quoted 6 lines
Quoted 3 lines

If a built-in module has been actively
blacklisted, the entry is explicitly appended with a " [blacklisted]" suffix.

Can this be added to the /proc/modules output in some fashion? Perhaps just add TAINT_BLACKLISTED and we get this info almost for free?

Unfortunately, we cannot append this information to /proc/modules. That interface iterates over the kernel's modules list, which relies on struct module metadata. Because built-in modules are statically linked into vmlinux, they lack this runtime structure entirely and are invisible to /proc/modules.

Petr Pavlu offered excellent advice — extend module_blacklist to also cover built-in modules [1] — I do like this idea.

[1]: https://lore.kernel.org/lkml/[email protected]/

Kind regards,

Signature · 1 line
Aaron Tomlin