From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B07B01547DE; Tue, 6 Aug 2024 19:37:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722973058; cv=none; b=oA1C0XOBhwP6K0nOFGVcMQSLuAgsmERIbHwA20ifYT1rzgwhuUEbXJdKuPCpxWfph4y/9kfctv5+5kqD+3roUR1g4m5WRiU6YwC8c+4cmEGMEcI+cHOyISSMl2wegypnUddDLmAb9XRbkLvBk9AYQWUu/svgKYju/mpA2R97Rs8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722973058; c=relaxed/simple; bh=e35vjbhMOBQ7+JlS9DJB1T/+6MrsmRSF0dBpuKz6rv0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DxfbQTJGe739NLRrChilnHYRClOjU4DA61es6JEu8uJIdC6AfjlmbHKJD6wFdUaHuJ2/YgGum8xGyBL3aY57uOzGcDCX7D9HvGzLyq0qAfHPP1ClGmKl+Ke/jyi1twUhduG75GYk5LpxFerfh4aF8RzXrB2bi4p9snl6AhDzd2c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nmkIqn3E; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nmkIqn3E" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 470CEC32786; Tue, 6 Aug 2024 19:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722973058; bh=e35vjbhMOBQ7+JlS9DJB1T/+6MrsmRSF0dBpuKz6rv0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nmkIqn3EpcMc8L4EHnk1TELdWqSEC3z+uHowUc0kL+mxAwN/zSmr8lnK0i/9VGCN6 lSJXwLxXeuc0Goxl+fmeikJW7rLzn/rsCIqPLXaSiecU7LxzqM0qgsP9VUPnGvYb69 e8EM9A+j3etbdlye8tzL/FiVPyO+GYyPOw0Caij4n7Mzqk9aVwPUASf4t6M/pV2FLQ r1pCH5kHfDLg/inmgBi7397YWnIIvrLdUBew6sNrmIHZwPo8u7VPwrJoX24YG1Racu KPgALQuVkiP/7qrQb8PowXWdJKOPkRHVE3Lashh9oPxppuDFyaQSz5kKZf+/jRI/K4 XDBXBZJfqJUBg== Date: Tue, 6 Aug 2024 12:37:37 -0700 From: Kees Cook To: Alice Ryhl , Ard Biesheuvel Cc: Catalin Marinas , Will Deacon , Jamie Cunliffe , Sami Tolvanen , Nathan Chancellor , Conor Dooley , Masahiro Yamada , Nicolas Schier , Marc Zyngier , Mark Rutland , Mark Brown , Nick Desaulniers , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Benno Lossin , Andreas Hindborg , Valentin Obst , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, rust-for-linux@vger.kernel.org Subject: Re: [PATCH v5] rust: support for shadow call stack sanitizer Message-ID: <202408061237.17199E80AC@keescook> References: <20240806-shadow-call-stack-v5-1-26dccb829154@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240806-shadow-call-stack-v5-1-26dccb829154@google.com> On Tue, Aug 06, 2024 at 10:01:44AM +0000, Alice Ryhl wrote: > This patch adds all of the flags that are needed to support the shadow > call stack (SCS) sanitizer with Rust, and updates Kconfig to allow > configurations that work. > > The -Zfixed-x18 flag is required to use SCS on arm64, and requires rustc > version 1.80.0 or greater. This restriction is reflected in Kconfig. > > When CONFIG_DYNAMIC_SCS is enabled, the build will be configured to > include unwind tables in the build artifacts. Dynamic SCS uses the > unwind tables at boot to find all places that need to be patched. The > -Cforce-unwind-tables=y flag ensures that unwind tables are available > for Rust code. > > In non-dynamic mode, the -Zsanitizer=shadow-call-stack flag is what > enables the SCS sanitizer. > > At the time of writing, all released rustc versions up to and including > 1.81 incorrectly think that the Rust targets aarch64-unknown-none and > riscv64-unknown-none-elf don't support -Zsanitizer=shadow-call-stack, so > the build will fail if you enable shadow call stack in non-dynamic mode. > See [1] for the relevant feature request. To avoid this compilation > failure, Kconfig is set up to reject such configurations. > > Note that because these configurations are rejected, this patch only > allows SCS to be used with arm64 and not on riscv. However, once [1] is > implemented, I will submit a follow-up patch that allows configurations > without UNWIND_PATCH_PAC_INTO_SCS on sufficiently new compilers. That > patch will implicitly allow SCS to be enabled on riscv, but this is okay > because unlike arm64, riscv does not need any flags for rustc beyond > -Zsanitizer=shadow-call-stack. > > It is possible to avoid the requirement of rustc 1.80.0 by using > -Ctarget-feature=+reserve-x18 instead of -Zfixed-x18. However, this flag > emits a warning during the build, so this patch does not add support for > using it and instead requires 1.80.0 or greater. > > The `depends on` clause is placed on `config RUST` to avoid a situation > where enabling Rust silently turns off the sanitizer. Instead, turning > on the sanitizer results in Rust being disabled. We generally do not > want changes to CONFIG_RUST to result in any mitigations being changed > or turned off. > > Link: https://github.com/rust-lang/rust/issues/121972 [1] > Signed-off-by: Alice Ryhl I'd like to make sure Ard is happy with this, but from what I can see it looks correct. Thanks! Reviewed-by: Kees Cook -- Kees Cook