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 50B54C004D4 for ; Fri, 20 Jan 2023 01:08:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229851AbjATBIS (ORCPT ); Thu, 19 Jan 2023 20:08:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229902AbjATBIL (ORCPT ); Thu, 19 Jan 2023 20:08:11 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9EAFA57B8 for ; Thu, 19 Jan 2023 17:08:05 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id d3so3980041plr.10 for ; Thu, 19 Jan 2023 17:08:05 -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=flFLctJTPfL2nXWtj1YNou8QQFyZ70WxAkpNrSzol2k=; b=Wn5vPjaYTZvwNCHchRHbnsIHk1WCdLejvx1AtDl8vEi8uPvw6uThwG0dwVe/H4pu0x cWDItOTdO/sk1AcDZle8xJFIiw9crgtNk9c/LiXJgd1qZydXSg3s2fpleRnoqRYRPNd/ dYRQT01ECPVEyE2xdqjjf7PE+qQAB2iqNpbc8= 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=flFLctJTPfL2nXWtj1YNou8QQFyZ70WxAkpNrSzol2k=; b=Aj1GU0zyH+XxRIKe+6jcFH5SKICmTgYvvpdEx7CLw6Eo5M3b53VM/JOxs2OAUEjMlJ 67j5ylHu2ArJhCsXkbf2k1i0sWB0KgpQ4cc+mczE7LdMDklI1lbL6VDpeoXgkKOAQWAj fWTYul4xD6ucQlVO3BcOf2u8MewXfDgenpJWjuTFU7BxewMNPAGo7DD8EXSsXP6R0N/3 fr8SBTpiL+hGJlM+xUe2AdGsh0e1L0EVActD8ciwPnxRh2y31qsOIVh4R3vWbE0KWUbx e7Hr4fHQZCdLaenKlzm9swuTQBk9Py1+bsID95NRbrCx8RiqF9M+FqJGCtdQMS54phZV BGQA== X-Gm-Message-State: AFqh2kr+9JtCi8XDoydoi35rXN6ag3PLUnoVrFWPKweUOEDcfnAv/mYI hPQXUSXqyi0QG3hHOE54Img4YQ== X-Google-Smtp-Source: AMrXdXsQathgrTdjgVAi679ipcO9Vh3LvoE/7091JNAPiU/s9vvqq/sC6hX4drnilOyMkIKibvHXbA== X-Received: by 2002:a05:6a21:3989:b0:b8:d65d:5f7a with SMTP id ad9-20020a056a21398900b000b8d65d5f7amr12678405pzc.35.1674176885185; Thu, 19 Jan 2023 17:08:05 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id j18-20020a635952000000b004cd1f1a14f6sm7519083pgm.86.2023.01.19.17.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jan 2023 17:08:04 -0800 (PST) Date: Thu, 19 Jan 2023 17:08:04 -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 Subject: Re: [PATCH v5 37/39] x86: Add PTRACE interface for shadow stack Message-ID: <202301191708.F1C43C9D8@keescook> References: <20230119212317.8324-1-rick.p.edgecombe@intel.com> <20230119212317.8324-38-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230119212317.8324-38-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org On Thu, Jan 19, 2023 at 01:23:15PM -0800, Rick Edgecombe wrote: > From: Yu-cheng Yu > > Some applications (like GDB) would like to tweak shadow stack state via > ptrace. This allows for existing functionality to continue to work for > seized shadow stack applications. Provide an regset interface for > manipulating the shadow stack pointer (SSP). > > There is already ptrace functionality for accessing xstate, but this > does not include supervisor xfeatures. So there is not a completely > clear place for where to put the shadow stack state. Adding it to the > user xfeatures regset would complicate that code, as it currently shares > logic with signals which should not have supervisor features. > > Don't add a general supervisor xfeature regset like the user one, > because it is better to maintain flexibility for other supervisor > xfeatures to define their own interface. For example, an xfeature may > decide not to expose all of it's state to userspace, as is actually the > case for shadow stack ptrace functionality. A lot of enum values remain > to be used, so just put it in dedicated shadow stack regset. > > The only downside to not having a generic supervisor xfeature regset, > is that apps need to be enlightened of any new supervisor xfeature > exposed this way (i.e. they can't try to have generic save/restore > logic). But maybe that is a good thing, because they have to think > through each new xfeature instead of encountering issues when new a new > supervisor xfeature was added. > > By adding a shadow stack regset, it also has the effect of including the > shadow stack state in a core dump, which could be useful for debugging. > > The shadow stack specific xstate includes the SSP, and the shadow stack > and WRSS enablement status. Enabling shadow stack or wrss in the kernel > involves more than just flipping the bit. The kernel is made aware that > it has to do extra things when cloning or handling signals. That logic > is triggered off of separate feature enablement state kept in the task > struct. So the flipping on HW shadow stack enforcement without notifying > the kernel to change its behavior would severely limit what an application > could do without crashing, and the results would depend on kernel > internal implementation details. There is also no known use for controlling > this state via prtace today. So only expose the SSP, which is something > that userspace already has indirect control over. > > Tested-by: Pengfei Xu > Tested-by: John Allen > Co-developed-by: Rick Edgecombe > Signed-off-by: Rick Edgecombe Reviewed-by: Kees Cook -- Kees Cook