From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 52D53C52D6F for ; Tue, 6 Aug 2024 19:38:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SjlDnh0swK584Qex+gLJLL+Kwijc9PdP2M0FzYphZns=; b=QUr3X5XUE3vT9iKdejolJ9Vm4m e/SocBw8LIkBioPMaZIft+KdmVSniw4muabyH6CUfwPhzNlOxOhzhDfQ2ntkJro5zMgymKQjO3HHC kO43xzgJj6CVoecTfXIIteglqtuy7N1ub9ZyJvBMdFBby6bFWxGu9FnHw5rgsYEHpva7ispQEgRRW cq0D3tzE9zQPdXdmctPRRw0L1GjbaUr8M++odmhbZYsnyIxB5BPEriARaeR1LKfcYgEgfmevwaq1U B/WbNLIHVcyn1Bq4urB0xBJX3WeClRk/gAAsLkWPH31bHPvkx3uqr+iA+MYNSEf1zy8wvIWkCAHdu 7RFypg6A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbQ0b-00000002iuK-3PD9; Tue, 06 Aug 2024 19:38:14 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbQ03-00000002imG-1v1N for linux-arm-kernel@lists.infradead.org; Tue, 06 Aug 2024 19:37:41 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9C10660FB5; Tue, 6 Aug 2024 19:37:38 +0000 (UTC) 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> 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240806_123739_754419_3DED654D X-CRM114-Status: GOOD ( 29.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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