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 347DBC4321E for ; Sat, 3 Dec 2022 02:24:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B2C066B0074; Fri, 2 Dec 2022 21:24:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ADC706B0078; Fri, 2 Dec 2022 21:24:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 97F9D6B007B; Fri, 2 Dec 2022 21:24:45 -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 87D496B0074 for ; Fri, 2 Dec 2022 21:24:45 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 53C93140881 for ; Sat, 3 Dec 2022 02:24:45 +0000 (UTC) X-FDA: 80199401730.13.FB47868 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf12.hostedemail.com (Postfix) with ESMTP id E6A7540005 for ; Sat, 3 Dec 2022 02:24:44 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=IZNU2dMU; spf=pass (imf12.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.179 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=1670034285; 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=sycaKxrnAspMqyMU77ofh2U6+r7smc986YIDXo/lwrY=; b=yF7bxhKla7e6kjCFh/4heNeyoy75K56eot8RLCcFYGwfPFfdHX8Hr4KAP+pOTaksgNRZto RXjAAxFmY1C90pTiqJTSIwEzr2CcZWrfEJZ7o2VeGOCIx9q0kYElu4H+DbwW7bsoewBpzl J79K8wWDde/pzb4UD1jKzBFiZ2o80Cc= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=IZNU2dMU; spf=pass (imf12.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.179 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=1670034285; a=rsa-sha256; cv=none; b=fZZ2lIhODVlFePDXCOPrgimseaGBAHGxPsKeViJUH7SWHWuv2sqDfPDZkpUPoPolJQ4Y29 Kz67QjQxft90/6dtyvH6Yvv9uvCBa9XJxNVMoFGW+GR0M7C3HPzyykoFImLm9hvF8M/PDA HGrpB7SEDcfzo7K8ko/qvQR04w1egoU= Received: by mail-pf1-f179.google.com with SMTP id 130so6511903pfu.8 for ; Fri, 02 Dec 2022 18:24:44 -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=sycaKxrnAspMqyMU77ofh2U6+r7smc986YIDXo/lwrY=; b=IZNU2dMUs6dvRCVJt3dLZHnp6oLw0v5rzZGKA6Kd8bm4NsBjo1K2kKghVQvOMP5i79 V5hckw+Ac+GOxd2xVatczR8mFDBRoQEA/NmtdC3AfnW+31NXeBuq84WimyN5Nqyd8TDC +oYC0Sul0eoDxnpiV5qkpFYReUt5JMZM+klbA= 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=sycaKxrnAspMqyMU77ofh2U6+r7smc986YIDXo/lwrY=; b=nL8EEwfx5F8PzG32m4mnK2CrUQ0ktE3MuqnMoukUqwdyfKq2RSjknUnqpmvj1nuqHl oxpVqiYZt23eH/kUAdYbCb52itwA7Ar1vyQY1bFhzdq36noqRMpR5okIsA9J2zqyYhD4 U7w3csy6MSTMZy7Ikq5zwPrSxrhKXHMuRuE1Pz1jXiQ9masEj7H8AozR5iYSB3jIHuAS aoi/MeZD8ENXDuhCGWBOMOdZksTp32JjY+cbUTpynFVdzVitXIDxmWJtJT4S8+AmdKOM YzXQOO0qHxUkV5xixWGsuRmFyfG0Y4NNGTH1PRQ4+DgtGr0PAA+VhIPDY88A2gcLm56e ZsIQ== X-Gm-Message-State: ANoB5pnvuv6oXeY100hcANA0O9rALJRRBsWZOLo+tebaAeoGObnUkNxj g/kbkstO19QUTY7mC0s6tRzmNw== X-Google-Smtp-Source: AA0mqf6ecGDellGthenD6ceIHI53cmnvUC0Mod6jRuSERrc/xcY+2kDsyICXdTabTZG7Un5WGhNfAw== X-Received: by 2002:a63:1655:0:b0:478:4cf6:d01 with SMTP id 21-20020a631655000000b004784cf60d01mr17112608pgw.279.1670034283967; Fri, 02 Dec 2022 18:24:43 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 74-20020a62164d000000b0056c0d129edfsm5718087pfw.121.2022.12.02.18.24.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 18:24:43 -0800 (PST) Date: Fri, 2 Dec 2022 18:24:42 -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 05/39] x86/fpu/xstate: Introduce CET MSR and XSAVES supervisor states Message-ID: <202212021824.8EE4948F9@keescook> References: <20221203003606.6838-1-rick.p.edgecombe@intel.com> <20221203003606.6838-6-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221203003606.6838-6-rick.p.edgecombe@intel.com> X-Stat-Signature: mtwfrty3ypzr31n4bpje8cdfbx5pjour X-Rspam-User: X-Spamd-Result: default: False [5.09 / 9.00]; SORBS_IRL_BL(3.00)[209.85.210.179: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.01)[43.34%]; 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-Rspamd-Queue-Id: E6A7540005 X-Rspamd-Server: rspam06 X-HE-Tag: 1670034284-397826 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:35:32PM -0800, Rick Edgecombe wrote: > From: Yu-cheng Yu > > Shadow stack register state can be managed with XSAVE. The registers > can logically be separated into two groups: > * Registers controlling user-mode operation > * Registers controlling kernel-mode operation > > The architecture has two new XSAVE state components: one for each group > of those groups of registers. This lets an OS manage them separately if > it chooses. Future patches for host userspace and KVM guests will only > utilize the user-mode registers, so only configure XSAVE to save > user-mode registers. This state will add 16 bytes to the xsave buffer > size. > > Future patches will use the user-mode XSAVE area to save guest user-mode > CET state. However, VMCS includes new fields for guest CET supervisor > states. KVM can use these to save and restore guest supervisor state, so > host supervisor XSAVE support is not required. > > Adding this exacerbates the already unwieldy if statement in > check_xstate_against_struct() that handles warning about un-implemented > xfeatures. So refactor these check's by having XCHECK_SZ() set a bool when > it actually check's the xfeature. This ends up exceeding 80 chars, but was > better on balance than other options explored. Pass the bool as pointer to > make it clear that XCHECK_SZ() can change the variable. > > While configuring user-mode XSAVE, clarify kernel-mode registers are not > managed by XSAVE by defining the xfeature in > XFEATURE_MASK_SUPERVISOR_UNSUPPORTED, like is done for XFEATURE_MASK_PT. > This serves more of a documentation as code purpose, and functionally, > only enables a few safety checks. > > Both XSAVE state components are supervisor states, even the state > controlling user-mode operation. This is a departure from earlier features > like protection keys where the PKRU state is a normal user > (non-supervisor) state. Having the user state be supervisor-managed > ensures there is no direct, unprivileged access to it, making it harder > for an attacker to subvert CET. > > To facilitate this privileged access, define the two user-mode CET MSRs, > and the bits defined in those MSRs relevant to future shadow stack > enablement patches. > > Tested-by: Pengfei Xu > Tested-by: John Allen > Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook -- Kees Cook