Browse Source

[SGX PAL] Improving the warning messages when the kernel modules are not loaded, or the WRFSBASE instruction is not enabled.

Signed-off-by: Chia-Che Tsai <chiache@tamu.edu>
Chia-Che Tsai 5 years ago
parent
commit
f54440eb1a
2 changed files with 16 additions and 10 deletions
  1. 15 6
      Pal/src/host/Linux-SGX/sgx_framework.c
  2. 1 4
      Pal/src/host/Linux-SGX/sgx_main.c

+ 15 - 6
Pal/src/host/Linux-SGX/sgx_framework.c

@@ -19,11 +19,19 @@ void * zero_page;
 int open_gsgx(void)
 {
     gsgx_device = INLINE_SYSCALL(open, 3, GSGX_FILE, O_RDWR, 0);
-    if (IS_ERR(gsgx_device))
+    if (IS_ERR(gsgx_device)) {
+        SGX_DBG(DBG_E, "Cannot open device " GSGX_FILE ". Please make sure the"
+                " \'graphene_sgx\' kernel module is loaded.\n");
         return -ERRNO(gsgx_device);
+    }
+
     isgx_device = INLINE_SYSCALL(open, 3, ISGX_FILE, O_RDWR, 0);
-    if (IS_ERR(isgx_device))
+    if (IS_ERR(isgx_device)) {
+        SGX_DBG(DBG_E, "Cannot open device " ISGX_FILE ". Please make sure the"
+                " Intel SGX kernel module is loaded.\n");
         return -ERRNO(isgx_device);
+    }
+
     return 0;
 }
 
@@ -101,14 +109,15 @@ static size_t get_ssaframesize (uint64_t xfrm)
 
 int check_wrfsbase_support (void)
 {
-    if (gsgx_device == -1)
-        return -EACCES;
-
     uint32_t cpuinfo[4];
     cpuid(7, 0, cpuinfo);
 
-    if (!(cpuinfo[1] & 0x1))
+    if (!(cpuinfo[1] & 0x1)) {
+        SGX_DBG(DBG_E, "The WRFSBASE instruction is not permitted on this"
+                " platform. Please make sure the \'graphene_sgx\' kernel module"
+                " is loaded properly.\n");
         return 0;
+    }
 
     return 1;
 }

+ 1 - 4
Pal/src/host/Linux-SGX/sgx_main.c

@@ -681,11 +681,8 @@ static int load_enclave (struct pal_enclave * enclave,
 #endif
 
     ret = open_gsgx();
-    if (ret < 0) {
-        SGX_DBG(DBG_E, "cannot open device /dev/gsgx, possibly the kernel "
-                "module is not loaded.\n");
+    if (ret < 0)
         return ret;
-    }
 
     ret = check_wrfsbase_support();
     if (ret < 0)