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 E8137C004D4 for ; Fri, 20 Jan 2023 00:47:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5CA796B0075; Thu, 19 Jan 2023 19:47:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 554616B0078; Thu, 19 Jan 2023 19:47:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3CE546B007B; Thu, 19 Jan 2023 19:47:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2F6C66B0075 for ; Thu, 19 Jan 2023 19:47:01 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E449B8094B for ; Fri, 20 Jan 2023 00:47:00 +0000 (UTC) X-FDA: 80373337800.23.DC8B9E9 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by imf03.hostedemail.com (Postfix) with ESMTP id 1798C20009 for ; Fri, 20 Jan 2023 00:46:58 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=LKldp5a7; spf=pass (imf03.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.51 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=1674175619; 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=ayJn/GYBuR/fjLdDFpqtJAjszedzztZoiWdekO0asUc=; b=5Xt0AomvAMliDOjNfW6tXKc3h8C9xKGuyHA3pyPg0HbLqjqw5O4ktutT95Lud5/oGkUYIa qK6DhcjxSmeUbjAMn6eoDMIkc2KqqEls+YCHHU8Wm4t1Qwfh02Kd2KE59WAYat3h3SupNj dNiUDMvus6gt3IyMvW5xTvCNNRmYZCY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=LKldp5a7; spf=pass (imf03.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.51 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=1674175619; a=rsa-sha256; cv=none; b=aavR1R0UD4ua8EHI3CKvwbVrvDxjkiTzDHlbs2WeIQMOimbz4FiXsrgxvNh2IgAIuWDq3s JflgcnnQNmBeHr6bNVJch0BgXuq3qTBIoEQJUIeMtVW/eJBYsu4VejO/znRbklWL385Ghj impDZ8cP75TgZmiU/Uy6SUrQxKIJIMw= Received: by mail-pj1-f51.google.com with SMTP id z1-20020a17090a66c100b00226f05b9595so3485873pjl.0 for ; Thu, 19 Jan 2023 16:46:58 -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=ayJn/GYBuR/fjLdDFpqtJAjszedzztZoiWdekO0asUc=; b=LKldp5a7K3BsUCsXJfb8c+4bU1Z1rcCPaC6m1IG3+dGP0kcfglcgNPJWU6gHFk57BM ygiHAt3O1+ekCwb5p5hlgI2h7bYQzAca7U8VlDDtO9oyTPawyLWlpYuU/HICfsTWVNiu 9XqTBs/GbFlq+lrpUCNHjoePJxihOK9Iw0aYQ= 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=ayJn/GYBuR/fjLdDFpqtJAjszedzztZoiWdekO0asUc=; b=omF0BTG2CtGleSEjBbZbuUO9PRu1g0x68gjnYukEhepf1MRGu9Thb03p3TQ42ehdMC PMCfkuVegNvblhfYKiGcflb2/7lz23NeODJDAzJc+iHNU9bGg+REvT6U1HH4bMxtvQgG zbg+sIf9jAxePm1eLhaVstRamuoTh6OQBlSx6BsScFyfuyEyZpqAibcfvvQS24AM5WiN 7U0DQ+fLDWtnBGUgqrpuY2lsoWGUYCbPrQgfxacUA9dNOyWxC7VsIKwvpSz8P7uK0kMO oT0MpKifeOBpFKcb4H/Pu616ULbGFqc0AfPrHt1f3gK9YIhStgYMAYsTUfvBCj73gMLD tVvw== X-Gm-Message-State: AFqh2kov6AMu5BfUXiNQXiiqVNLm2JmX3Oa98mwfj0hcBikjFZuFo2jk UKp/IV/13ZLQR9vuNunlqO2lrw== X-Google-Smtp-Source: AMrXdXuKfEj0zOvGfr1iA/kr1NdJ/npdryHNpx4REj8VhMm71VRKkoixQ6w2KxNIbipwCihUiBMNPQ== X-Received: by 2002:a17:902:cec7:b0:191:2a9c:52a1 with SMTP id d7-20020a170902cec700b001912a9c52a1mr17245912plg.19.1674175618067; Thu, 19 Jan 2023 16:46:58 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id c8-20020a170902d48800b001925c3ec34esm2560903plg.196.2023.01.19.16.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Jan 2023 16:46:57 -0800 (PST) Date: Thu, 19 Jan 2023 16:46:56 -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 05/39] x86/fpu/xstate: Introduce CET MSR and XSAVES supervisor states Message-ID: <202301191646.BE63FEC@keescook> References: <20230119212317.8324-1-rick.p.edgecombe@intel.com> <20230119212317.8324-6-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230119212317.8324-6-rick.p.edgecombe@intel.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 1798C20009 X-Stat-Signature: q9ojhxums91h3arwz3nyu814k3a98p6o X-Rspam-User: X-HE-Tag: 1674175618-572314 X-HE-Meta: U2FsdGVkX1+ZFH58j4MWTwZHagW9bAa23qWQ2J9NX3ZdCK9EtGcSkevRxXuGGt/J++5wMJCgfANYHpTzjRgzVG3SpKCSZ4fp06gFEzWL8z0x94jfca4K3+FbIrrm/bFkJFDgNo7+xscYbuktpU2mu0ZhMdnVhFH1QBrR72SG7jCyhx+LEEQY25zPa4BjhdMph0wwGeJ+uXbeJyMkz9Tq760lo1H52EU62USjL3LRd4/1rpDmExDVvwBuYdShxZX9gBiYBh4dNA/DLOXnaVkPhzGx+nKaQogtXcJKqFyprFGNwwQMKyy6WAsME0EoUxEYCTV+lreoLgEIPJ6lP1I08/82sDCUiYUgoV9jRA2mSKgOrdtSzxEKaZTKu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nahyz6wuWkgi8533EZKH4nJscXai07OJHAFMGdcKSGgM1OmiHMWNCwr+UDWkjjzq/ykQO0q5ElLab43y9r6n07zqyLvLMwG748= 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 Thu, Jan 19, 2023 at 01:22:43PM -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