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 361B7C678DC for ; Fri, 20 Jan 2023 00:50:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229471AbjATAua (ORCPT ); Thu, 19 Jan 2023 19:50:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjATAu2 (ORCPT ); Thu, 19 Jan 2023 19:50:28 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48102B773 for ; Thu, 19 Jan 2023 16:50:27 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id p24so3940546plw.11 for ; Thu, 19 Jan 2023 16:50:27 -0800 (PST) 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:message-id:reply-to; bh=R2aEPPbfB/worS45EAxatPQssMYjlVb1o5H9g9LucF0=; b=lZ5Lch+fy2oLgIdUAA75L9S48vEREC8i/frZUS5ItPKxp3Pld370+Dr1dRugVzsT+M 7heNk7KiSyRSOUwU7RFFj47VfbQhnuJAgSEyvRD0fgxnkBfzNE5EOjIorGzYdWbr52z4 4rmF4UPJPe8tgvkNN/exAf+u0UyWvpPid5+ig= 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 :message-id:reply-to; bh=R2aEPPbfB/worS45EAxatPQssMYjlVb1o5H9g9LucF0=; b=csAtwWQwYwss9rZ+oIgfGP6N4oGSxUDc5O9qconefSDKPh2apxBFQkOwD6/hlzFngm 0CK8EqbYog6uxs4cJoOjr2UAyP89rg8pW917ra7dSG5zXc75QzvaOBOrE/QC7b87n0xS ORUiCk8ckM8muo8ynsKC5HZ/uyQt1dbb6jYlN1W/AwtwpK5qchg39B7v8fMKW+7R4EXM s66tG6QvgrSbebntvX2p+G+Q3akEEiqO3wO0hq3xfaOABjM8knOfjrr4NrHWekT0uhxi patxaaIn+7CMb4VbHozq8PAYYfl7cK/iq4R3p6mDfflcZivjiUM4nc0qZ6q6NP1y9ilf nyTg== X-Gm-Message-State: AFqh2ko54zkMTTJtiyFCQQUoBrK+hPF+ekwkRXeGqh8l0O4kmD6B3T96 xWIfDUfYpBOT12d9EeGMqqQI4Q== X-Google-Smtp-Source: AMrXdXtc7roB+w/tCl6tJQ9aF1cdAEg63HAhbectzk8kGPfsJ3hnUhD7/rAtxmwtE0GL8Q/xUmc13g== X-Received: by 2002:a17:90a:71c3:b0:229:77f:6d2f with SMTP id m3-20020a17090a71c300b00229077f6d2fmr13141866pjs.44.1674175826738; Thu, 19 Jan 2023 16:50:26 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id mt19-20020a17090b231300b0022704cc03ebsm238569pjb.41.2023.01.19.16.50.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jan 2023 16:50:26 -0800 (PST) Date: Thu, 19 Jan 2023 16:50:25 -0800 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 , 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, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com, Yu-cheng Yu , Michael Kerrisk Subject: Re: [PATCH v5 07/39] x86: Add user control-protection fault handler Message-ID: <202301191649.5283D6C@keescook> References: <20230119212317.8324-1-rick.p.edgecombe@intel.com> <20230119212317.8324-8-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230119212317.8324-8-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 19, 2023 at 01:22:45PM -0800, Rick Edgecombe wrote: > From: Yu-cheng Yu > > A control-protection fault is triggered when a control-flow transfer > attempt violates Shadow Stack or Indirect Branch Tracking constraints. > For example, the return address for a RET instruction differs from the copy > on the shadow stack. > > There already exists a control-protection fault handler for handling kernel > IBT faults. Refactor this fault handler into separate user and kernel > handlers, like the page fault handler. Add a control-protection handler > for usermode. To avoid ifdeffery, put them both in a new file cet.c, which > is compiled in the case of either of the two CET features supported in the > kernel: kernel IBT or user mode shadow stack. Move some static inline > functions from traps.c into a header so they can be used in cet.c. > > Opportunistically fix a comment in the kernel IBT part of the fault > handler that is on the end of the line instead of preceding it. > > Keep the same behavior for the kernel side of the fault handler, except for > converting a BUG to a WARN in the case of a #CP happening when the feature > is missing. This unifies the behavior with the new shadow stack code, and > also prevents the kernel from crashing under this situation which is > potentially recoverable. > > The control-protection fault handler works in a similar way as the general > protection fault handler. It provides the si_code SEGV_CPERR to the signal > handler. > > Tested-by: Pengfei Xu > Tested-by: John Allen > Signed-off-by: Yu-cheng Yu This diff would have been a bit easier to review if the file move was separate from the addition of the handler, but regardless: Reviewed-by: Kees Cook -- Kees Cook