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 4C89DC4321E for ; Sat, 3 Dec 2022 02:28:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235010AbiLCC2P (ORCPT ); Fri, 2 Dec 2022 21:28:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235035AbiLCC2N (ORCPT ); Fri, 2 Dec 2022 21:28:13 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B2DB5A6CA for ; Fri, 2 Dec 2022 18:28:11 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id 82so5878635pgc.0 for ; Fri, 02 Dec 2022 18:28:11 -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=LOsmhWzvTaGod4c98WIAwoN6RgdbrhOpBfnKGq6TCqg=; b=KvAsfhCwVbLiHtggx4tLU+VgpymrMDHEzjPfhgXtmVu/ofbJX5AhlXNCHmaTYn5KAp Py5x3/L/SY0cp4KjKMqFdj0TT4KzaX71tq6XCmOX/+8/RjaXBtgpB9reg7zfFfOGC01V ZHRTs9UAP5P1M8HT39RFsB1QQ8YFZtMDHhVdg= 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=LOsmhWzvTaGod4c98WIAwoN6RgdbrhOpBfnKGq6TCqg=; b=Y8Uw2BlhCTSxIlK1tGOuAcHZgxGOTTskeh1/TvqA+ZgIn21BBtPdFzC4huTQ1PfL6d rF0okXMcgF8ZYnT0Z75kf7Mp7hPfrzSNn8LflScsc3Qpoq+onsOQuk8lPQXVR2rmCzPl nBLOSOwqSO1WKctvqVu2XuJNvvEJMrs47a8JhKhdOoUZ3S5IzD/2JVxUuYxZ4UJTqtnt h0GXtWU5piMPF8IVpbktYfdcPe28r0xPgIcwn871eiUr26vyg95488Pbvi3q2pHrGLQJ Rh1rAa5Xe9jWQ1wsf3QlI+xn9r27TX+NNDXQcc0dUV/QsxHd/ZxtLU1yUxldXd9JSUG/ Stbw== X-Gm-Message-State: ANoB5pm17Gmb33v/h4pJQJJRREnDUASjNrhPCSgIBy34cEkYwAgOzP9w r6+nnPSF6nFn2tdK5C97IjI4vw== X-Google-Smtp-Source: AA0mqf5LGiNqlxi+OSZapMhWipQg4aQbiacQEOzN4PxP65c2T9P8s/SelBujWUq07q05VtM4ESiCWQ== X-Received: by 2002:a63:ce0e:0:b0:457:dced:8ba9 with SMTP id y14-20020a63ce0e000000b00457dced8ba9mr51658398pgf.221.1670034490505; Fri, 02 Dec 2022 18:28:10 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w4-20020a634744000000b004786c63c21esm3602572pgk.42.2022.12.02.18.28.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 18:28:09 -0800 (PST) Date: Fri, 2 Dec 2022 18:28:08 -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 v4 07/39] x86: Add user control-protection fault handler Message-ID: <202212021827.03F637C9C9@keescook> References: <20221203003606.6838-1-rick.p.edgecombe@intel.com> <20221203003606.6838-8-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221203003606.6838-8-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org On Fri, Dec 02, 2022 at 04:35:34PM -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. Refactor this fault handler into sparate user and kernel handlers, > like the page fault handler. Add a control-protection handler for usermode. > > 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 > !cpu_feature_enabled(). 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 > Co-developed-by: Rick Edgecombe > Signed-off-by: Rick Edgecombe This looks nice cleaner to me. Thanks! Reviewed-by: Kees Cook -- Kees Cook