Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3216152rwb; Mon, 3 Oct 2022 11:20:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6YwvcP2LwdEqYWiBy07xIw9z/7827JrWdRzKY4bBk+1ret/8z8GOel6EGg7kJ3AqzMU6+g X-Received: by 2002:a05:6a00:1ace:b0:546:94a3:b235 with SMTP id f14-20020a056a001ace00b0054694a3b235mr24109237pfv.50.1664821230288; Mon, 03 Oct 2022 11:20:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664821230; cv=none; d=google.com; s=arc-20160816; b=pU8hTH3dIU1I6i9BbRFrEHyLPX0V5ql26Ie1xR9BtAmGV9zShZUQ/TAiVcPyo8EIG0 Ddinjcs6rtozVsu4FOgDGkd+mjUINAZswcZyv6RERVNSpZ/+BfPjQZwGQ9+tRvmklyHK s6a34Gk+5V7mkIau1iESCCofNkCwRi3qQ+Nq7+CsQk7AEhqnvhXsl57gVgLRKAoFLME6 hkH4psNXGpGC+GZzMUgrboTyf3vDPYGgdGGoZhLiSU8nWGKYugnzQtmaW/5eBN0If6UJ K9iZ5WO/BPPPKOeMm18Z4JKXfp4n+GqdA9YfbyIw9rUobn33y1D0XvvvkGZufngpkXKB aDKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/dv15tDc2ktB7BAbAEqIaqb+HPgnCrw6tzjaeXZYRdw=; b=x863dImywDLLIX1oTp0krlXmc01ELCyVKG/tbCZdYBD21EguZ88lstjQo8dM/MTVTy 9x5i8tT6BBRXC2wzSAT33DaPamTFADmta3rkckHLBdl7CH/7+hPT2EvV59JgTCdywaPC dHkAhmJCKVgMpv+CKxDPKcPvxRd57ZmBzJcUSlWxrVHR3WYTAwz+fKJuchxdJp6kCBuV mJ7pfiESbjEqDcghdZws2Xh0HJnEvFo7Cudynnfs0ZEXEfbY27NOq07Njx91d86mN8s9 tcMNymgA6G4Xx4v0q2IaocnfdIwIUp4jDeBJANVjgyyseDfqxU9cJDwfs7xbBJ7LEMfK GbKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Luxyct5Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j11-20020a62e90b000000b00543851d000bsi10079381pfh.253.2022.10.03.11.20.18; Mon, 03 Oct 2022 11:20:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Luxyct5Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229950AbiJCSEr (ORCPT + 99 others); Mon, 3 Oct 2022 14:04:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229794AbiJCSEc (ORCPT ); Mon, 3 Oct 2022 14:04:32 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C1B52F654 for ; Mon, 3 Oct 2022 11:04:29 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id 70so10539069pjo.4 for ; Mon, 03 Oct 2022 11:04:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=/dv15tDc2ktB7BAbAEqIaqb+HPgnCrw6tzjaeXZYRdw=; b=Luxyct5ZDEAf+s4tZkbPi5QWvqscJMmjQmwgPzdkwonol+VoRlsiuiHoPDe6z649HT GdmX3uXicFJo82Sjaz8mQCGFSRAQfkLCvV3r9epbDHNd85DICH2NOHamMJ/YfINRznXm RCqqekGfOD/I6JxvPfwxxVlkhxNGcYPH6wMo8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=/dv15tDc2ktB7BAbAEqIaqb+HPgnCrw6tzjaeXZYRdw=; b=mo+6+6F+vFoNJCUEM+rywHG+3USzUdO3rLPiLQMEulkE0qvpduMZS7hU7NY9hTdS4N zR3I/qOQu0B3Ie3VOFT24SLADc0lcfX39XaAZVFhEQEqBZ2PIfi61GmsaaPqvuZmX5H+ jU/S1QknZrwdz6HioIxLw9EcxzzGFtWRc54M/gAGNiFSa4xL+3lnzlhZqDy5ZZIxr7BG zGe3Ph2U5AN0bKSrTslAoo0TWaGQW55fN8IEBtgWQLrf3L+XPzdJjIfA9UyCSV647u0R Iamq2J9sx/866g4v76QYIfS+1efh9pNhY8YOTzCnMXzui6v2uprdJ047g/misV0VuwZv syng== X-Gm-Message-State: ACrzQf0p3KiPNuSxeNajviO+JOKQWwXOUs07WI+x9Cie8z5j2vYm4+dO p8DCVdarh4c1Nt1kcPilRcuicA== X-Received: by 2002:a17:90b:1a81:b0:20a:71e5:728d with SMTP id ng1-20020a17090b1a8100b0020a71e5728dmr12719181pjb.107.1664820269511; Mon, 03 Oct 2022 11:04:29 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id g8-20020a17090a4b0800b0020a61d0e4eesm5470654pjh.30.2022.10.03.11.04.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 11:04:28 -0700 (PDT) Date: Mon, 3 Oct 2022 11:04:27 -0700 From: Kees Cook 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 , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jann Horn , Jonathan Corbet , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V . Shankar" , Weijiang Yang , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, Yu-cheng Yu , Michael Kerrisk Subject: Re: [PATCH v2 07/39] x86/cet: Add user control-protection fault handler Message-ID: <202210031055.62E60F6BBE@keescook> References: <20220929222936.14584-1-rick.p.edgecombe@intel.com> <20220929222936.14584-8-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220929222936.14584-8-rick.p.edgecombe@intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 29, 2022 at 03:29:04PM -0700, Rick Edgecombe wrote: > [...] > -#ifdef CONFIG_X86_KERNEL_IBT > +#if defined(CONFIG_X86_KERNEL_IBT) || defined(CONFIG_X86_SHADOW_STACK) This pattern is repeated several times. Perhaps there needs to be a CONFIG_X86_CET to make this more readable? Really just a style question. diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index b68eb75887b8..6cb52616e0cf 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1836,6 +1836,11 @@ config CC_HAS_IBT (CC_IS_CLANG && CLANG_VERSION >= 140000)) && \ $(as-instr,endbr64) +config X86_CET + def_bool n + help + CET features are enabled (IBT and/or Shadow Stack) + config X86_KERNEL_IBT prompt "Indirect Branch Tracking" bool @@ -1843,6 +1848,7 @@ config X86_KERNEL_IBT # https://github.com/llvm/llvm-project/commit/9d7001eba9c4cb311e03cd8cdc231f9e579f2d0f depends on !LD_IS_LLD || LLD_VERSION >= 140000 select OBJTOOL + select X86_CET help Build the kernel with support for Indirect Branch Tracking, a hardware support course-grain forward-edge Control Flow Integrity @@ -1945,6 +1951,7 @@ config X86_SHADOW_STACK def_bool n depends on ARCH_HAS_SHADOW_STACK select ARCH_USES_HIGH_VMA_FLAGS + select X86_CET help Shadow Stack protection is a hardware feature that detects function return address corruption. Today the kernel's support is limited to > [...] > +#if defined(CONFIG_X86_KERNEL_IBT) || defined(CONFIG_X86_SHADOW_STACK) > +DEFINE_IDTENTRY_ERRORCODE(exc_control_protection) > +{ > + if (!cpu_feature_enabled(X86_FEATURE_IBT) && > + !cpu_feature_enabled(X86_FEATURE_SHSTK)) { > + pr_err("Unexpected #CP\n"); > + BUG(); > + } I second Kirill's question here. This seems an entirely survivable (but highly unexpected) state. I think this whole "if" could just be replaced with: WARN_ON_ONCE(!cpu_feature_enabled(X86_FEATURE_IBT) && !cpu_feature_enabled(X86_FEATURE_SHSTK), "Unexpected #CP\n"); Otherwise this looks good to me. Reviewed-by: Kees Cook -- Kees Cook