Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1254114pxk; Fri, 4 Sep 2020 05:04:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0hwWDZOSQqp053O1CVJEA33+hIvbASKGV6wIYp/kgIczEg4WJ6qoO7N8AhWkpliOX8GS4 X-Received: by 2002:a17:906:2cc2:: with SMTP id r2mr6911688ejr.482.1599221088513; Fri, 04 Sep 2020 05:04:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599221088; cv=none; d=google.com; s=arc-20160816; b=kXHHAeTRPqwTYhQFf11QRKWsB/nUfe6bT3yrJsiDm3oXGBvqv+fC6N4RtL0JCwxMUq PaV9K4l5Z3z4N3XW+7GXjR4RgQMQiFVAAtUaowbgp6tkXMpkQpQ0ZJfvWW0vlp9yssho UEjp5KxVKecGZOMdNXoQemf1ViilsPsEIyUrnHZ7gSxBQKqfgwTR8uM8tE3oHg/1mLEI PO6sBfrfn4kCaoePQ9VY7Cl0cvIkS7x24WPKBU/+Ix7zRA9wRcSSFFUa64txPB0T8ZAM ++OF85rw/PSBz6O8PPf4fBH81DKlWH8uKDMF9fhM4CLVdN+oo70wVUVf6mp7Vqqpsa9G EalQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:ironport-sdr :ironport-sdr; bh=YuoV7kdANyWU0pAwdh0cCYRMe5j/SxlwCZWy6zgHvkc=; b=eAhxGg39HXGZ221OuTS1sFvAeko06CfSayjTSHn1fyBx+EioT0UT8/kkyFwhLbEfQY plLUys1aPyDmMHKhoxTilzIrWccFAJfrgTtx+5XQ1Zx91bqYje1n87X8IFtlbuJilRWD FgYXs33g+3WJFD5SBVNFI0oftVdwL+PETRrtxanczCMIjVCqoOmd1mzTPGzfhrZdGUBJ acc9TjiM6or0kXBQ/bDU2lC6WPrgLxCeGHMXDNq/6urUUN6MwoFmSRZbs0Nx8NdcSGkK QtzFl4/7UHhm+3SDLMWZyqNPRhL+3c0LCQhw5cTjHc/tWGLYOd4u/6NDS0ajr80+5kuB nIyg== 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 t16si3944389ejt.27.2020.09.04.05.04.23; Fri, 04 Sep 2020 05:04:48 -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 S1730021AbgIDMDO (ORCPT + 99 others); Fri, 4 Sep 2020 08:03:14 -0400 Received: from mga06.intel.com ([134.134.136.31]:7973 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730114AbgIDMBv (ORCPT ); Fri, 4 Sep 2020 08:01:51 -0400 IronPort-SDR: 1I8Rtwh4GWOdeWX7J7eIEpl+QU7QjKZ9Egp+qCty8QrPl9PLcuDF5Vunz+D2G0TgvPl1hv2yM1 YSFOXsT3oDgQ== X-IronPort-AV: E=McAfee;i="6000,8403,9733"; a="219283543" X-IronPort-AV: E=Sophos;i="5.76,389,1592895600"; d="scan'208";a="219283543" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Sep 2020 05:01:34 -0700 IronPort-SDR: JBhmnVDQJvbdd61JWWR8kZUG+owj8Bw5jHT4ua8fCs3yJvwjj2wBZCZEB0ACc/MeYpvQb5GIuI Z1Fx+DDEHNdg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,389,1592895600"; d="scan'208";a="478460799" Received: from pipper-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.56.104]) by orsmga005.jf.intel.com with ESMTP; 04 Sep 2020 05:01:27 -0700 Date: Fri, 4 Sep 2020 15:01:26 +0300 From: Jarkko Sakkinen To: Haitao Huang Cc: Sean Christopherson , 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: <20200904120126.GB39023@linux.intel.com> 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: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo 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 >. > > Thanks > Haitao Thans a lot! I added this changelog entry to the v37 log: * Fixed off-by-one error in a size calculation: https://github.com/intel/SGXDataCenterAttestationPrimitives/commit/e44cc238becf584cc079aef40b557c6af9a03f38 Given the Boris' earlier feedback I xref every changelog entry in v37 changelog. Then it is also less time consuming to spot if something is missing. /Jarkko