Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3346653pxk; Mon, 21 Sep 2020 11:12:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw++rMYpTO1L7lY/Y/SvsC2VEePO6HKJAPeA3c9Gxf1MD5yjtOM/+AQUsSiuQOqTRZHXN/m X-Received: by 2002:a05:6402:6c9:: with SMTP id n9mr139524edy.297.1600711925178; Mon, 21 Sep 2020 11:12:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600711925; cv=none; d=google.com; s=arc-20160816; b=WNgQuh31eRIqjVHawLSj5GIjyHhrmM97V2YMR+JK8nYK5E3vSjafzWt24WK98qjQ27 q75Gy2+XDEVsF+AweoBeZK2tzJbUSLjOxqsau77hECttAy7HaG8jYPGjdPo1+uUEjQME FwpHdFoIegIi3iC9rYxl8Q1HcV6I5BjlD6WTRWj+LjwZTr3wd2bv6KG8YHmj+Q19T3Zm +pae2iRbkLjZH7gbGluf8NirS7bD8l003KWzyjFQe5YN9iKAY/lFRHSO/+RpEHUGIQ0a rPg/wrzBi4RAkI0UYGi5j+HjVqg/SUv/nlO2cy6cttg+tTeGdirAiWXmXqoDGjhW5rt5 ussg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=R5y8g7BxrycAZEX1ekGP1NxNUv8mptOYaOPNzUsUn9Q=; b=0SfMdCr1eGaaKjOYdp5iAAZSe1ZGHSMV3cMK5E9vgQ2er2LVFN0dUiO5F41Q3xPAYo +5KCn0G6kTborkt9QhQZhS9syTn8v34rg0DwYJ57ldTN5vIynxlXRoHnYM8umnrt+80i Lbr1tDQBB6X2m7mXhhWdKkZFv2uYnUoZpqCI8n6nDyXz7BPBHRZzJeMOGBSKWh+5JKBC OgvaI17jJqnjES0/S+7vXXWFoxAgYAmspskOg7Dah3GJ6b6TL7EI/Ld0qxnWZb/bpVnr 2bgvIG9sQVJ9Apv+pmRuyPrY+CH9ykMidojY/m1ORx15FbgH+h6MeEMBc/elTPxhMhu7 ABQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y14si8386307edo.347.2020.09.21.11.11.40; Mon, 21 Sep 2020 11:12:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727291AbgIUSKe (ORCPT + 99 others); Mon, 21 Sep 2020 14:10:34 -0400 Received: from mga18.intel.com ([134.134.136.126]:10434 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726436AbgIUSKe (ORCPT ); Mon, 21 Sep 2020 14:10:34 -0400 IronPort-SDR: coZfDMUQZWYD0aFZbk6fcu+YjUsR3SYwSOzhXjJ/rY/PbEWUiGlfHCQYdcWf75wDdCPBEehmwY WhXwvnwKQvPQ== X-IronPort-AV: E=McAfee;i="6000,8403,9751"; a="148207084" X-IronPort-AV: E=Sophos;i="5.77,287,1596524400"; d="scan'208";a="148207084" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2020 11:10:23 -0700 IronPort-SDR: mpDMERO1472sfD/4J47NZq8BnQx2HCiGrr4acojo+GMCebeKiuwmaWlEv35AfvufSHZ3jXk2yd ADRtpBp0zvsA== X-IronPort-AV: E=Sophos;i="5.77,287,1596524400"; d="scan'208";a="485597119" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.160]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2020 11:10:22 -0700 Date: Mon, 21 Sep 2020 11:10:21 -0700 From: Sean Christopherson To: Borislav Petkov Cc: Jarkko Sakkinen , x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, Jethro Beekman , Haitao Huang , Chunyang Hui , Jordan Hand , Nathaniel McCallum , Seth Moore , Darren Kenny , Suresh Siddha , akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, asapek@google.com, cedric.xing@intel.com, chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, dave.hansen@intel.com, haitao.huang@intel.com, josh@joshtriplett.org, kai.huang@intel.com, kai.svahn@intel.com, kmoy@google.com, ludloff@google.com, luto@kernel.org, nhorman@redhat.com, puiterwijk@redhat.com, rientjes@google.com, tglx@linutronix.de, yaozhangx@google.com Subject: Re: [PATCH v38 14/24] x86/sgx: Add SGX_IOC_ENCLAVE_INIT Message-ID: <20200921181021.GA24481@linux.intel.com> References: <20200915112842.897265-1-jarkko.sakkinen@linux.intel.com> <20200915112842.897265-15-jarkko.sakkinen@linux.intel.com> <20200921173514.GI5901@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200921173514.GI5901@zn.tnic> User-Agent: Mutt/1.5.24 (2015-08-30) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 21, 2020 at 07:35:14PM +0200, Borislav Petkov wrote: > On Tue, Sep 15, 2020 at 02:28:32PM +0300, Jarkko Sakkinen wrote: > > +static int sgx_einit(struct sgx_sigstruct *sigstruct, void *token, > > + struct sgx_epc_page *secs, u64 *lepubkeyhash) > > +{ > > + int ret; > > + > > + preempt_disable(); > > + sgx_update_lepubkeyhash_msrs(lepubkeyhash, false); > > So this will update the cached copies *and* the MSRs itself if what's > cached is stale... > > > + ret = __einit(sigstruct, token, sgx_get_epc_addr(secs)); > > + if (ret == SGX_INVALID_EINITTOKEN) { > > ... so why would it return this error here? > > Definition of this error says: > > * %SGX_INVALID_EINITTOKEN: EINITTOKEN is invalid and enclave signer's > * public key does not match IA32_SGXLEPUBKEYHASH. > > when you just updated them?! > > > + sgx_update_lepubkeyhash_msrs(lepubkeyhash, true); > > So why force a second time? The LE pubkey hash MSRs are special snowflakes. They get reset to Intel's default key on any loss of EPC, e.g. if the system does a suspend/resume cycle. The approach we took (obviously) is to assume the kernel's cache can be stale at any given time. The alternative would be to try and track loss of EPC conditions and emulate the reset, but that's a bit dicey on bare metal as any missed case would hose SGX, and in a VM it's theoretically impossible to handle as a particularly unhelpful VMM could emulate loss of EPC at will. Yes, this need a big fat comment. > > + ret = __einit(sigstruct, token, sgx_get_epc_addr(secs)); > > + } > > + preempt_enable(); > > + return ret; > > +}