[intel-sgx-kernel-dev,v5,3/8] intel_sgx: fix error resolution in SGX_IOC_ENCLAVE_INIT
diff mbox

Message ID 20161202200018.25552-4-jarkko.sakkinen@linux.intel.com
State New
Headers show

Commit Message

Jarkko Sakkinen Dec. 2, 2016, 8 p.m. UTC
From: Sean Christopherson <sean.j.christopherson@intel.com>

The ioctl now always return -EBUSY when something fails. This is not a
good idea because it advices the user space always to retry.

This commit changes the error resolution in a way that the default error
code is instead -EFAULT. Only in the case of SGX_UNMASKED_EVENT (after
several retries of EINIT) we will return -EBUSY. We also change the
ioctl to return -EPERM when the sigstruct is not properly authenticated.

[jarkko.sakkinen@linux.intel.com: updated patch to return EPERM and
 rewrote the commit message to properly explain the problem statement
 and the solution.]

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 drivers/platform/x86/intel_sgx_ioctl.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

Patch
diff mbox

diff --git a/drivers/platform/x86/intel_sgx_ioctl.c b/drivers/platform/x86/intel_sgx_ioctl.c
index db17b9f..b377200 100644
--- a/drivers/platform/x86/intel_sgx_ioctl.c
+++ b/drivers/platform/x86/intel_sgx_ioctl.c
@@ -824,7 +824,22 @@  static int __sgx_encl_init(struct sgx_encl *encl, char *sigstruct,
 out:
 	if (ret) {
 		sgx_dbg(encl, "EINIT returned %d\n", ret);
-		ret = -EBUSY;
+		switch (ret) {
+		case SGX_UNMASKED_EVENT:
+			ret = -EBUSY;
+			break;
+		case SGX_INVALID_SIG_STRUCT:
+		case SGX_INVALID_ATTRIBUTE:
+		case SGX_INVALID_MEASUREMENT:
+		case SGX_INVALID_SIGNATURE:
+		case SGX_INVALID_LICENSE:
+		case SGX_INVALID_CPUSVN:
+			ret = -EPERM;
+			break;
+		default:
+			ret = -EFAULT;
+			break;
+		}
 	} else {
 		encl->flags |= SGX_ENCL_INITIALIZED;