From patchwork Mon Nov 11 20:54:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13871395 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 DDA65D3ABF6 for ; Mon, 11 Nov 2024 21:07:39 +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=tMlsvWpG6tsWe8/RBS/99SCLy1PaNcb8uPhn3yNGdWk=; b=4S7IXo45ttTMRf PRSN88fAldziPe8cR3Sd5SYC81XzJHFlc5pwNiplGfeYPPXMCO78/pKoOOBXQhBD0f+Rrc81i4dzt gAb52XMGv1qStPvsBpIc46TzEqWvzaeb36fFGWTlHAE5Dx1wbdWCRLRfb5uwYarZ/mIJaA//Xh8An p1+aRBIGQratmtwl/KxcxurWUUUu6V5VPbi2QrfKJgdDlfQiIUk0bzKAZWfjbH4hD+03TtWeve2zn FAvokiZEvWb1HuaD1k11ttieMvRdPhLsa2rrxyOyr4yPBaDfjiNvj/wtZ3Z+xlEDVXSEr2dkXWAOo bVZX0k7K+aT/xz4cXcdQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tAbdD-00000001K12-26On; Mon, 11 Nov 2024 21:07:31 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tAbR9-00000001GMO-3Psv for linux-riscv@lists.infradead.org; Mon, 11 Nov 2024 20:55:06 +0000 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-2e34a089cd3so4001493a91.3 for ; Mon, 11 Nov 2024 12:55:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1731358503; x=1731963303; 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=v87E2FN7teOOU1wWTBhK9gVAN0VjVVh/KdbYNd+fh68=; b=F7+0HJ5wY89lnzfC4FndKAQkaEDnz9JgEeLUbl2FE7I/0jRIn/2yTuS94zRdmraRIy 479+HCaCod41w5m3+DsytUFlOK0ZgVKDx9ZP7Yi1XrGJjnzJADZZnC0TfKOLTFIUWsb6 IQpe5xVLsAj3sF8VCmWD6twSRglriaBLwOtUmQss2K19esn87pv6Cnroc0zfZTce+F3y RpE3xdcO1mnQB9JYgNpUy29b5RGETNo71rkhYwhgeNQfOn7aR/iSb/0zvX1CB+fP+nlB LZ4NQD8mLe+Zg1b3GnnuA1gej3vyOyhjFbd7FsGK/EJFnKkXa+y7vTX+2xdH8wiIJ/XG /wWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731358503; x=1731963303; 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=v87E2FN7teOOU1wWTBhK9gVAN0VjVVh/KdbYNd+fh68=; b=qn8HIhOtygRFSUfF3cjqyQK3LJhWOQVwb6BY27jtBcPlIcsbSgcJl2Lk9ZWf1et07m 4oyozZ0x2rIRmw07BnHwvWZtPRPjPN2SjbBB881YqumJQBZXs84Huz/86HfbprB1hMBl HNJENx9574zWZvIPhgPdPA4woxtA5ojMGEYXIgKA9v5EWfM47pq8pvM2+C4iiPuJK7mO TZxD4ujFV8yGT9DseSyRHUJQVdxXa30vI1onGJCDA6Lo1/M0Vc0tmx6FPc5IkPee07Xp Wjba5iGFSjEnHVq8kSkF9zbQvAFNv5HYavAFAXpCS/hd2YpaN1OROWGqLi+WAhtdz+tF xYJg== X-Forwarded-Encrypted: i=1; AJvYcCUTbhdIcNr5RuW3MZEgrMvpeU0Nux4KcQ2/HegZydOqJlnt85V7C2BQNP+Kkpz4m/IzIlxQqEOZZ9s7Iw==@lists.infradead.org X-Gm-Message-State: AOJu0YxXYb7zfvRVrZx24Sair+AlKKjiqnQBbohxfWWv3iriPNfrKqaX FxJZNiWVGRtwbb4BhAc7bzNen9y4nWH6Voe1S75orMcl9ZH7ED4WcJNrz7kjx5I= X-Google-Smtp-Source: AGHT+IE6pHU7K0D6Kovlo0iT4mPH8p4N2kcP8nKM47bgfKvZsvt7nFC76OWezD1by9y3vt8KBs+5Mg== X-Received: by 2002:a17:90b:1a92:b0:2e2:cd22:b092 with SMTP id 98e67ed59e1d1-2e9b171f93amr20303584a91.16.1731358503151; Mon, 11 Nov 2024 12:55:03 -0800 (PST) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e9a5fd1534sm9059974a91.42.2024.11.11.12.55.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:55:02 -0800 (PST) From: Deepak Gupta Date: Mon, 11 Nov 2024 12:54:10 -0800 Subject: [PATCH v8 25/29] riscv: kernel command line option to opt out of user cfi MIME-Version: 1.0 Message-Id: <20241111-v5_user_cfi_series-v8-25-dce14aa30207@rivosinc.com> References: <20241111-v5_user_cfi_series-v8-0-dce14aa30207@rivosinc.com> In-Reply-To: <20241111-v5_user_cfi_series-v8-0-dce14aa30207@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-20241111_125503_927765_8166F2E2 X-CRM114-Status: GOOD ( 13.00 ) 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 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 +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);