From patchwork Mon Nov 11 20:54:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13871396 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 BE520D3ABF6 for ; Mon, 11 Nov 2024 21:07:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=AJgd8D/AVhWlbrGW1flI5dRn4oz22+nbWnh+kJUZbHM=; b=W2XJph/5jlOYCk PBXjDPaytNoYQUf+vIuZ2NnhP+g8j8KWOkYUF1WVMhGjA0lguuvbNhitrIGKfLPks2SLY06PDC6jH u9nwpLmFqTZJLFZIq7W10R6JjvY6XOqJTEyzC3UWSRP3ghxzqXL4ie+ilfWgdX2QHYMIRZy/1czQH dVmh8fLktrdwciCsSMGTGOZdGAJOWRtX8ZE50WXBrwk5nfv32E6lUixkZiIohFPKSMw7EQYXnmG8t GhzgPsVxEJW9ShisIgW6NjELWRER6IWTxzmO5hgyn3sqoTI5xjsf2IJWJoj4elcRNbExRH8F9COuI 5Z7Rmr3XhiH9fles+1zQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAbdP-00000001KAK-108f; Mon, 11 Nov 2024 21:07:43 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tAbRC-00000001GOV-1pVe for linux-riscv@lists.infradead.org; Mon, 11 Nov 2024 20:55:08 +0000 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-2e2cc469c62so3569603a91.2 for ; Mon, 11 Nov 2024 12:55:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1731358506; x=1731963306; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=sEpSBMtfQIdn0VsL6AOSyBd/7ZO5cM9GZrrfF6sqPzw=; b=WVwJBYtJpM1Gd2m0tmeWAF40VUrDBVs51BuahcVdIN+0IZT9wpqNMvfnb8yZ+kGC3p kFkq/a9qUkFgtAOBe9FZjcSdA7Np2R7IM05sgfGAS1stZW2VNEbnf1xGfeg4sI/ST8E5 Hp5i6Qj8u9PLq8OVRdCum1CDp2yIJGxyNDvTKJtF4QshQCVxh+oGMsySAe7u67e0ZJZp 5/eu5YbLxTR4Eb5BNHNkXAfHiuOFfvylMhlamvLuaq/8Jpun+qH8/qrx673My/QPtfhZ fRCQwr6h3bZqcgDJxt/yRnKJna8V9J8MrCmB8RswAJmDM4nA2DJe7nMCl+JNV2L9Khsx ZDlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731358506; x=1731963306; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sEpSBMtfQIdn0VsL6AOSyBd/7ZO5cM9GZrrfF6sqPzw=; b=UdRzekLDywxyn58GXo7CzqYvd+6ZsT+4U6yNy4YFzPiwOsBUBaS/v9FPpy3iZZTCgV ttXLub/h+nLTT0FukSV5STyVf5aCEqHSnMUTmC/Isqno9lQXv+Y8TKb5AJ+ZqqB3usC9 Hnhryta9gAvUzcTKK/mdkHIRk2acV4jeF0TXYlBsasbFJetLUPMm8qvmI8ZgIM6sK5oz g1wcx3cc1gPicAIfpZOuQVTKYFtWBbWzSHbuVuor3Ecdkrq0+bEhpkb0RQQA8hFrY7Yt r+W26tK25NAn+wkzhFEHBE1PvG7MuCCwgtGMkpSMCi1Pc0dNKSyF2O4IykYUTczX6cND wZpQ== X-Forwarded-Encrypted: i=1; AJvYcCUFJXYTDPciN2EhWLAbB8krxIsKpnEQFks1FjlbGkYpSI+8tVUScSX07JhTuIJfzV2RKBe7//mnRGZ/oA==@lists.infradead.org X-Gm-Message-State: AOJu0YynieCLVFR0WzYb0iXHA/AiO9VkfUXua0eElNP1OzTMDa6JPReA +5j7sW0amlib9IQ/k3ohKiWFpol9RYFhsWRF0Tq7dxCQDC8iwzHSJOXvXxtZ8ZY= X-Google-Smtp-Source: AGHT+IFzBuraYyYmpM+mIAMFI16Yg/jetlEaju2rqc5UFMlTYdZs+XaMbAKQKjfpaEa7usCG1NdnaQ== X-Received: by 2002:a17:90b:4d11:b0:2e2:b922:48a with SMTP id 98e67ed59e1d1-2e9b173aff9mr21100247a91.18.1731358505869; Mon, 11 Nov 2024 12:55:05 -0800 (PST) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e9a5fd1534sm9059974a91.42.2024.11.11.12.55.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:55:05 -0800 (PST) From: Deepak Gupta Date: Mon, 11 Nov 2024 12:54:11 -0800 Subject: [PATCH v8 26/29] riscv: create a config for shadow stack and landing pad instr support MIME-Version: 1.0 Message-Id: <20241111-v5_user_cfi_series-v8-26-dce14aa30207@rivosinc.com> References: <20241111-v5_user_cfi_series-v8-0-dce14aa30207@rivosinc.com> In-Reply-To: <20241111-v5_user_cfi_series-v8-0-dce14aa30207@rivosinc.com> To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Rob Herring , Krzysztof Kozlowski , Arnd Bergmann , Christian Brauner , Peter Zijlstra , Oleg Nesterov , Eric Biederman , Kees Cook , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, alistair.francis@wdc.com, richard.henderson@linaro.org, jim.shu@sifive.com, andybnac@gmail.com, kito.cheng@sifive.com, charlie@rivosinc.com, atishp@rivosinc.com, evan@rivosinc.com, cleger@rivosinc.com, alexghiti@rivosinc.com, samitolvanen@google.com, broonie@kernel.org, rick.p.edgecombe@intel.com, Deepak Gupta X-Mailer: b4 0.14.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241111_125506_627095_19E878F8 X-CRM114-Status: GOOD ( 11.39 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org This patch creates a config for shadow stack support and landing pad instr support. Shadow stack support and landing instr support can be enabled by selecting `CONFIG_RISCV_USER_CFI`. Selecting `CONFIG_RISCV_USER_CFI` wires up path to enumerate CPU support and if cpu support exists, kernel will support cpu assisted user mode cfi. If CONFIG_RISCV_USER_CFI is selected, select `ARCH_USES_HIGH_VMA_FLAGS`, `ARCH_HAS_USER_SHADOW_STACK` and DYNAMIC_SIGFRAME for riscv. Signed-off-by: Deepak Gupta --- arch/riscv/Kconfig | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 5bdda86ada37..0887a9ae0c20 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -246,6 +246,26 @@ config ARCH_HAS_BROKEN_DWARF5 # https://github.com/llvm/llvm-project/commit/7ffabb61a5569444b5ac9322e22e5471cc5e4a77 depends on LD_IS_LLD && LLD_VERSION < 180000 +config RISCV_USER_CFI + def_bool y + bool "riscv userspace control flow integrity" + depends on 64BIT && $(cc-option,-mabi=lp64 -march=rv64ima_zicfiss) + depends on RISCV_ALTERNATIVE + select ARCH_HAS_USER_SHADOW_STACK + select ARCH_USES_HIGH_VMA_FLAGS + select DYNAMIC_SIGFRAME + help + Provides CPU assisted control flow integrity to userspace tasks. + Control flow integrity is provided by implementing shadow stack for + backward edge and indirect branch tracking for forward edge in program. + Shadow stack protection is a hardware feature that detects function + return address corruption. This helps mitigate ROP attacks. + Indirect branch tracking enforces that all indirect branches must land + on a landing pad instruction else CPU will fault. This mitigates against + JOP / COP attacks. Applications must be enabled to use it, and old user- + space does not get protection "for free". + default y + config ARCH_MMAP_RND_BITS_MIN default 18 if 64BIT default 8