From patchwork Tue Oct 1 16:06:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13818432 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7492CCEACE2 for ; Tue, 1 Oct 2024 16:08:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E7DF2800B8; Tue, 1 Oct 2024 12:08:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 097CA280068; Tue, 1 Oct 2024 12:08:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E2DE92800B8; Tue, 1 Oct 2024 12:08:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C4584280068 for ; Tue, 1 Oct 2024 12:08:20 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6C2CB41576 for ; Tue, 1 Oct 2024 16:08:20 +0000 (UTC) X-FDA: 82625515560.27.81CB967 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf06.hostedemail.com (Postfix) with ESMTP id 75AB0180016 for ; Tue, 1 Oct 2024 16:08:18 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=D6ULUSwz; spf=pass (imf06.hostedemail.com: domain of debug@rivosinc.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727798772; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6xdKLFU+R+/xaPo3sKfaOPe5nwRayI/Mj3nw6nC0RbY=; b=ZbRxnSnmrtfq8InD/S7jWzRisxleLA2uJxyQQqu+HjDctBoNnf1vXA/cDZWqO4IusMSp34 5BTO0DjrcE11hYEio26BrtI/sVMIYYd0g/6kgAwD6SMONa2rd8m9vXUFN5bwITLhiHHII+ 6ul6NqW3hECqMRzRadkYC+6SaoJqnFY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727798772; a=rsa-sha256; cv=none; b=HXh298AxnCJUj57GYA71n5XCOuI0bZhkTHOFuHympjUh8z95yLrYT6ZzyjbBGm0IgszMgr kMyMWY9vMuIMl/IybpKVX2MkV0gIMNKA3CpCAgLKiFSyFzsBdDAHdK4TfxaWDBC/cHeCgJ N2aJbsb5cakvlQfwIOI8gstfkur3tzw= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=D6ULUSwz; spf=pass (imf06.hostedemail.com: domain of debug@rivosinc.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2e082f2a427so4337486a91.3 for ; Tue, 01 Oct 2024 09:08:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1727798897; x=1728403697; darn=kvack.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=6xdKLFU+R+/xaPo3sKfaOPe5nwRayI/Mj3nw6nC0RbY=; b=D6ULUSwzP70gQZNCvQd3wUzjNR4oigv7eIHX5TRgnahGLrPHrOgvU9TZr82dZOduas 0Vd22t4rhH9jj+kNODS8B2XpFG8sGWhRF4Ip+io4JwtjCXjHYOg+LpNAiKmgoCH8qvby xGFdrOEB53C/WzlvCc1nCRa68k2w0wN8dXWHm5mA/+hoqHuY14aDtrgzx4CkX0re4E8C amT2Wp+ci1mcvSNHV1wA8oVz5w0hUEUQqIVZCwOx6sqVsJJagwO5vHeNi93ESku1OOHD iiHGfY7/o5kKnw4bEpg9NcxCwtJu000n30MfkCsoR62g9L4ieHNx6Ay5nfY9tVrye8X9 b+yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727798897; x=1728403697; 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=6xdKLFU+R+/xaPo3sKfaOPe5nwRayI/Mj3nw6nC0RbY=; b=sOd9aWKzzVreihR5f/6EwCk4yNR9TB89kps/UgdPKdkXjjvR87WdG7WaG1hXQp+0XD IvS2KGJ6u7a9fhdVu0p34vd6H0hRaXSyC28qOw9vgC/gewDVbRFVCHTRN6MkfMvmtAqF DtUU5DqhBIeVBznh5RRg7GB4xgbe4hStVK/aIot1FHPo+yL92H4xNYWCrlHTyuFVtJ+H ydOKLfRKu3npxSPqj5aIDQvgc6AIJLR7FIf3Sxp8FrK2R7CzciBq/sGM8UJ1viM5Coe7 IeeLUp6m+sc+oX3IhOGBR6hdpv392sRfc14u0ZC72crI4oeRql4oI4tt91PqurkRF0YI lA1Q== X-Forwarded-Encrypted: i=1; AJvYcCWEnHRG7QTG++9ec0H6RQj15DzcY8grcLQ5DxOmFrMFo5JjwO/NPXO2vEKcZ1QJwQwqrpxAEeBDXA==@kvack.org X-Gm-Message-State: AOJu0Yy9GXa2f4X/SeCD2IUWN2AuxLMUnS2EaZuCcNhzGKBcTlyGqak4 hAsR7T8o89bzSdIKmYPmXsCv29YRxNRMTWJk+w4vp+CnDKQstXrCMRQ9IEa93Cs= X-Google-Smtp-Source: AGHT+IGSPOS/rjJlw+fxdYuzivcwlYhVRY55jtXIOD8f6jn9tgzzpKbZ8nfdXLTRzGnEFUMQVR22nA== X-Received: by 2002:a17:90a:f494:b0:2d8:8ead:f013 with SMTP id 98e67ed59e1d1-2e18452dd9emr235870a91.7.1727798897223; Tue, 01 Oct 2024 09:08:17 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 09:08:16 -0700 (PDT) From: Deepak Gupta Date: Tue, 01 Oct 2024 09:06:34 -0700 Subject: [PATCH 29/33] riscv: kernel command line option to opt out of user cfi MIME-Version: 1.0 Message-Id: <20241001-v5_user_cfi_series-v1-29-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-Rspamd-Queue-Id: 75AB0180016 X-Stat-Signature: ant7ditxa84mkumc6kmqfo6cyaj3z4mk X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1727798898-673868 X-HE-Meta: U2FsdGVkX19XufYEXVI8l2FR3TIfIfVyyXgqOEry/nfljgJ20Ep/QVTBXEFdpiKuxDdfX9oWRuBGuWfQh7uwqMBbbC7YdJYiw2IZGVmCK4I/ZDX42Z1zDIOpM1qaRWTjDaaQwPVAfK3ItkDZ7Bn+7UZMNUGFnk/5MHcctGF0Y6PW8RhrLVpiFV76s/JMoOhMuQHS/eJyVVXgqRNBFUQ5MAAGqgXeo9vECOr4yNMy9p63NilN6e5n6gdmZ0TG9EWzoZMgYGN4S3eHUF9SIAXnDvJ1Yncw5bQAfPqtcaBthNzbnCGskQuoDj+EXCZX/E/AoKm0PkZpKfXN5noKVPkonYYQCHw5CgMMUqx/CHHXxMjSaCNuJ3UOnnwXeXFZBbS6I0JAp5/k2iiW5gv82A0CRRVNSxVJtJGvDcBE7DbfQawRmjcby5L/xm1XIgQMZE/lpoKH38b4463nZR7duq49Wk/F4+SkUXQzfB7vAT1fzLfb1cHFAztWvTZK2Jc92zBjpcc5a5UWSIAOUR0327t3CdVR1lqqrZwtKCyjn+VsAUBYfAfH5JjEV0DzSQmvOkRhmgwSu9lhrBjww0jWn7gvrZQEZuos5s2vYEoUEgX3deAJSw4mg9v+4e0q7DuayhcO3ucDCaRTucupGldyprrPHxqgD7IZ/NaqFQ/lsD+uI/TchO0AH9xurtMW59tHWV7Z2uttAHM5egZaEiIGjJK4Ijxcq9sgyLy5/x4auR/L8N/o/eky0omHbkAkX7cwYUvG0QP61RYiyKV8c7hLDWI7kPLJI8QXbss68uxbSthskXQBHYqx19nT2yD+l+n/bhUJOgToekF8N5MjQb7t1GSerU82qZ20CRP0YBzrAycgidzXTh8jL4YXZR8ugjGVulCjqtO2M9pedt/WdITE+dDhEMpWMdEyy7dZqeTpaUJ/g581io44KWz460g1OfYgyn7ITIwL3tJfOrSnn70ATYO G/Q3Ms4p l17mtPpzj3+s0FB/75/0lDH7TjbXmFGVymUKiQUP6pBsd30WCnKeiDFuMmMbXdsX+dD8+QG2H/wjalAw9lorTS5IAGWxKqgJI8Y+ccmUkt7c4/5Jni5kQ4/qKrBLQM7hXqjrcsMoFD4y5rGwoAjr/T96DDEq3c21X8yYQjlUDkedg4qPdzU+DSZoKgfDGB5vYVTzQw+yFt1lbtSz91P2xSyzFlmug0Hy241YzXgzPRsaDsvwt5JDIlQivix9cxZxRnIHLZqmcG6Ii+mX6wqR4bqi4BBl+HVdobcfzpVdf9FNOjDJUrYBKEtfLYS+4UTeHirwyybdxBCT9vQeT8RuuLxyD6Xtq/gwTy9ZtPEkbuw6M/fieBogsat/CihjonRhoq9Orr1q8ICZQod9Kp0M+FSEZVDAlrRxZXotzmy1gatEkfJ2kKfA7pKWNROap3CtNXvUMdx6ihyS785g= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 40c32258b6ec..d92b49261b58 100644 --- a/arch/riscv/kernel/usercfi.c +++ b/arch/riscv/kernel/usercfi.c @@ -17,6 +17,8 @@ #include #include +bool disable_riscv_usercfi; + #define SHSTK_ENTRY_SIZE sizeof(void *) 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 = 0, addr = 0; bool enable_shstk = false; + if (disable_riscv_usercfi) + return 0; + if (!cpu_supports_shadow_stack()) return -EINVAL; @@ -472,6 +477,9 @@ int arch_set_indir_br_lp_status(struct task_struct *t, unsigned long status) { bool enable_indir_lp = false; + if (disable_riscv_usercfi) + return 0; + if (!cpu_supports_indirect_br_lp_instr()) return -EINVAL; @@ -504,3 +512,15 @@ int arch_lock_indir_br_lp_status(struct task_struct *task, return 0; } + +static int __init setup_global_riscv_enable(char *str) +{ + if (strcmp(str, "true") == 0) + disable_riscv_usercfi = true; + + pr_info("Setting riscv usercfi to be %s\n", (disable_riscv_usercfi ? "disabled" : "enabled")); + + return 1; +} + +__setup("disable_riscv_usercfi=", setup_global_riscv_enable);