Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp579065pxk; Wed, 2 Sep 2020 09:13:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcozgiDZMpuBaTcT+t3u/GUHhVmzGq7tlYHlEmtQJsOEXlJ5LcupoP+hUIW+gxHKKpWWzc X-Received: by 2002:a17:906:a0c5:: with SMTP id bh5mr771724ejb.120.1599063209727; Wed, 02 Sep 2020 09:13:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599063209; cv=none; d=google.com; s=arc-20160816; b=yIpizsdSD06y9vNZkgRbtgDDQGCCSKBPEY9Zha5l+R/kCGkrLY75RhxrbdTnawnBav kZ8zrK01VVS5VJFpRA4UiG/TBw6gLMzH3gkY1RmtQgv/GsJS4cLbPqs4Pt5reGdjt2N9 weFfXL/4vwnL/r+2B4ATTYG5t6rrYNYaDqLmrwxrom+2t6/LSSpQAGXET8fhCs4NMQDp plli30fHmZBP3mSRijyNAqrptKeIO1zELTuk78hI3wcTH5pwTyZAMiCEddxrrwOynWHr C3EjnMzAlnS5HR5gPbxTfoV6xrwOBpdzFpLNk+Mt8TN8jxAfOz9yPqaH1Oc9sT19ooSG BNgw== 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 :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:ironport-sdr :ironport-sdr; bh=w7N1mBythAiDvYovD5vUU/3spKxKVV7OYPRZ5T7MgW8=; b=i3Z5Mjnt+GxnvAad/7+pmVcOFxpTKFXGk79KcemS/pyRZb8TGXc1F263oqQ4ey2m40 2od4VV94Mc49N5LvLv/5XuQYqrzHU2t8AM/ry8l3AlwUdrcBj8b1GilUkPb/Z0rs3ZpE hn7AqH1I03FcN5olsZvCY+FsnIhzKs9t+F5r/5EOOj3zs+igHGTWPfsWHZpz38Etpq7o MmQKO6Zmc/3mIOuzc9oHNXkC6FsI5f42nJUjt6h+Ibo4CfJ6jdOSRkOrV+r4dLduMCrG /KlDPT1eJ2ZdPEtuquMqNUcMCa+8ODo6IUT4ACvXs6Cd2SPOQYoGCZ6XEN/GhRleidR/ vGWQ== 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 m14si2704474eds.454.2020.09.02.09.13.06; Wed, 02 Sep 2020 09:13:29 -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 S1727872AbgIBQKS (ORCPT + 99 others); Wed, 2 Sep 2020 12:10:18 -0400 Received: from mga12.intel.com ([192.55.52.136]:54567 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726293AbgIBQKP (ORCPT ); Wed, 2 Sep 2020 12:10:15 -0400 IronPort-SDR: pTlYTrPte78yWv7EsbcamGLtbomhEQ2xXyX5iiWnQIWxxhMOdGy/FMWOfD/0dIAWwOGio6rBqp udCDY098iAeA== X-IronPort-AV: E=McAfee;i="6000,8403,9732"; a="136936699" X-IronPort-AV: E=Sophos;i="5.76,383,1592895600"; d="scan'208";a="136936699" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2020 09:10:14 -0700 IronPort-SDR: z7oVRryQh/ClvKbs+i9o24T4ivjV7OmRQjFOvPMU7sRVdfGLKDdgp/Ru5lhwJWC/pV1wW0GNPE p6CXSVkxosHg== X-IronPort-AV: E=Sophos;i="5.76,383,1592895600"; d="scan'208";a="446576484" Received: from sjchrist-ice.jf.intel.com (HELO sjchrist-ice) ([10.54.31.34]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2020 09:10:14 -0700 Date: Wed, 2 Sep 2020 09:10:12 -0700 From: Sean Christopherson To: Haitao Huang 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 Message-ID: <20200902161012.GD11695@sjchrist-ice> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?