diff mbox

[intel-sgx-kernel-dev,v6,4/8] intel_sgx: fix error resolution in SGX_IOC_ENCLAVE_INIT

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

Commit Message

Jarkko Sakkinen Dec. 4, 2016, 6:40 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>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 drivers/platform/x86/intel_sgx_ioctl.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
diff mbox

Patch

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;