diff mbox

[intel-sgx-kernel-dev] intel_sgx: fail if CPUID does not give correct ranges

Message ID 20170628222527.21316-1-jarkko.sakkinen@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jarkko Sakkinen June 28, 2017, 10:25 p.m. UTC
The driver init should not continue in a broken environment.

Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 drivers/platform/x86/intel_sgx/sgx_main.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
diff mbox

Patch

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 <jarkko.sakkinen@linux.intel.com>");
 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);
 }