[RFC PATCH] rust: firmware: diagnose insufficient modinfo buffer capacity

From: Georgios Androutsopoulos

Date: Sun Nov 22 2026 - 11:56:48 EST


`ModInfoBuilder::push_internal()` tracks the required length even when
the buffer is too small, but `push_module_name()` can still index past
its end. During const evaluation, this reports an out-of-bounds index
rather than the capacity constraint.

Check the capacity explicitly with `build_error!` so the failure
reports the violated constraint.

Link: https://github.com/Rust-for-Linux/linux/issues/1271
Signed-off-by: Georgios Androutsopoulos <georgeandrout13@xxxxxxxxx>
---
rust/kernel/firmware.rs | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/rust/kernel/firmware.rs b/rust/kernel/firmware.rs
index a18f8b84f3e3..54c6a13714c5 100644
--- a/rust/kernel/firmware.rs
+++ b/rust/kernel/firmware.rs
@@ -339,6 +339,10 @@ const fn push_module_name(self) -> Self {
this = this.push_internal(module_name.to_bytes_with_nul());

if N != 0 {
+ if this.n > N {
+ crate::build_error!("Modinfo buffer too small for module name.");
+ }
+
// Re-use the space taken by the NULL terminator and swap it with the '.' separator.
this.buf[this.n - 1] = b'.';
}

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
2.47.3