From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0592D16F84A for ; Tue, 6 Aug 2024 20:28:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722976088; cv=none; b=PaA5CBSMyXvI1snsGbOcGhNS2uES/AXxKnJwDv/EoW6QC03/cLMvw52v2IOuLBruV8SNdS8BwBeK60gcBaFf7RuKgHLMmZ51uUX5GdBUQE1qLymILf5gxKdPEWjME7clWO6grGC7EoiPm+nTlrNCBUlRMcZz3Hn+rKKHANTiE0k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722976088; c=relaxed/simple; bh=PIqwq05eeSJrJAxwn95ybQWvhk0Dn6GFtbODZZoaYKg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nqeBGjQP6TwKXWuwBoacFCHBh9RQIeeTJUCrgdSlVansXZrBkSvj80ISA/Q3X574E2cWuYK15z0q4GWhKDVAAGKrxn8yMnqKKLMJMQ9h3l34DauUyp4AKd26mgpndmAJdvkye17FJUIYHsI2Xso/DeBwJ47LOzVN0UwW8ppu5wo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=cIxwze3f; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="cIxwze3f" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-710afa8d1dfso826681b3a.3 for ; Tue, 06 Aug 2024 13:28:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722976086; x=1723580886; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=YNJJxbMCTacBJYMokN6YIRV7m5EBShQyXf92BOxMYb0=; b=cIxwze3fhA0NLN5oMfEGkw+Y+xhu0TRfWOc2qTlDrGupWGFLzfyL/DX+6f9XCXLVcJ 1Cms9JgteDFeN046O9vit8bsnW0a4LwamURs0iyyoEPod2HTK6gHhQ/wYeHxJprNBkRd jDMk6BkyJJAHoYYzcC5peFdhjQaFFSQTd6o+t1XlhKW4F2ooJriHHtBsZcWGGqs4Buo+ yKWxa3wu6u20VydzceJhdt9fBbCGCrwap5PesKkuUB2WHaFmgx4wftLMjM8u32DR1Fkq Tw21bG/IjN0hQJes5NBLNous4M3X4HC74mhalNQhzfzyTvcxVoKQLA4dp4vF+6cU1YGI eLbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722976086; x=1723580886; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=YNJJxbMCTacBJYMokN6YIRV7m5EBShQyXf92BOxMYb0=; b=tmlQXLoYW5aP1ztaEs9R8Oq2SocpKT2gdz6Hb5dpOXYw+C5xfkD55wTwQHQx4Pqvxm p0PmSDskn+k+/9fktdESBbeoZiw1d3vN5b7dCwR3au5BBGxgqHVcqOyE0W0HrnimIoyW 4LaBLQv4qtAPWT6l0Rv5e5UiUX5v79YBps5MLM7fh1YU4L7kTVXjRfoY0N+pRM7FONC0 qGwv/s7oYbmlWLaiiQWqWZjn+6B6kdYrrRtiYssySypE5sZ7LUkDcQRnPijSvznhNJhd yqpNNiKNRTflwl9kTyzugbOrcjbFExV3lLDARxUre3y0LLiN036KC8ncinbBbT/6/+CN ZK8w== X-Forwarded-Encrypted: i=1; AJvYcCUoBJEmfaUeRM1GGqifnHINKtWEWbV3nQbPZsGyffnS63y6QavkPeHFFDjoDtEm9T/dpmi+IF0c5wCpEIC6mTPXhidlSEqzoDvpferrG3Q= X-Gm-Message-State: AOJu0YyiTrU+4AnOgqCRMEUyT2wwS9nKfM63gxJDzBtqsgucw31zebvo Gew5Oa2kR0R1I/eOQAcEuCea3LCprSqG1+cRXoeOMaCR3iPcJ7BjvjGy5v2lig== X-Google-Smtp-Source: AGHT+IFm9uhPYUcX6BBhhu0nbe6Hn1ROfYd6y3IS8Wi4xqj74fV2681KS5TuBgKc0cmX3bLcvOgaPQ== X-Received: by 2002:a05:6a20:b910:b0:1c6:b364:dbd1 with SMTP id adf61e73a8af0-1c6b364e170mr7596007637.19.1722976085743; Tue, 06 Aug 2024 13:28:05 -0700 (PDT) Received: from google.com ([2620:0:1000:2510:6419:5b4c:3008:6065]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7b763562989sm7403878a12.34.2024.08.06.13.28.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 13:28:05 -0700 (PDT) Date: Tue, 6 Aug 2024 13:27:58 -0700 From: Sami Tolvanen To: Alice Ryhl Cc: Catalin Marinas , Will Deacon , Jamie Cunliffe , Nathan Chancellor , Conor Dooley , Masahiro Yamada , Nicolas Schier , Ard Biesheuvel , 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, Kees Cook Subject: Re: [PATCH v5] rust: support for shadow call stack sanitizer Message-ID: <20240806202758.GA1634260@google.com> References: <20240806-shadow-call-stack-v5-1-26dccb829154@google.com> Precedence: bulk X-Mailing-List: rust-for-linux@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 Looks good to me, thanks! Reviewed-by: Sami Tolvanen Sami