From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFDCCC433FE for ; Mon, 7 Nov 2022 18:05:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232539AbiKGSFM (ORCPT ); Mon, 7 Nov 2022 13:05:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233026AbiKGSEt (ORCPT ); Mon, 7 Nov 2022 13:04:49 -0500 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9AD224F26; Mon, 7 Nov 2022 10:00:43 -0800 (PST) Received: from zn.tnic (p200300ea9733e71f329c23fffea6a903.dip0.t-ipconnect.de [IPv6:2003:ea:9733:e71f:329c:23ff:fea6:a903]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 49F851EC059D; Mon, 7 Nov 2022 19:00:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1667844042; h=from:from: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:in-reply-to:in-reply-to: references:references; bh=UkSYnjmUQupdoESl0cYE22dAydPPeLNDAdR5Iz0pnhU=; b=bXNIbKBf++r6UJZ1YxkMPFeTEsnxN+C6+C+eLrtUPptX7sJ1W2m3VuISpp81WPCK4PTYdm mK9DduVUBLvg9bqJuQ6msgSIq572Li4j8FEI7OJElPzWdein5uvqIVmWrwPB6EpjLMZqtf Xphdp9jPHy+GLhx1wExdY8rJG2XIe+E= Date: Mon, 7 Nov 2022 19:00:37 +0100 From: Borislav Petkov To: Rick Edgecombe Cc: x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V . Shankar" , Weijiang Yang , "Kirill A . Shutemov" , John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Yu-cheng Yu Subject: Re: [PATCH v3 04/37] x86/cpufeatures: Enable CET CR4 bit for shadow stack Message-ID: References: <20221104223604.29615-1-rick.p.edgecombe@intel.com> <20221104223604.29615-5-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20221104223604.29615-5-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 04, 2022 at 03:35:31PM -0700, Rick Edgecombe wrote: > static __always_inline void setup_cet(struct cpuinfo_x86 *c) > { > - u64 msr = CET_ENDBR_EN; > + bool kernel_ibt = HAS_KERNEL_IBT && cpu_feature_enabled(X86_FEATURE_IBT); > + bool user_shstk; > + u64 msr = 0; > > - if (!HAS_KERNEL_IBT || > - !cpu_feature_enabled(X86_FEATURE_IBT)) > + /* > + * Enable user shadow stack only if the Linux defined user shadow stack > + * cap was not cleared by command line. > + */ > + user_shstk = cpu_feature_enabled(X86_FEATURE_SHSTK) && > + IS_ENABLED(CONFIG_X86_USER_SHADOW_STACK) && > + !test_bit(X86_FEATURE_USER_SHSTK, (unsigned long *)cpu_caps_cleared); Huh, why poke at cpu_caps_cleared? Look below: > + if (!kernel_ibt && !user_shstk) > return; > > + if (user_shstk) > + set_cpu_cap(c, X86_FEATURE_USER_SHSTK); > + > + if (kernel_ibt) > + msr = CET_ENDBR_EN; > + > wrmsrl(MSR_IA32_S_CET, msr); > cr4_set_bits(X86_CR4_CET); > > - if (!ibt_selftest()) { > + if (kernel_ibt && !ibt_selftest()) { > pr_err("IBT selftest: Failed!\n"); > setup_clear_cpu_cap(X86_FEATURE_IBT); > return; > } > } > +#else /* CONFIG_X86_CET */ > +static inline void setup_cet(struct cpuinfo_x86 *c) {} > +#endif > > __noendbr void cet_disable(void) > { > - if (cpu_feature_enabled(X86_FEATURE_IBT)) > - wrmsrl(MSR_IA32_S_CET, 0); > + if (!(cpu_feature_enabled(X86_FEATURE_IBT) || > + cpu_feature_enabled(X86_FEATURE_SHSTK))) > + return; > + > + wrmsrl(MSR_IA32_S_CET, 0); > + wrmsrl(MSR_IA32_U_CET, 0); Here you need to do setup_clear_cpu_cap(X86_FEATURE_IBT); setup_clear_cpu_cap(X86_FEATURE_SHSTK); and then the cpu_feature_enabled() test above alone should suffice. But, before you do that, I'd like to ask you to update your patchset ontop of tip/master because the conflicts are getting non-trivial. This one doesn't even want to apply with a large fuzz: $ patch -p1 --dry-run -F20 -i /tmp/new checking file arch/x86/kernel/cpu/common.c Hunk #1 FAILED at 596. 1 out of 1 hunk FAILED Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette