Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2954110rwb; Fri, 2 Dec 2022 18:39:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf4mQdSOTiLuLclCXYHrdBM+N8O/iWsJgtXc574mrQFPWtiUq+3/ct2sh2/u57Q3iH6BHodA X-Received: by 2002:a63:ed46:0:b0:476:e11d:8d51 with SMTP id m6-20020a63ed46000000b00476e11d8d51mr50500337pgk.252.1670035195062; Fri, 02 Dec 2022 18:39:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670035195; cv=none; d=google.com; s=arc-20160816; b=O8jz3J6d0snyuIj7IveWHV36A1URsiArnnY7nOuVG5beRsQMpS/FjFdkXER1mrB1m+ qy2PSKrCIb5Gz02MbnrGZ0bxee4OBb/2AKtyqhAjvV9jxeUZxrv1TSu9V6XXLcKTAlwz l7XzwTwGYyc/GR+DlG2QOx62QWQfXqTErTAvUvz/TDld9hBbiqUJJweSj86s7Y7GenlU hT4hXRqZcMVZuPCNXvATmiJyS66AorgasZbvUlGwg/PnOwFET01g/R5twyJDPyUrSIbN kLbypvrcZk0FN5n3bUA8Nk+COJZgYCt9L0Wnkhkdwf6fJzxbCABt5xQuvx5HAtmDmA59 Y/eQ== 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=LOsmhWzvTaGod4c98WIAwoN6RgdbrhOpBfnKGq6TCqg=; b=FXCVR9kUnjU2xmEy+yFPvBc4OY71t/GTcuo6ES7lY8KOILzxDuTeFnhUX2xN7NLD1S nsutYczaCNS+ejT5Cda7VnDDMGD2YflGrk2Kvl+hR6r6DiNDDgq9hJsZ2EoU76lQ4vG1 NNxgBxBZxZ6KrWLlM6AseKeGuTauuE/7nnqJRjdKV3JbJSvFM6a/7ZyQqt/GKTD6nP9B 5hez0fRcDdqZO+qSeDYR4Db9EuGlI9C9mUz2fwY6BtCgGzinHri/G9VWDXZQr+ZPCxjB 5/3P5MzLR5xxDgYzPVkCsmRAzLSwXUS5nTYf7W6f3bzwD93SU3fJ9hhQpvuWOzCjSd+V vW9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KvAsfhCw; 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 7-20020a17090a034700b0021306464b66si8407790pjf.28.2022.12.02.18.39.44; Fri, 02 Dec 2022 18:39:55 -0800 (PST) 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=KvAsfhCw; 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 S234899AbiLCC2O (ORCPT + 82 others); Fri, 2 Dec 2022 21:28:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234242AbiLCC2M (ORCPT ); Fri, 2 Dec 2022 21:28:12 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 026F455C97 for ; Fri, 2 Dec 2022 18:28:11 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id 62so5809185pgb.13 for ; Fri, 02 Dec 2022 18:28:10 -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=yqReivh0zotXbludpuG2wYgJpO9mQE2DtkJ7VM2yQW1IKrnoGxoM2FNua4p26qFyR9 KzgJHPRwOSJ+i05KD52RBcJDinpJB9jStPfu51AbFflfF88QQlMzdnd29jcn6vmpwsKl Yth3ntIcg7Lx9BhXNFnMer9AF6e+1lFM13eSW/ioww589ifokQHliRttzWFnIOrLMp04 OoIlWOiCLu/2Ym2+4kVn+xdcP/HqRteHiPEZ+B9BCXlzWHsLLSaT3jnutjnplE6Ts1tI 5y03ktr2S5wi/3i0gyQMD9qbgtoeVnkX4kgv+AZV9BYfpSyu5LPIBW/HPpz32u5dPhNT BGGg== X-Gm-Message-State: ANoB5pkqTK8cFNxpT7qQEu3V0ZSVWZ85E8tZ/GHq+HeQ3W18fGBm1g5u bFbfJt9hDjLHbDUqX7vhlKa4Nw== 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> 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 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