Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2803426ybt; Fri, 3 Jul 2020 20:33:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEdpcIC0Gxucr/PIUmLCaB+lpbiqmuAmnXjs3w/xWsouYW9SRe3OoSjVxGVo5JQ6WA0MiA X-Received: by 2002:a17:906:824c:: with SMTP id f12mr34280551ejx.443.1593833633330; Fri, 03 Jul 2020 20:33:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593833633; cv=none; d=google.com; s=arc-20160816; b=dQkQBFzx+8f0rO4Ljc2VUJXmvytBEArDxI2J3euZ0JB9H86nLOUMJcdX748NEGzH4E OJu3M11/YvbI+75pNWUZbet0vTzK5YBTAH50Cr5bMA9lED48fpO7cFF7eLHOGrewFtQm dTGnIavTC+mR93vCp3XH/LbWnV4Dg/WNROp0h7txVOy9us3XCVOApfn1/bBOFypKZLnd fTfrI4ZTtXpOfl+W5kZMu2W30cO+6UMMq8OsRzj7kLvCaHjh6iIjkhUwJ5CYeip4jzhU GgTIzc6xu14aTnFnkmqXRUGqdT+KE7VQI/Xnx+a0AuDQxuuXvDWWbVJFmsFJ8QMFgq78 wXrw== 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=EOUm9qagVIJkNwVhZMOE4Kpuw9t7es50Hk3F2FKQVuo=; b=IK4uBIIjukZ4IUW7ZiKVDr0khM8sreFP/0JqjLsIu19MhaRCuzlRwn2GqxHk5ItZV0 cdnm0SsVmmapE8+rVPNw5EuYwthGfw2J9xMENWP6Kp9VDAk8RZeen6IL/hzgU52185uC wgh94Uy28v9bngbU3rVHSo9ftG37MxTyNn8zXlX4o2mj5xOORvAtKMqYti5Jf6MS1flo 2EfZlSDgnKCLsc0zTOvHWsSPgNd1NDDKvqBiVu2/wATj7sSPwruZ5DK9iYJmX/7MeHvp UgY6+sgrbqQ/KAHtR9RFu8eGpMF93BL6RVk0sG9VlPTWx9j9b66+nmfXkLOQao71z3jG hHbg== 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 bu19si8987835edb.468.2020.07.03.20.33.30; Fri, 03 Jul 2020 20:33:53 -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 S1727063AbgGDDb2 (ORCPT + 99 others); Fri, 3 Jul 2020 23:31:28 -0400 Received: from mga03.intel.com ([134.134.136.65]:39715 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726501AbgGDDb1 (ORCPT ); Fri, 3 Jul 2020 23:31:27 -0400 IronPort-SDR: IN3AXyWv1h7g810kGPi06xjmhEO6V8Jte2eAsIZ7uZHBCB61XSwCl2M89bLTS9OXvME8gk3Kl4 I0/R+QhQdjJg== X-IronPort-AV: E=McAfee;i="6000,8403,9671"; a="147239518" X-IronPort-AV: E=Sophos;i="5.75,310,1589266800"; d="scan'208";a="147239518" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jul 2020 20:31:26 -0700 IronPort-SDR: JlMMqkTiFk8Mk98DqTZ8i8/NJpMhQO7FUiSWpuFrinD4zff6ep+DUsAsP4tSpnVXoWfqKKGudK kweN9iMAlOQw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,310,1589266800"; d="scan'208";a="456075034" Received: from winzenbu-mobl1.ger.corp.intel.com (HELO localhost) ([10.249.41.221]) by orsmga005.jf.intel.com with ESMTP; 03 Jul 2020 20:31:12 -0700 Date: Sat, 4 Jul 2020 06:31:10 +0300 From: Jarkko Sakkinen To: Sean Christopherson Cc: x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Jethro Beekman , Haitao Huang , 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, 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 v33 11/21] x86/sgx: Linux Enclave Driver Message-ID: <20200704033025.GA144756@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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200702035902.GC1819@linux.intel.com> 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 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; /Jarkko