Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp3037482lqz; Wed, 3 Apr 2024 16:50:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWBCFziEfl/PToy/T+s3oKo+yM+XwAmv4e29zhFlqXs1ky1E1FAteYDyMkGeLvrPr7yRCmNzqb6oXHVnUHhZeEs/W7yjy+uC+Gt80/l9A== X-Google-Smtp-Source: AGHT+IGO+2bglDGm/s3Nf0EaJksaL6T16zMcXK+77QZDaKGqDBVnCXk6bKygz49132l7Gv6oqJOT X-Received: by 2002:a9d:7310:0:b0:6e9:e442:1584 with SMTP id e16-20020a9d7310000000b006e9e4421584mr670191otk.33.1712188217801; Wed, 03 Apr 2024 16:50:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712188217; cv=pass; d=google.com; s=arc-20160816; b=KSGnW8IemJyWkXODqBf5JjWaxLESgbXvcZEUUGKogp0+VhoBdoe1A6BFp1DtudmVgZ 5PT+3hiDQ321HN3WYeP1UZ8ZCY36bU0UQQKAvGkEWEizGQBnmLUlopJ6df/lXzSjirQ7 sBZyW/DuixgGVNDiIbQYy4BIjAQ47bOCdklyfYVwsNBFNQM3D2uECFgtc+VzJ96oX9SF qtyePs0ndJ9rneEG1jXSTgez+5ZFvRQuscFZJatCIFSzImi0gVuE9f8kGPGGd84KvubS D9bicxMD6q9tIcsAK1x4k9r7JSjiUWFIvtnHXbKtnwLKQbPcHBXUvJuUWP9q3+I5iTf2 huiQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9DtlDgd/GAT0EKcB2AjZTXvg/KwB3A8UKH6yER0NyfA=; fh=FW7WtF1zDgxso5jM0BG7GWqj+rOlbFp1Je/pXYmzCFY=; b=e0ptmZ/NEu9QgeO4YzDtLVL3rSkn+GC1/2+CgIqvyE7MlktPCm8ptrAJUVajg9x2+T GY3ewgxObrTKVroo71kEHf/E1C1T3/rXYn9V6pTk+DjuBRX874WaToZ2YECgZtrgGJ9n /hVQdyj7HW+j2GQjxAFJnESwZV6+EQWv+SzKIjSkpa+FkGs8ZmMjmCC6TFjg8AyxqHQ4 6ThDcsm9XCvwHuIuoRNLDwYBG3j+005FwsFiJcLwaf8uHgCMdeiwUAgCSHBH49Iws72D G0kNh6KVKI3EvaC79bqGkSENa48l9aAyA9gWE+Q5LewsuiOR/vXfmvTWmu+oPvfWoIzS +RCQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=YwMx341w; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-130745-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130745-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o16-20020a637e50000000b005e83f49a85csi14287772pgn.527.2024.04.03.16.50.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 16:50:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-130745-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=YwMx341w; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-130745-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-130745-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8018028CC96 for ; Wed, 3 Apr 2024 23:49:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6BA0815E5C3; Wed, 3 Apr 2024 23:42:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="YwMx341w" 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 0A9BB15D5D8 for ; Wed, 3 Apr 2024 23:42:47 +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=1712187769; cv=none; b=BzlTtnte0sgKfLy6e7irN/XJsuRVdg1acysvMY0XMhHo9wLyzSHTllJL87916mMefPU+WQ2+iLD7zezqA8QGDoks4Te0jjYwFAMusjr8tSqKLRVfKcz+yjQ/vgRc4x9EZrdPNK+zIq46TOccmr23QxsuiSeRVnlOwlCm36M8zNk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712187769; c=relaxed/simple; bh=gRUEuRotPJjUi2hlrSXSLGRWOK9UqoUEje/IwX9OQE8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JdImd1FUk/uLRR4AYFVeEnxdf6wD6F0zNtLSjNYZxB5ZIJfnB9mmnr87ByN2DV5F9KyjpPS0uFq4VY43sCksXiyoQbiOz78RyLU4G5H9e6qyX6qpuYZqTgMApqU4s+epJHKmVym7Dt6RNnHlaFTiwxQ7k8VeqJfLCt7j1AbEaaU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=YwMx341w; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6e6c0098328so333600b3a.3 for ; Wed, 03 Apr 2024 16:42:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712187767; x=1712792567; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9DtlDgd/GAT0EKcB2AjZTXvg/KwB3A8UKH6yER0NyfA=; b=YwMx341wx/Wa3bsWUkv9/0EdOfHv8Zq9ZoouLn4DtRxapcnfryBzyRZhRVoBURgbWS XdAshDMADFJ7tkrqy1N8EtdmuEX29biH/cLgfTucRcQhBz9waC5NrkvyVyrzaPh7H2D8 ByrFBZQNk5w6tb1vI/Qw+BGzOrsF78WB0TzEfxO5IGKCzZrab7nPj9pRwBpMAqjeeeRT c4TYMLHVGPQKu0ZC+lO3XzbSVWAJPSshnE0J1yXcFtO5FdtVkGvlpuYGOIIAKJsQOzRP fRrGblFel1Cb2FBLr7xCOCUPXlMUGd0NaN1ribZ2jbmjzfiQJuWzX3g3qVcmaBZISzk1 8f1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712187767; x=1712792567; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9DtlDgd/GAT0EKcB2AjZTXvg/KwB3A8UKH6yER0NyfA=; b=f4xIpC+lA/X9e1Mxckz69bYOPHZlWKD2MmSENA0V6vpJksq7A9z66dg/nFTu9szP6e +EVyODnxeTHpEHGXv0hemUZAnve5r3MKYEup0f/iZ1P/vj0XFa56/XpGIRxIvoBp1Svj y0DRAEUR7Tr5hlo7J60/sbP+VlHJ62Fj+VmczLPygOgfuXVzMuNvuA4ntu59jZnJoIzv 5hL6426o4pnHMslzqivkJbJwPQaoqElJP+TPazuRcgsJep0yuRfLA2xKkqwMBgGAdWWu Y/5zx6noRka973DIMnTqhXn5pZ9DuI2l//LBpe0bpaJLcp2aGue0DFKJTNs6gHynoHEQ VioA== X-Forwarded-Encrypted: i=1; AJvYcCUw/OxiwtUtCO+1dJ+ZxAdXrvaOM1EYImmkfJh0ST4ObrWy+/odkht9TWikbAe2jKiz8jZai3wtng+qp5l2hwXgPLU6Wt4rHqym5wxa X-Gm-Message-State: AOJu0YyVDOQGQFuO7iARwgQWbSUsX9Cu6n9dsLxJBPunoWWMencGENG2 stv6JVeaDtE0SYoTcg1k3MpecXOIZaIVy/R54+jrxCpWZW8NeJkJRAu6V/c7Ek8= X-Received: by 2002:a05:6a20:7285:b0:1a7:2437:3d58 with SMTP id o5-20020a056a20728500b001a724373d58mr1369671pzk.13.1712187767375; Wed, 03 Apr 2024 16:42:47 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id b18-20020a170902d51200b001deeac592absm13899117plg.180.2024.04.03.16.42.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 16:42:47 -0700 (PDT) From: Deepak Gupta To: paul.walmsley@sifive.com, rick.p.edgecombe@intel.com, broonie@kernel.org, Szabolcs.Nagy@arm.com, kito.cheng@sifive.com, keescook@chromium.org, ajones@ventanamicro.com, conor.dooley@microchip.com, cleger@rivosinc.com, atishp@atishpatra.org, alex@ghiti.fr, bjorn@rivosinc.com, alexghiti@rivosinc.com, samuel.holland@sifive.com, conor@kernel.org Cc: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, corbet@lwn.net, palmer@dabbelt.com, aou@eecs.berkeley.edu, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, oleg@redhat.com, akpm@linux-foundation.org, arnd@arndb.de, ebiederm@xmission.com, Liam.Howlett@oracle.com, vbabka@suse.cz, lstoakes@gmail.com, shuah@kernel.org, brauner@kernel.org, debug@rivosinc.com, andy.chiu@sifive.com, jerry.shih@sifive.com, hankuan.chen@sifive.com, greentime.hu@sifive.com, evan@rivosinc.com, xiao.w.wang@intel.com, charlie@rivosinc.com, apatel@ventanamicro.com, mchitale@ventanamicro.com, dbarboza@ventanamicro.com, sameo@rivosinc.com, shikemeng@huaweicloud.com, willy@infradead.org, vincent.chen@sifive.com, guoren@kernel.org, samitolvanen@google.com, songshuaishuai@tinylab.org, gerg@kernel.org, heiko@sntech.de, bhe@redhat.com, jeeheng.sia@starfivetech.com, cyy@cyyself.name, maskray@google.com, ancientmodern4@gmail.com, mathis.salmen@matsal.de, cuiyunhui@bytedance.com, bgray@linux.ibm.com, mpe@ellerman.id.au, baruch@tkos.co.il, alx@kernel.org, david@redhat.com, catalin.marinas@arm.com, revest@chromium.org, josh@joshtriplett.org, shr@devkernel.io, deller@gmx.de, omosnace@redhat.com, ojeda@kernel.org, jhubbard@nvidia.com Subject: [PATCH v3 26/29] riscv: create a config for shadow stack and landing pad instr support Date: Wed, 3 Apr 2024 16:35:14 -0700 Message-ID: <20240403234054.2020347-27-debug@rivosinc.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240403234054.2020347-1-debug@rivosinc.com> References: <20240403234054.2020347-1-debug@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Signed-off-by: Deepak Gupta --- arch/riscv/Kconfig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 7e0b2bcc388f..d6f1303ef660 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -203,6 +203,24 @@ 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_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 -- 2.43.2