lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 2 Aug 2023 19:26:05 +0100
From:   Gary Guo <gary@...yguo.net>
To:     Miguel Ojeda <ojeda@...nel.org>
Cc:     Wedson Almeida Filho <wedsonaf@...il.com>,
        Alex Gaynor <alex.gaynor@...il.com>,
        Boqun Feng <boqun.feng@...il.com>,
        Björn Roy Baron <bjorn3_gh@...tonmail.com>,
        Benno Lossin <benno.lossin@...ton.me>,
        Alice Ryhl <aliceryhl@...gle.com>,
        Andreas Hindborg <a.hindborg@...sung.com>,
        rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
        patches@...ts.linux.dev
Subject: Re: [PATCH 2/2] rust: enable `no_mangle_with_rust_abi` Clippy lint

On Sun, 30 Jul 2023 00:03:17 +0200
Miguel Ojeda <ojeda@...nel.org> wrote:

> Introduced in Rust 1.69.0 [1], this lint prevents forgetting to set
> the C ABI when using `#[no_mangle]` (or thinking it is implied).
> 
> For instance, it would have prevented the issue [2] fixed by commit
> c682e4c37d2b ("rust: kernel: Mark rust_fmt_argument as extern "C"").
> 
>     error: `#[no_mangle]` set on a function with the default (`Rust`) ABI
>       --> rust/kernel/print.rs:21:1  
>        |
>     21 | / unsafe fn rust_fmt_argument(
>     22 | |     buf: *mut c_char,
>     23 | |     end: *mut c_char,
>     24 | |     ptr: *const c_void,
>     25 | | ) -> *mut c_char {
>        | |________________^
>        |
>        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#no_mangle_with_rust_abi
>        = note: requested on the command line with `-D clippy::no-mangle-with-rust-abi`
>     help: set an ABI
>        |
>     21 | unsafe extern "C" fn rust_fmt_argument(
>        |        ++++++++++
>     help: or explicitly set the default
>        |
>     21 | unsafe extern "Rust" fn rust_fmt_argument(
>        |        +++++++++++++
> 
> Thus enable it.
> 
> In rare cases, we may need to use the Rust ABI even with `#[no_mangle]`
> (e.g. one case, before 1.71.0, would have been the `__rust_*`
> functions). In those cases, we would need to `#[allow(...)]` the lint,
> since using `extern "Rust"` explicitly (as the compiler suggests)
> currently gets overwritten by `rustfmt` [3].
> 
> Link: https://github.com/rust-lang/rust-clippy/issues/10347 [1]
> Link: https://github.com/Rust-for-Linux/linux/pull/967 [2]
> Link: https://github.com/rust-lang/rustfmt/issues/5701 [3]
> Signed-off-by: Miguel Ojeda <ojeda@...nel.org>

Reviewed-by: Gary Guo <gary@...yguo.net>

> ---
>  Makefile | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/Makefile b/Makefile
> index 658ec2b8aa74..93bf3eca3ead 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -467,6 +467,7 @@ export rust_common_flags := --edition=2021 \
>  			    -Dclippy::let_unit_value -Dclippy::mut_mut \
>  			    -Dclippy::needless_bitwise_bool \
>  			    -Dclippy::needless_continue \
> +			    -Dclippy::no_mangle_with_rust_abi \
>  			    -Wclippy::dbg_macro
>  
>  KBUILD_HOSTCFLAGS   := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ