From patchwork Wed Jun 28 22:25:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 9815609 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0F37C60383 for ; Wed, 28 Jun 2017 22:25:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05D9727F82 for ; Wed, 28 Jun 2017 22:25:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE6812844B; Wed, 28 Jun 2017 22:25:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EA5BC27F82 for ; Wed, 28 Jun 2017 22:25:39 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3C85321CB74C2; Wed, 28 Jun 2017 15:24:07 -0700 (PDT) X-Original-To: intel-sgx-kernel-dev@lists.01.org Delivered-To: intel-sgx-kernel-dev@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 23BCF21A00ACB for ; Wed, 28 Jun 2017 15:24:06 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jun 2017 15:25:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.40,277,1496127600"; d="scan'208"; a="1188223619" Received: from ksingh4-mobl2.amr.corp.intel.com (HELO localhost) ([10.252.0.244]) by fmsmga002.fm.intel.com with ESMTP; 28 Jun 2017 15:25:35 -0700 From: Jarkko Sakkinen To: intel-sgx-kernel-dev@lists.01.org Date: Thu, 29 Jun 2017 01:25:27 +0300 Message-Id: <20170628222527.21316-1-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.11.0 Subject: [intel-sgx-kernel-dev] [PATCH] intel_sgx: fail if CPUID does not give correct ranges X-BeenThere: intel-sgx-kernel-dev@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Project: Intel® Software Guard Extensions for Linux*: https://01.org/intel-software-guard-extensions" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kai.huang@intel.com MIME-Version: 1.0 Errors-To: intel-sgx-kernel-dev-bounces@lists.01.org Sender: "intel-sgx-kernel-dev" X-Virus-Scanned: ClamAV using ClamSMTP The driver init should not continue in a broken environment. Signed-off-by: Jarkko Sakkinen --- drivers/platform/x86/intel_sgx/sgx_main.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/platform/x86/intel_sgx/sgx_main.c b/drivers/platform/x86/intel_sgx/sgx_main.c index 962768d72546..8124d027e5d7 100644 --- a/drivers/platform/x86/intel_sgx/sgx_main.c +++ b/drivers/platform/x86/intel_sgx/sgx_main.c @@ -72,9 +72,6 @@ #define DRV_DESCRIPTION "Intel SGX Driver" #define DRV_VERSION "0.10" -#define ENCL_SIZE_MAX_64 (64ULL * 1024ULL * 1024ULL * 1024ULL) -#define ENCL_SIZE_MAX_32 (2ULL * 1024ULL * 1024ULL * 1024ULL) - MODULE_DESCRIPTION(DRV_DESCRIPTION); MODULE_AUTHOR("Jarkko Sakkinen "); MODULE_VERSION(DRV_VERSION); @@ -87,8 +84,8 @@ struct workqueue_struct *sgx_add_page_wq; #define SGX_MAX_EPC_BANKS 8 struct sgx_epc_bank sgx_epc_banks[SGX_MAX_EPC_BANKS]; int sgx_nr_epc_banks; -u64 sgx_encl_size_max_32 = ENCL_SIZE_MAX_32; -u64 sgx_encl_size_max_64 = ENCL_SIZE_MAX_64; +u64 sgx_encl_size_max_32; +u64 sgx_encl_size_max_64; u64 sgx_xfrm_mask = 0x3; u32 sgx_ssaframesize_tbl[64]; bool sgx_has_sgx2; @@ -310,12 +307,13 @@ static int sgx_drv_probe(struct platform_device *pdev) } cpuid_count(SGX_CPUID, 0x0, &eax, &ebx, &ecx, &edx); - if (edx & 0xFFFF) { + if (!(edx & 0xFFFF)) + return -ENODEV; + #ifdef CONFIG_X86_64 - sgx_encl_size_max_64 = 1ULL << ((edx >> 8) & 0xFF); + sgx_encl_size_max_64 = 1ULL << ((edx >> 8) & 0xFF); #endif - sgx_encl_size_max_32 = 1ULL << (edx & 0xFF); - } + sgx_encl_size_max_32 = 1ULL << (edx & 0xFF); return sgx_dev_init(&pdev->dev); }