Skip to contentSkip to conversation

rust: bug: pass TAINT_WARN to warn_slowpath_fmt() on UML

PATCH Applied FUJITA Tomonori 3 participants 3 messages Oct 1 – Oct 3

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

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.

Fixes dff64b072708 ("rust: Add warn_on macro")
---
 rust/kernel/bug.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
rust/kernel/bug.rs +2 -1
index 3566f0234ca4..af8eba4563de 100644
@@ -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,
-                $flags as $crate::ffi::c_uint,
+                $crate::bindings::TAINT_WARN,
                 ::core::ptr::null(),
             );
         }

base-commit: 551c722f40809618230001baccf219193e22fc5a

Signature · 1 line
2.43.0
Applied
#1 lore raw
Quoted 11 lines · FUJITA Tomonori

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().

Quoted 5 lines

Pass TAINT_WARN directly, as C does on UML.

Fixes dff64b072708 ("rust: Add warn_on macro")

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

Reviewed-by on v1 1/1
#2 lore raw
In reply to FUJITA Tomonori

Le 01/10/2026 à 20:31, FUJITA Tomonori a écrit :

Quoted 10 lines

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().

Quoted 6 lines

Pass TAINT_WARN directly, as C does on UML.

Fixes dff64b072708 ("rust: Add warn_on macro")

---

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
index 3566f0234ca4..af8eba4563de 100644
@@ -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,
-                $flags as $crate::ffi::c_uint,
+                $crate::bindings::TAINT_WARN,
                  ::core::ptr::null(),
              );
          }

base-commit: 551c722f40809618230001baccf219193e22fc5a