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]
Message-ID: <CF7780EE-D42B-4D79-BA8E-666D6E0E2A9D@kloenk.dev>
Date: Thu, 04 Jul 2024 17:07:33 +0200
From: Finn Behrens <me@...enk.dev>
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>,
 Gary Guo <gary@...yguo.net>,
 Björn Roy Baron <bjorn3_gh@...tonmail.com>,
 Benno Lossin <benno.lossin@...ton.me>,
 Andreas Hindborg <a.hindborg@...sung.com>, Alice Ryhl <aliceryhl@...gle.com>,
 rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
 patches@...ts.linux.dev, Masahiro Yamada <masahiroy@...nel.org>,
 Nathan Chancellor <nathan@...nel.org>, Nicolas Schier <nicolas@...sle.eu>,
 Andrew Morton <akpm@...ux-foundation.org>, linux-kbuild@...r.kernel.org
Subject: Re: [PATCH 12/13] rust: support the new `-Zub-checks` flag



On 1 Jul 2024, at 20:36, Miguel Ojeda wrote:

> Rust 1.79.0 has introduced a new codegen flag, `-Zub-checks` [1], to
> allow to independently configure (from `-Cdebug-assertions`) whether the
> extra runtime checks for UB are emitted, in a similar fashion to
> `-Coverflow-checks`.
>
> This allows to configure the kernel with only the UB checks enabled,
> but not the `debug_assert!`s; or vice versa, e.g. [2].
>
> It also showcases how `RUSTC_VERSION` and the Kbuild macros, introduced
> in the previous commit, can be used.
>
> Link: https://github.com/rust-lang/compiler-team/issues/725 [1]
> Link: https://godbolt.org/z/jY69ezx5K [2]
> Signed-off-by: Miguel Ojeda <ojeda@...nel.org>

Reviewed-by: Finn Behrens <me@...enk.dev>

> ---
>  Makefile          |  9 +++++++--
>  lib/Kconfig.debug | 18 ++++++++++++++++++
>  2 files changed, 25 insertions(+), 2 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 3f43f03f855e..c0cb5c237c26 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -820,10 +820,15 @@ KBUILD_CFLAGS += -Os
>  KBUILD_RUSTFLAGS += -Copt-level=s
>  endif
>
> -# Always set `debug-assertions` and `overflow-checks` because their default
> -# depends on `opt-level` and `debug-assertions`, respectively.
> +# Always set `debug-assertions` because its default depends on `opt-level`.
>  KBUILD_RUSTFLAGS += -Cdebug-assertions=$(if $(CONFIG_RUST_DEBUG_ASSERTIONS),y,n)
> +
> +# Always set `overflow-checks` and `ub-checks` because their default depends on
> +# `debug-assertions`.
>  KBUILD_RUSTFLAGS += -Coverflow-checks=$(if $(CONFIG_RUST_OVERFLOW_CHECKS),y,n)
> +ifeq ($(call rustc-min-version, 107900),y)
> +KBUILD_RUSTFLAGS += -Zub-checks=$(if $(CONFIG_RUST_UNDEFINED_BEHAVIOR_CHECKS),y,n)
> +endif
>
>  # Tell gcc to never replace conditional load with a non-conditional one
>  ifdef CONFIG_CC_IS_GCC
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index 59b6765d86b8..6b4f512f9e13 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -3020,6 +3020,24 @@ config RUST_OVERFLOW_CHECKS
>
>  	  If unsure, say Y.
>
> +config RUST_UNDEFINED_BEHAVIOR_CHECKS
> +	bool "Undefined Behavior checks"
> +	depends on RUST && RUSTC_VERSION >= 107900
> +	help
> +	  Enables rustc's `-Zub-checks` codegen option.
> +
> +	  This flag allows you to control whether additional runtime checks that
> +	  detect some causes of Undefined Behavior at runtime will be emitted.
> +	  When enabled, a Rust panic will occur if UB is detected.
> +
> +	  All checks are generated on a best-effort basis; even if there is a check
> +	  implemented for some cause of Undefined Behavior, it may be possible for
> +	  the check to not fire.
> +
> +	  Note that this will apply to all Rust code, including `core`.
> +
> +	  If unsure, say N.
> +
>  config RUST_BUILD_ASSERT_ALLOW
>  	bool "Allow unoptimized build-time assertions"
>  	depends on RUST
> -- 
> 2.45.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ