rust: bug: pass TAINT_WARN to warn_slowpath_fmt() on UML
Subsystems (4)
PATCH 1/1 rust: bug: pass TAINT_WARN to warn_slowpath_fmt() on UML
From: FUJITA Tomonori <[email protected]>
On UML, warn_flags! calls warn_slowpath_fmt() directly. Its third argument is a taint number, but warn_on! passes its bug flags there.
As a result, add_taint() gets 2304 instead of 9 (TAINT_WARN). The warning is not recorded: /proc/sys/kernel/tainted stays 0 after warn_on! fires, where it should be 512. It also causes an out-of-bounds write in add_taint().
Pass TAINT_WARN directly, as C does on UML.
--- rust/kernel/bug.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
rust/kernel/bug.rs +2 -1
@@ -85,6 +85,7 @@ macro_rules! warn_flags { ($file:expr, $flags:expr) => {if false { _ = $file; + _ = $flags; }// SAFETY: It is always safe to call `warn_slowpath_fmt()`
@@ -93,7 +94,7 @@ macro_rules! warn_flags { $crate::bindings::warn_slowpath_fmt ( $crate::str::CStrExt ::as_char_ptr ($crate::c_str!(::core::file!())),line! ()as $crate::ffi::c_int , - $flagsas $crate::ffi::c_uint , + $crate::bindings::TAINT_WARN , ::core::ptr::null (), ); }
base-commit: 551c722f40809618230001baccf219193e22fc5a
Signature · 1 line
2.43.0
Miguel Ojeda
AppliedQuoted 11 lines · FUJITA Tomonori
From: FUJITA Tomonori <[email protected]>
On UML,
warn_flags!callswarn_slowpath_fmt()directly. Its third argument is a taint number, butwarn_on!passes its bug flags there.As a result,
add_taint()gets 2304 instead of 9 (TAINT_WARN). The warning is not recorded:/proc/sys/kernel/taintedstays 0 afterwarn_on!fires, where it should be 512. It also causes an out-of-bounds write inadd_taint().
Quoted 5 lines
Pass
TAINT_WARNdirectly, as C does on UML.Fixes dff64b072708 ("rust: Add warn_on macro")Signed-off-by FUJITA Tomonori <[email protected]>
Applied to rust-next -- thanks!
We should update the // SAFETY: It is always safe to call warn_slowpath_fmt() ...` comment to cover everything that may go wrong (like it did).
Cheers,
Miguel
Le 01/10/2026 à 20:31, FUJITA Tomonori a écrit :
Quoted 10 lines
From: FUJITA Tomonori <[email protected]>
On UML,
warn_flags!callswarn_slowpath_fmt()directly. Its third argument is a taint number, butwarn_on!passes its bug flags there.As a result,
add_taint()gets 2304 instead of 9 (TAINT_WARN). The warning is not recorded:/proc/sys/kernel/taintedstays 0 afterwarn_on!fires, where it should be 512. It also causes an out-of-bounds write inadd_taint().
Quoted 6 lines
Pass
TAINT_WARNdirectly, as C does on UML.Fixes dff64b072708 ("rust: Add warn_on macro")Signed-off-by FUJITA Tomonori <[email protected]>---
Nice catch!
Cheers,
-- David
Quoted 26 lines
rust/kernel/bug.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)rust/kernel/bug.rs +2
-1@@ -85,6 +85,7 @@ macro_rules! warn_flags { ($file:expr, $flags:expr) => {if false { _ = $file; + _ = $flags; }// SAFETY: It is always safe to call `warn_slowpath_fmt()` @@ -93,7 +94,7 @@ macro_rules! warn_flags { $crate::bindings::warn_slowpath_fmt ( $crate::str::CStrExt ::as_char_ptr ($crate::c_str!(::core::file!())),line! ()as $crate::ffi::c_int , - $flagsas $crate::ffi::c_uint , + $crate::bindings::TAINT_WARN , ::core::ptr::null (), ); }base-commit:
551c722f40809618230001baccf219193e22fc5a