From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 E66E234F46A for ; Thu, 16 Oct 2025 15:31:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760628675; cv=none; b=pY99OfukOoLzwUoDBGXW9q9l0XR+QEs425DczL0+A85wzw8v/k4vCiuX5W/ydLsGPNM4YAf+RR9EDN0sy9p8h+EogQJMCHmeRO24Gl6MyTSi1Cwm+rAGHj8EBR4p8kiUncoUghZibkin40WVdPl+h45Bh20p2jvg2qBunadBcNc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760628675; c=relaxed/simple; bh=9p3Gr4qeRbg0Ysh2iAnD1VpHOA3SkA6SHTG6Wu71gKQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ksmlg76COdC3+CTO6s6GiJWtghg1VILFjCh3+4lJHPY/sZ3T2PUTpZXw0ElXDW8n0rzxWtNc9kLn2qh4VQVE/fNCsHxaIU2sSNqCUn90OhvgzXdtdRADRFWl0/NC76tt0wNOjkWdP4ll4zQJtTQy/cBiBzgvxS00FhFbQ4OlxKI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc.com header.i=@rivosinc.com header.b=doPubc3P; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc.com header.i=@rivosinc.com header.b="doPubc3P" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-28e7cd34047so8558665ad.2 for ; Thu, 16 Oct 2025 08:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc.com; s=google; t=1760628671; x=1761233471; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=oPplYqAzpwU4gxjQp2Rw6jkCzCOQWdHbasm8KJuRgKg=; b=doPubc3P+gZ+HV7IYjMGh6lGx9ouANOyuXU4B+3+4MAHmWEyWU77V475Dyc9hub6Q6 snrFK1pfy0QH0ZJfrksGyE/R51FzqaCxy+nN9v5ZVxoRWeiGBkGzHsQkkgRKC8oRGs6A Qc4XHh7LpCelOZyfpQFDtzZyfPNzoG7Xxq/MEbhVrfOGCMVpO3ALWzGG8KEXiZ0gTd2U kXz5LAeozLbwfJ0qMLwrbxobgJ90xnwvoyp+T3GYAK7Q1A1ZNxveNu/2UBljDFB+2H9T hEOfqN2+6TlM6U39FORldh72GZE0OMZnNbyPJlJ28O1jqgCYMcvLbG1m8zRdqkaXZYSZ fP6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760628671; x=1761233471; h=in-reply-to:content-transfer-encoding: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=oPplYqAzpwU4gxjQp2Rw6jkCzCOQWdHbasm8KJuRgKg=; b=WI1ElgLhm6NdMie4aFdB3mLqqEfZ90/IwMB5xe7eGBvaHMeFmNcIgK43sekN3XOMUk zo6sqkPCOdAM9X9DNe3HkjE2Ay/AKyUvv5DpuoNVo9VJ5j8yf/FKp4w9kW/DHWzLfGp2 /AkBpq1DEk35LCwzh9REY/YQaJgn2D9exoRGJAxstkI5zEsTGuzZ8lEtWbGdYucNxYn1 i1zFEf79+tOWjpRCapPcDInFN84VPnDGiyKepLPmjfj5sSzBc4dt2MVbqmi4MWiTGccg kERdARRIKWxC9dusiuX2VjK1LzHsFnaMdhmhbIdp9RXVnmRMlKXR770n+5jPEdHk8/Wj d+Kw== X-Forwarded-Encrypted: i=1; AJvYcCXhFbIN4+e9x9mh8yocGmy0SDuh+is21DZ3Bkk4xmQ63DqD77r2R+iOulaEMhj6FYXD/4nDXTPHto3tq/54TQ==@vger.kernel.org X-Gm-Message-State: AOJu0YxzWMBwN6Y8IlxhNyH43MZOdxXvgdF9GbvZHao+XneOuAKauCwe HlP+r00juUioBzT38z6Vs84yPxG2QUzMMkfQzmSP6132xCzo9VA2GO8z8DU5hvymaWE= X-Gm-Gg: ASbGncudK2kPFzc9ncC0DkF9ZQERzlYqM+NaNLZ3ogNLvwdK7HOc9gcIgyrIz+CWDLE LV40qicZ3TyTfZ9rq2iFE3JP38LoI1MR1e2K7gNmhVwqxjtNhNfXJ6xmiXjLR7y0TbSDrcccNNt oDandVHeURcmBZoSSg6wvz+Iu648fuglCtFsd1u08s98qQbq+5nEGJGEAorMwZ/2Q4Rv11HtgJ9 NDRvbgga9xWiJtsY+faDIy3iZuUEm8msfpVCfjbHJM2SpmbRVmTL9RILTo8zPfKAjNU5PpYSsEq TfCye8ieF7YyT45z9EqwVhzUPHLlZnrPKGLyyziqzIoAwGa9AV2Kn0coFQwYsYPzX38iqgsYAl8 U9SohlRUAnBUXaoRXOL1tLbYPEWwFgljDCGGugs1u+wPjIZbKrwP2nDNnxmSl++pwcHC+37SINw TelxTsJTU6Sg== X-Google-Smtp-Source: AGHT+IHwQKe9LAMk6ozD/GRZ/4wHAc2uQ93fezPeXjgomM0kYDp4EL0uCq03NAVcolelP7TLwPE5CA== X-Received: by 2002:a17:902:db0b:b0:24c:d6c6:c656 with SMTP id d9443c01a7336-290c9c8a84bmr4369005ad.4.1760628671090; Thu, 16 Oct 2025 08:31:11 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29099343065sm34122695ad.26.2025.10.16.08.31.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Oct 2025 08:31:10 -0700 (PDT) Date: Thu, 16 Oct 2025 08:31:07 -0700 From: Deepak Gupta To: Zong Li Cc: 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 , Jann Horn , Conor Dooley , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Andreas Hindborg , Alice Ryhl , Trevor Gross , Benno Lossin , 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, rust-for-linux@vger.kernel.org Subject: Re: [PATCH v21 25/28] riscv: create a config for shadow stack and landing pad instr support Message-ID: References: <20251015-v5_user_cfi_series-v21-0-6a07856e90e7@rivosinc.com> <20251015-v5_user_cfi_series-v21-25-6a07856e90e7@rivosinc.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=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Oct 16, 2025 at 04:29:48PM +0800, Zong Li wrote: >On Thu, Oct 16, 2025 at 2:14 AM Deepak Gupta wrote: >> >> 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. >> >> Reviewed-by: Zong Li >> Signed-off-by: Deepak Gupta >> --- >> arch/riscv/Kconfig | 21 +++++++++++++++++++++ >> arch/riscv/configs/hardening.config | 4 ++++ >> 2 files changed, 25 insertions(+) >> >> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig >> index 0c6038dc5dfd..aed033e2b526 100644 >> --- a/arch/riscv/Kconfig >> +++ b/arch/riscv/Kconfig >> @@ -1146,6 +1146,27 @@ config RANDOMIZE_BASE >> >> If unsure, say N. >> >> +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 RISCV_SBI >> + 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 n. > >Maybe it is default 'y' instead of 'n' aah yes, this needs to change. thanks. I'll see if there are other significant issues, if yes then I'll fix it in that version. Else I request Paul to fix it. > >> + >> endmenu # "Kernel features" >> >> menu "Boot options" >> diff --git a/arch/riscv/configs/hardening.config b/arch/riscv/configs/hardening.config >> new file mode 100644 >> index 000000000000..089f4cee82f4 >> --- /dev/null >> +++ b/arch/riscv/configs/hardening.config >> @@ -0,0 +1,4 @@ >> +# RISCV specific kernel hardening options >> + >> +# Enable control flow integrity support for usermode. >> +CONFIG_RISCV_USER_CFI=y >> >> -- >> 2.43.0 >>