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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6151C4321E for ; Sat, 3 Dec 2022 02:55:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5BE1E6B0071; Fri, 2 Dec 2022 21:55:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 546BF6B0072; Fri, 2 Dec 2022 21:55:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 399516B0073; Fri, 2 Dec 2022 21:55:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 248426B0071 for ; Fri, 2 Dec 2022 21:55:52 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E7A914062A for ; Sat, 3 Dec 2022 02:55:51 +0000 (UTC) X-FDA: 80199480102.26.6B56EBB Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf07.hostedemail.com (Postfix) with ESMTP id 871A94000D for ; Sat, 3 Dec 2022 02:55:51 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=ATpOOq4F; spf=pass (imf07.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.182 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670036151; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=n2U2r+2t7pkXJfqUVDBQCHb1t4+jJyTASRBi7nj2p/k=; b=aMv50MN0QvyIONutM0nSCCCyejmy+3XsGR6xIZlkE2aI9QuD0ey8YQ8j0oF9335KPE/Yzv Y1jEkWcAvTj2HnGkkjdMvTtP2t2uB6/+bNnARMTBOqxInLE3jsn39YdyDtA4SPZqUJcgDN hH3MhJWiZqQs2HX5ubFSMLizXGTKLQc= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=ATpOOq4F; spf=pass (imf07.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.182 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670036151; a=rsa-sha256; cv=none; b=INuxQ+GUUveQ5kfNR0zAWOCQBlfoBeh5ZeQUBDNExk4IDR5N9xJgRDlzyfSj6wwUxcRNHQ aFY5qpEgF6Q0iyevRTlX/W0AMkuFvVXu3q2898cxH7ofAHDR6+IEpqtcgbLoOgc/2xrwdj f/xpkiLKD3cyUnGUYLMKf13VYu+ebVA= Received: by mail-pg1-f182.google.com with SMTP id w37so5869093pga.5 for ; Fri, 02 Dec 2022 18:55:51 -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=n2U2r+2t7pkXJfqUVDBQCHb1t4+jJyTASRBi7nj2p/k=; b=ATpOOq4FoL+4Yp2Dgf6WeXAC1dU8qOSQQP1qF3+pWOHUBvu3pwQfSKS7wGOII2ScCT tTCMi9+GPdv9E7fhMUWl0xLvYy3xjMdMWswcNd9euLVaiLW2FflFl39Kh6ko7mGBUPDv mu3Jx6n7d8C6bgEMDGlVI+2tfYAVEXVrGJtUI= 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=n2U2r+2t7pkXJfqUVDBQCHb1t4+jJyTASRBi7nj2p/k=; b=UCnVzdBGNJE4s0kjKZwR1si73T77ubTBTWJ+jXwrbznqY/Ad22xYICZFQXjiJXZEap tqeuJdxvdLnkcr/fxC1CEQyAqKtuB1mNCstWhL2B88GImQbgs4SKnspyqGPtd5z60tta 2WpPpa3Uh6gk5QXD+LelYR9UXn9+JRNq/JQtpc7B0WAEb+vrR22CI5EFR1vnqIca+Q9J IRdVfieJbB+71q9aYoEUWCKBVvB9YH4pkn7QCj123usbeoiPFYnZnPHTdC86mmltJEQa NhGhn0HDOp/JHyBmqYBKElm23SuThZZ5Bga3AngOGIuFnpnwkTJOZDf+xBfrD4XQf98o PDeg== X-Gm-Message-State: ANoB5pm5N0xOy0tZ1nqPDNXR6QRxWEIIgQBMH+imGADnlpomQvf5zqKU 5wRfFoSMbnvFld9RuOf5o9zHuA== X-Google-Smtp-Source: AA0mqf5A1qERUjt/R+6TLTBviWIJ7Ee6ql5DOsOsuuxe2fjmgyBWCWRVOpwsDrrukXVaieWbRbMZWA== X-Received: by 2002:a05:6a00:21c8:b0:562:e0fb:3c79 with SMTP id t8-20020a056a0021c800b00562e0fb3c79mr54806230pfj.39.1670036150539; Fri, 02 Dec 2022 18:55:50 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id i17-20020a170902c95100b00189847cd4acsm6330926pla.237.2022.12.02.18.55.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 18:55:50 -0800 (PST) Date: Fri, 2 Dec 2022 18:55:49 -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 v4 37/39] x86: Add PTRACE interface for shadow stack Message-ID: <202212021855.41F90E2D9@keescook> References: <20221203003606.6838-1-rick.p.edgecombe@intel.com> <20221203003606.6838-38-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221203003606.6838-38-rick.p.edgecombe@intel.com> X-Spamd-Result: default: False [5.07 / 9.00]; SORBS_IRL_BL(3.00)[209.85.215.182:from]; SUSPICIOUS_RECIPS(1.50)[]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; BAYES_HAM(-0.03)[50.99%]; DKIM_TRACE(0.00)[chromium.org:+]; RCPT_COUNT_TWELVE(0.00)[39]; FROM_EQ_ENVFROM(0.00)[]; DMARC_POLICY_ALLOW(0.00)[chromium.org,none]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; PREVIOUSLY_DELIVERED(0.00)[linux-mm@kvack.org]; R_DKIM_ALLOW(0.00)[chromium.org:s=google]; ARC_NA(0.00)[]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:209.85.128.0/17]; TO_DN_SOME(0.00)[]; TAGGED_RCPT(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 871A94000D X-Stat-Signature: 4mfocwz1mcpntuxygzq5669p91i76ymq X-HE-Tag: 1670036151-18299 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Dec 02, 2022 at 04:36:04PM -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