From patchwork Tue Oct 1 16:06:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13818598 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 4F43BCEACF6 for ; Tue, 1 Oct 2024 17:31:43 +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=UsJ7BQCzYqJmylNub/vXxKYqXY1E77HzCnFNSJhZIjI=; b=kjY9QYe933ESop v5i9AYXcxiJIpT1E45ZU1TOT9ShOyih13+QYQkU2aZ4RApnd1TXrkZE6xAyxl0FblKP7UCz71WT1A zQsUIBNaNSZjEGZYtcZfy6wdRSfYXge9UN4AgqJoZN/BDhSMm8kWnZ45cBm/P8z79Rj481KcUw1dT a/Hr010ldzuDa3s0451Qig7e/rAqjIdebx8tDn4Sq/2V1EsJ2qlNt0fUCAGYJcqqhLarLpLl9uJf7 eBRG+GXc8H7VlxVO/ukQDragKKnJZH/tKH50guIRCDMF65i+uyTrFfcue7DCmYczYxs3pMVpokJtf Ysa6aWUodzVnZwplrmHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1svgip-00000003fDN-0Z9N; Tue, 01 Oct 2024 17:31:39 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1svfQD-00000003RdQ-0nMe for linux-riscv@lists.infradead.org; Tue, 01 Oct 2024 16:08:23 +0000 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-20b90984971so23679085ad.3 for ; Tue, 01 Oct 2024 09:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1727798900; x=1728403700; 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=a4qrRFCNXnOZYa1fD74V0zlcrdQ+HWyEoqE9F8mKpFo=; b=dkjAfzn/QX7lQaDvAC3xdnkwZACjp0OOuXXJBq/tSj+s+DB+j+u24POVxPF9nm7KZ6 HRWW2UmMHLejL0BX4TFoxwiFJEGPL4oqbwDEeiDmKJQ7SNXGkIz4VA2K8caSjxOMSW8V 2/5rZidEiUKvWeytC8k2xd5V3+oj8JGX5lGOa5Tv/vPdMfISlC0OUqyBIVdZz2DLnX2F rrprNOKwvdiw2QDNzydmX08e+qwp36SBTOSHqyTaZcEy9ayyiwUyFNHT6ac853bKMg1r 5iCh+RaHs9ui/4R6fc2yy4IYKzdir88xsSdD8VNis7cBipKGPssbz7m1/LKR+bGydmyq xxfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727798900; x=1728403700; 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=a4qrRFCNXnOZYa1fD74V0zlcrdQ+HWyEoqE9F8mKpFo=; b=X6S21hmqonJ08YcN2cLgWkUSlD1DhVPvV7tNENBpRuzId7ADzy9wNcPeX+q+WO4hj2 m3Q3D/q4wACQ+A3gxa8YtmzKJ4K3myD97uX4YyPDAg50Ynu0e/B1XnZtqj3sU0bcRVlX wNrPxYL9aNYqawVPEdtlIQ3n/WxErkbpJXd7gplu4NEU39MnpPdR4TaLu7M0u45RqD5n +0kkR+Rbiz3OVvuzFyEGSziPk9X3wxXrgUrHEvGTZO0Bed/eR1pYFAUbNGFHRUTBM/Ya lq2U/6Rp6zq7R6yZassh9Bw3of+h5umIskQmeE5Qmjegq0AewX27nkbPWTWt0lAu0wIg +ybw== X-Forwarded-Encrypted: i=1; AJvYcCXkSTo694AnGsOPpQWbeMGkqizGg8RbsLKlX1HQgbJvdUuhrwGXtOHDcGsqr5VFVrLcJEFVQ6FvQivjNw==@lists.infradead.org X-Gm-Message-State: AOJu0Yy/lpPGBeHm51Z9aRBT4nVAa+SvUrgBSOKl3x3a3UAt3/Pt6Nwb AuOI+3iVpIi57AgKJJqhr2Zc/QTs/9p5ADfGrLBH8qrFm2j2gHpzzFbd2lVCy4I= X-Google-Smtp-Source: AGHT+IGiAxXYx6yXeYkA/G/la8C9nBfo7vSN2Z7fy96K3UGQ0W+8BbkIQQBBecsOmRmnWw0/cNAzkw== X-Received: by 2002:a17:90b:3543:b0:2d8:8175:38c9 with SMTP id 98e67ed59e1d1-2e184804fc6mr237651a91.20.1727798899815; Tue, 01 Oct 2024 09:08:19 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e06e1d7d47sm13843973a91.28.2024.10.01.09.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 09:08:19 -0700 (PDT) From: Deepak Gupta Date: Tue, 01 Oct 2024 09:06:35 -0700 Subject: [PATCH 30/33] riscv: create a config for shadow stack and landing pad instr support MIME-Version: 1.0 Message-Id: <20241001-v5_user_cfi_series-v1-30-3ba65b6e550f@rivosinc.com> References: <20241001-v5_user_cfi_series-v1-0-3ba65b6e550f@rivosinc.com> In-Reply-To: <20241001-v5_user_cfi_series-v1-0-3ba65b6e550f@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-20241001_090821_360584_F1FA5768 X-CRM114-Status: GOOD ( 11.65 ) 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` and `ARCH_HAS_USER_SHADOW_STACK` for riscv. Signed-off-by: Deepak Gupta --- arch/riscv/Kconfig | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 808ea66b9537..d0cc2879fcd4 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -245,6 +245,25 @@ 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 + 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