rust: bug: update the SAFETY comment for warn_slowpath_fmt() on UML
Subsystems (3)
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
@@ -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
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. Commit951d09ca450c("rust: bug: passTAINT_WARNtowarn_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.Suggested-by Miguel Ojeda <[email protected]>Signed-off-by FUJITA Tomonori <[email protected]>
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
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
MAINTAINERSif 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.
Miguel Ojeda
AppliedQuoted 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. Commit951d09ca450c("rust: bug: passTAINT_WARNtowarn_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.Suggested-by Miguel Ojeda <[email protected]>Signed-off-by FUJITA Tomonori <[email protected]>
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