Skip to contentSkip to conversation

rust: bug: update the SAFETY comment for warn_slowpath_fmt() on UML

PATCH Applied FUJITA Tomonori 2 participants 4 messages Oct 2 – Oct 12

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

PATCH 1/1 rust: bug: update the SAFETY comment for warn_slowpath_fmt() on UML

From: FUJITA Tomonori <[email protected]>

The SAFETY comment says that it is always safe to call warn_slowpath_fmt() with a valid null-terminated string. This is not true. The taint argument must also be a valid taint number. Commit 951d09ca450c ("rust: bug: pass TAINT_WARN to warn_slowpath_fmt() on UML") fixed a bug where it was not.

List each condition that the call meets: the file name, the taint number, and the null fmt.

---
 rust/kernel/bug.rs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
rust/kernel/bug.rs +4 -2
index 6abed2c055b1..3b40b0bd37b5 100644
@@ -88,8 +88,10 @@ macro_rules! warn_flags {
             _ = $flags;
         }
 
-        // SAFETY: It is always safe to call `warn_slowpath_fmt()`
-        // with a valid null-terminated string.
+        // SAFETY:
+        // - The file name is a null-terminated string with `'static` lifetime.
+        // - `TAINT_WARN` is a valid taint number.
+        // - `fmt` can be NULL, and NULL is passed.
         unsafe {
             $crate::bindings::warn_slowpath_fmt(
                 $crate::str::CStrExt::as_char_ptr($crate::c_str!(::core::file!())),

base-commit: 948440b3f429f84680db58b4bf529b1ed2a20e15

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

The SAFETY comment says that it is always safe to call warn_slowpath_fmt() with a valid null-terminated string. This is not true. The taint argument must also be a valid taint number. Commit 951d09ca450c ("rust: bug: pass TAINT_WARN to warn_slowpath_fmt() on UML") fixed a bug where it was not.

Quoted 5 lines

List each condition that the call meets: the file name, the taint number, and the null fmt.

Thanks Tomo!

(By the way, you have been authoring all the work in this file -- we could have an entry for the file in MAINTAINERS if you want it)

Cheers,
Miguel

#2 lore raw
Quoted 2 lines · On Fri, 2 Oct 2026 12:54:47 +0200 Miguel Ojeda…

(By the way, you have been authoring all the work in this file -- we could have an entry for the file in MAINTAINERS if you want it)

Thanks, let's add one. It would make sure that I am Cc'd on changes to the file. I'll send a patch to update MAINTAINERS.

Applied
#3 lore raw
In reply to FUJITA Tomonori
Quoted 9 lines · FUJITA Tomonori

From: FUJITA Tomonori <[email protected]>

The SAFETY comment says that it is always safe to call warn_slowpath_fmt() with a valid null-terminated string. This is not true. The taint argument must also be a valid taint number. Commit 951d09ca450c ("rust: bug: pass TAINT_WARN to warn_slowpath_fmt() on UML") fixed a bug where it was not.

Quoted 5 lines

List each condition that the call meets: the file name, the taint number, and the null fmt.

Applied to rust-next -- thanks!

I added:

    Cc: [email protected]
    Fixes: dff64b072708 ("rust: Add warn_on macro")

so that this goes together with the other one that actually fixes the issue. It is not really a user-facing fix, but it seems to me that it makes sense to put them together and to avoid a de-sync in the comment.

Cheers,
Miguel