Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp674233pxk; Wed, 2 Sep 2020 11:44:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbti8fYOelYyCCiHmisJeHr+jf91fIADJpb7HpWjXSqm8Ffsx/z9bKWFjIDXQD49jtWcHm X-Received: by 2002:a50:fb15:: with SMTP id d21mr1538585edq.150.1599072264061; Wed, 02 Sep 2020 11:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599072264; cv=none; d=google.com; s=arc-20160816; b=uz+PGB0INw4gMusLEIWnjDAX2TkAQvwjeEnX+tnU0bvSICgxBobpZndEAeZ8HjRrAI BIsTho9uLlGfNmyd6orsHY+NoMTKql8u54yRn8uOxcEIldqxliN89XYIjfXulenN1yKD KbJVJbPgZ7+/I+E/I2bX5UuUSVRylFsbOwXoHXGHidN7VAg0WCoCFkdK0znYCiLl6UEB v5I3mwrYZhEx3fFA1hN5m7mIPJEygQXB+SvfWXRJtkjGBIzknNsxby7431jeFSAHvvfh zz65Uc3GhqajT8qxUsRT6GdQCInyuxVAa2OxDmgjD4y1A1YANcWGKzgLxZBMcjuXvNq+ yXPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to:message-id :organization:from:content-transfer-encoding:mime-version:date :references:subject:cc:to:ironport-sdr:ironport-sdr; bh=ffPZD112s6Iv7Os2+TNjIEIEC2wJ8Uc85x6kzyYmuU4=; b=bMJnvETwAT0URIC/RYyDaE6a57aeUzMJ3jqQ16f8lIrPwRG9f5jxT6X01jBnPw3hY6 Bn9IQcl8Ha2eWJ104sTGRGPjp9XxxswUG3pjHpq8hloU21Frzg6Vvw5JfQfc1JZGWNsO nmnewJHwh90Fn6I7a0KcVBholNysWdIxGSOJObUL9xn4J/tpvXflX194px7WnDGvJo8o kgtDQNSgzmWHu/RIFIJndaocQdu0KoyxzK8v16bca3Ru7utkPtkAdXzeiGSU3Cmmzlpe zjchzFHhTtdIURNT9QRWu9iolmmqp7qAaeZRPWdwON3AUbDccqNDKs0sZ75THZSF/HIK Vn1A== 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 bd8si50072edb.477.2020.09.02.11.44.00; Wed, 02 Sep 2020 11:44:24 -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 S1728281AbgIBSk5 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 2 Sep 2020 14:40:57 -0400 Received: from mga07.intel.com ([134.134.136.100]:17072 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726567AbgIBSky (ORCPT ); Wed, 2 Sep 2020 14:40:54 -0400 IronPort-SDR: tKAYgg1zYv4AUuuI/LWak6KL/a4DCSATuhu1aXx/v2EX2FyzYWFPPoS2BQfzB/7AFmitdb0V5a dEiz4fCJvdMg== X-IronPort-AV: E=McAfee;i="6000,8403,9732"; a="221674238" X-IronPort-AV: E=Sophos;i="5.76,383,1592895600"; d="scan'208";a="221674238" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2020 11:40:52 -0700 IronPort-SDR: P4YeBPN8mp1qKmIrafAtjmZm4807Q/A2J7qZUuipcGX0UCptRPoHbegSotuQlM/6nSqA5dL+kN EMMI3WIakq6Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,383,1592895600"; d="scan'208";a="502231194" Received: from hhuan26-mobl1.amr.corp.intel.com ([10.255.38.180]) by fmsmga006.fm.intel.com with ESMTP; 02 Sep 2020 11:40:48 -0700 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "Sean Christopherson" Cc: "Jarkko Sakkinen" , x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, "Jethro Beekman" , "Chunyang Hui" , "Jordan Hand" , "Nathaniel McCallum" , "Seth Moore" , "Suresh Siddha" , akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com, asapek@google.com, bp@alien8.de, cedric.xing@intel.com, chenalexchen@google.com, conradparker@google.com, cyhanish@google.com, dave.hansen@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 v33 11/21] x86/sgx: Linux Enclave Driver References: <20200617220844.57423-1-jarkko.sakkinen@linux.intel.com> <20200617220844.57423-12-jarkko.sakkinen@linux.intel.com> <20200702035902.GC1819@linux.intel.com> <20200704033025.GA144756@linux.intel.com> <20200902161012.GD11695@sjchrist-ice> Date: Wed, 02 Sep 2020 13:40:47 -0500 MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT From: "Haitao Huang" Organization: Intel Corp Message-ID: In-Reply-To: <20200902161012.GD11695@sjchrist-ice> User-Agent: Opera Mail/1.0 (Win32) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 02 Sep 2020 11:10:12 -0500, Sean Christopherson wrote: > On Tue, Sep 01, 2020 at 10:06:32PM -0500, Haitao Huang wrote: >> On Fri, 03 Jul 2020 22:31:10 -0500, Jarkko Sakkinen >> wrote: >> >> > On Wed, Jul 01, 2020 at 08:59:02PM -0700, Sean Christopherson wrote: >> > > On Thu, Jun 18, 2020 at 01:08:33AM +0300, Jarkko Sakkinen wrote: >> > > > +static int sgx_validate_secs(const struct sgx_secs *secs, >> > > > + unsigned long ssaframesize) >> > > > +{ >> > > > + if (secs->size < (2 * PAGE_SIZE) || !is_power_of_2(secs->size)) >> > > > + return -EINVAL; >> > > > + >> > > > + if (secs->base & (secs->size - 1)) >> > > > + return -EINVAL; >> > > > + >> > > > + if (secs->miscselect & sgx_misc_reserved_mask || >> > > > + secs->attributes & sgx_attributes_reserved_mask || >> > > > + secs->xfrm & sgx_xfrm_reserved_mask) >> > > > + return -EINVAL; >> > > > + >> > > > + if (secs->attributes & SGX_ATTR_MODE64BIT) { >> > > > + if (secs->size > sgx_encl_size_max_64) >> > > > + return -EINVAL; >> > > > + } else if (secs->size > sgx_encl_size_max_32) >> > > > + return -EINVAL; >> > > >> > > These should be >=, not >, the SDM uses one of those fancy ≥ >> ligatures. >> > > >> > > Internal versions use more obvious pseudocode, e.g.: >> > > >> > > if ((DS:TMP_SECS.ATTRIBUTES.MODE64BIT = 1) AND >> > > (DS:TMP_SECS.SIZE AND (~((1 << CPUID.18.0:EDX[15:8]) – 1))) >> > > { >> > > #GP(0); >> > >> > Updated as: >> > >> > static int sgx_validate_secs(const struct sgx_secs *secs) >> > { >> > u64 max_size = (secs->attributes & SGX_ATTR_MODE64BIT) ? >> > sgx_encl_size_max_64 : sgx_encl_size_max_32; >> > >> > if (secs->size < (2 * PAGE_SIZE) || !is_power_of_2(secs->size)) >> > return -EINVAL; >> > >> > if (secs->base & (secs->size - 1)) >> > return -EINVAL; >> > >> > if (secs->miscselect & sgx_misc_reserved_mask || >> > secs->attributes & sgx_attributes_reserved_mask || >> > secs->xfrm & sgx_xfrm_reserved_mask) >> > return -EINVAL; >> > >> > if (secs->size >= max_size) >> > return -EINVAL; >> > >> >> This should be > not >=. Issue raised and fixed by Fábio Silva for >> ported >> patches for OOT SGX support: >> https://github.com/intel/SGXDataCenterAttestationPrimitives/pull/123 >> >> I tested and verified with Intel arch, the comparison indeed should be >> >. > > And this is a confirmed SDM bug, correct? yes, the pseudo code for ECREATE is inaccurate and inconsistent with the CPUID spec. The latter is correct. Haitao