From nobody Mon Nov 25 06:42:01 2024 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 9FBBE215F74 for ; Tue, 29 Oct 2024 23:45:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730245533; cv=none; b=Y9gSNJAxsWcUiQ/x3xz3YMXl8/kUhw1ZbqhiSlW9j4yhSY3YWuKVJ1P3QIgb6yQsCKtAZ8GsK6AwBCuwzUk8ytntzRFDmnPsoawdWu4QHDM1OzXpyLXuKERaSyZ3N5GC1PtlYXNO2lI1w3Ak+vJwCaFOsS+lUN+obzJsJdTQNbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730245533; c=relaxed/simple; bh=QFCIa0+ds5blWBrVVV38UJRLoxk2ifalHQaaXLuF2k8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U1jHiGnvWHIcMqMkx9qA7dKidN6AdRES3MYzn+Z36g5ufrkATtwwTsRuKeW3VdyolGN1bU6+4+lcI4g3Bjj02k1eQMyBb4pPrO0kN7HCw2LxHp/L6y7spBVSqQTEPbtqTKuQFYDMjtKZavXcEAqTiijK5yC4FPIRcL/6S0G3tFI= 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=i/Jsk4EX; arc=none smtp.client-ip=209.85.215.172 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 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="i/Jsk4EX" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7edb3f93369so3917323a12.1 for ; Tue, 29 Oct 2024 16:45:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1730245530; x=1730850330; darn=vger.kernel.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=nRy4y69JgL5sB6geChrc5T0OHtDNFkvTlVG645IsDrc=; b=i/Jsk4EXs6ShwyZIcT5BV6f6uaCeb5OxGMMYxaGpIqYxKej6D2VJPvdDWnWTFxyJMr 2RQy8C4WuMfPji3MA8h9xGOIGxnQjKmslc7w7m2ky12QoXnNKH01qxgbcch7ZEOGXYoK 2mKV2HyUhgwX0o0gYxunPrm4PRdLAJygJOg6ug024Jq1BimpgF9yhuUGuq4T1VhairQE nZBLRjQluiJ6e+8rJTWH0W6f13FVlH3U3C+hKXvTX7LkBhuCnpyjoV8YrW8vH7vejTWI LKGA66hHPJSgrX0+1CRwV9ou6K0YamN7DUhW+iZZk6AIKa2O8Bi7VzhO5XppW+5/04Bg oXXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730245530; x=1730850330; 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=nRy4y69JgL5sB6geChrc5T0OHtDNFkvTlVG645IsDrc=; b=mXIVeysK+yBrEq1sLl4YqbL7x7U56Cd7dM07T9wpGWSmoDyfAZvh+8I3RNOtDoSyTg 2b5UqKkbM1nwE+pBWpR15kuWB1/TtR6HvYQPbI3yWaGLnfBMHw0gl9M+Rb1DiTtDQmE3 8LYHpJtLxPusCNExjdoWIZpY848wYxIGmgzPEvXpbsmVzA8KMHo5NEi1BiMz26eb4nKm aOcLNQP83ORT1tDZ+m8LpkYUnmnBOpmKlVttGjJeMdOU5qY4LuqtBEMjOJXyFeAYVHZ+ Jb5GsoU4H9tdDJQO9D1U1ZXHy7qyifh8J/hVwWphM6p5KfhsBozzYuEqn8DEm1wGEp9O yqZA== X-Gm-Message-State: AOJu0YwZiQUv2QbutbOmPtJFxMUk9Sr0RvodnTl52uHsQxjvgdEDLQue RoNaC7pVmcjYpFGJOi6oDudfpPPBSkEj1XcePCw7uC8Na4AYnR6TDePD1l4bHCc= X-Google-Smtp-Source: AGHT+IEJnoB5pjGPkuu5fVIOqNL3hz9Y12W/UY6bmoQpgc9NgKdtyZXYcI4NaGAWLxyKkPpDfpG9Xg== X-Received: by 2002:a05:6a20:e198:b0:1d6:fd8c:fa16 with SMTP id adf61e73a8af0-1d9a850541dmr17895816637.46.1730245530007; Tue, 29 Oct 2024 16:45:30 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72057921863sm8157643b3a.33.2024.10.29.16.45.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 16:45:29 -0700 (PDT) From: Deepak Gupta Date: Tue, 29 Oct 2024 16:44:28 -0700 Subject: [PATCH v7 28/32] riscv: kernel command line option to opt out of user cfi Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241029-v5_user_cfi_series-v7-28-2727ce9936cb@rivosinc.com> References: <20241029-v5_user_cfi_series-v7-0-2727ce9936cb@rivosinc.com> In-Reply-To: <20241029-v5_user_cfi_series-v7-0-2727ce9936cb@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 This commit adds a kernel command line option using which user cfi can be disabled. Signed-off-by: Deepak Gupta --- arch/riscv/kernel/usercfi.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/riscv/kernel/usercfi.c b/arch/riscv/kernel/usercfi.c index 04b0305943b1..223dfa482deb 100644 --- a/arch/riscv/kernel/usercfi.c +++ b/arch/riscv/kernel/usercfi.c @@ -17,6 +17,8 @@ #include #include =20 +bool disable_riscv_usercfi; + #define SHSTK_ENTRY_SIZE sizeof(void *) =20 bool is_shstk_enabled(struct task_struct *task) @@ -393,6 +395,9 @@ int arch_set_shadow_stack_status(struct task_struct *t,= unsigned long status) unsigned long size =3D 0, addr =3D 0; bool enable_shstk =3D false; =20 + if (disable_riscv_usercfi) + return 0; + if (!cpu_supports_shadow_stack()) return -EINVAL; =20 @@ -472,6 +477,9 @@ int arch_set_indir_br_lp_status(struct task_struct *t, = unsigned long status) { bool enable_indir_lp =3D false; =20 + if (disable_riscv_usercfi) + return 0; + if (!cpu_supports_indirect_br_lp_instr()) return -EINVAL; =20 @@ -504,3 +512,15 @@ int arch_lock_indir_br_lp_status(struct task_struct *t= ask, =20 return 0; } + +static int __init setup_global_riscv_enable(char *str) +{ + if (strcmp(str, "true") =3D=3D 0) + disable_riscv_usercfi =3D true; + + pr_info("Setting riscv usercfi to be %s\n", (disable_riscv_usercfi ? "dis= abled" : "enabled")); + + return 1; +} + +__setup("disable_riscv_usercfi=3D", setup_global_riscv_enable); --=20 2.34.1