rust: print: avoid evaluating arguments in `pr_*` macros in `unsafe` blocks
authorMiguel Ojeda <ojeda@kernel.org>
Tue, 13 Dec 2022 18:03:55 +0000 (19:03 +0100)
committerMiguel Ojeda <ojeda@kernel.org>
Sun, 15 Jan 2023 23:54:35 +0000 (00:54 +0100)
commit6618d69aa129a8fc613e64775d5019524c6f231b
treeeb85b88e3ab361b8b7e534bbc1941d3ef4d79d7a
parent5dc4c995db9eb45f6373a956eb1f69460e69e6d4
rust: print: avoid evaluating arguments in `pr_*` macros in `unsafe` blocks

At the moment it is possible to perform unsafe operations in
the arguments of `pr_*` macros since they are evaluated inside
an `unsafe` block:

    let x = &10u32 as *const u32;
    pr_info!("{}", *x);

In other words, this is a soundness issue.

Fix it so that it requires an explicit `unsafe` block.

Reported-by: Wedson Almeida Filho <wedsonaf@gmail.com>
Reported-by: Domen Puncer Kugler <domen.puncerkugler@nccgroup.com>
Link: https://github.com/Rust-for-Linux/linux/issues/479
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Björn Roy Baron <bjorn3_gh@protonmail.com>
Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
rust/kernel/print.rs