Skip to contentSkip to conversation

rust: firmware: diagnose insufficient modinfo buffer capacity

RFC PATCH New Georgios Androutsopoulos 1 participant 1 message Nov 22

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 rust: firmware: diagnose insufficient modinfo buffer capacity

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.

---
 rust/kernel/firmware.rs | 4 ++++
 1 file changed, 4 insertions(+)
rust/kernel/firmware.rs +4 -0
index a18f8b84f3e3..54c6a13714c5 100644
@@ -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

Signature · 1 line
2.47.3