Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1155613ybt; Wed, 1 Jul 2020 21:01:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4Hw6f9TiLYC6Y9bERGPf3ls6aTDL8NGwXOyVAP+VTvrAQuMFonyzzbS6PuKG9lvZwYTtH X-Received: by 2002:a17:906:4c2:: with SMTP id g2mr24488878eja.299.1593662507800; Wed, 01 Jul 2020 21:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593662507; cv=none; d=google.com; s=arc-20160816; b=H9NgcZSdtXWHuKpK9hwI3pOZOaNcJXmwtvSPrQ9nwoMpsIGvrkbjyvBVrtlclXdSsc NPR1TRnp+WgdeJ4CYh0rXX9uu4fnim0tZkpjvgb8mEeaTI/hIiZaLaDYmDFsmUjjL8he HhE58nPlStwrc1+NlappapITm5zkAFU4DuD3bzzX7KcRnRlyBW0+8JbpUp8KSlEjSeDz UMNwTbitCs/O5+289jrJ4+m+R8T9FnSuBL/boq/iGsjxcxdQhGLf1dWsJKXhVywbTpFs Bh+hcnsM0mGzy247K9PRXu7788TzeUHumsZPu7hxzV7pDxagYF29JNLdGBMsnUpjmOW7 YuzA== 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=Ubdt6tsL6g0hN0wUzFYB3GdpLSgknWm2JK8jxwBlGuE=; b=k14ZULphsXAABXvqDvh7eEJQiLinro4LDOkroVbnWoZTYiANFyJrWxhfMImK6ecTxC Np4lhJk+Li3Ub3Xx/3rLz4U8ZdvjyqB7IZtsLh7Y10TbuDdDTKzo81EYYUzDvSyZGBAM MZH6fNpSZHScEjn0iLYEQ8MAPNA8GBr6Hg+PKiajmHt/juSZiJB4T4HEafGZhJy4N++z BoD+2eDvDRLMC35yAPu9j3i09EflGL9Uctu4hIj+T+Ps3wdSxqwLlgyt6e5mZxemOT93 dXqGUUshurQxjgo7/ioT4EaEjcTqJ1Uj6o+hA/5B/+ewJs78Eg7q+s3/O79DER3/gG4z 1zeg== 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 x70si5706674ede.405.2020.07.01.21.01.24; Wed, 01 Jul 2020 21:01:47 -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 S1726345AbgGBD7D (ORCPT + 99 others); Wed, 1 Jul 2020 23:59:03 -0400 Received: from mga12.intel.com ([192.55.52.136]:26776 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726187AbgGBD7C (ORCPT ); Wed, 1 Jul 2020 23:59:02 -0400 IronPort-SDR: UeVKnAbzP9rV1gTs3a2u29CPmtIRCgtjMO1UdQtvlnfFX2evOWMfjqInDK8XFLHNaxyulKhd2e h0JTHWwqe8TQ== X-IronPort-AV: E=McAfee;i="6000,8403,9669"; a="126403730" X-IronPort-AV: E=Sophos;i="5.75,302,1589266800"; d="scan'208";a="126403730" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2020 20:59:02 -0700 IronPort-SDR: BVhIUUZ1L/xEqOBO26oXtglVzitgz3GWW+7g3i67tenBlNkARotauZWDCTJyDmhbtBaIFmo1cO c9Cf4XlxNByQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,302,1589266800"; d="scan'208";a="281818263" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.152]) by orsmga006.jf.intel.com with ESMTP; 01 Jul 2020 20:59:02 -0700 Date: Wed, 1 Jul 2020 20:59:02 -0700 From: Sean Christopherson To: Jarkko Sakkinen 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: <20200702035902.GC1819@linux.intel.com> References: <20200617220844.57423-1-jarkko.sakkinen@linux.intel.com> <20200617220844.57423-12-jarkko.sakkinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200617220844.57423-12-jarkko.sakkinen@linux.intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); } > + > + if (!(secs->xfrm & XFEATURE_MASK_FP) || > + !(secs->xfrm & XFEATURE_MASK_SSE) || > + (((secs->xfrm >> XFEATURE_BNDREGS) & 1) != > + ((secs->xfrm >> XFEATURE_BNDCSR) & 1))) > + return -EINVAL; > + > + if (!secs->ssa_frame_size || ssaframesize > secs->ssa_frame_size) > + return -EINVAL; > + > + if (memchr_inv(secs->reserved1, 0, sizeof(secs->reserved1)) || > + memchr_inv(secs->reserved2, 0, sizeof(secs->reserved2)) || > + memchr_inv(secs->reserved3, 0, sizeof(secs->reserved3)) || > + memchr_inv(secs->reserved4, 0, sizeof(secs->reserved4))) > + return -EINVAL; > + > + return 0; > +}