Thread (77 messages) 77 messages, 8 authors, 2019-06-14

RE: [RFC PATCH 3/9] x86/sgx: Allow userspace to add multiple pages in single ioctl()

From: Xing, Cedric <hidden>
Date: 2019-06-04 22:02:31
Also in: lkml, selinux

From: Andy Lutomirski [mailto:luto@kernel.org]
Sent: Tuesday, June 04, 2019 1:18 PM

On Mon, Jun 3, 2019 at 1:39 PM Sean Christopherson
[off-list ref] wrote:
quoted
On Mon, Jun 03, 2019 at 01:08:04PM -0700, Sean Christopherson wrote:
quoted
On Sun, Jun 02, 2019 at 11:26:09PM -0700, Xing, Cedric wrote:
quoted
quoted
From: Christopherson, Sean J
Sent: Friday, May 31, 2019 4:32 PM

+/**
+ * sgx_ioc_enclave_add_pages - handler for
+%SGX_IOC_ENCLAVE_ADD_PAGES
+ *
+ * @filep:       open file to /dev/sgx
+ * @cmd: the command value
+ * @arg: pointer to an &sgx_enclave_add_page instance
+ *
+ * Add a range of pages to an uninitialized enclave (EADD), and
+optionally
+ * extend the enclave's measurement with the contents of the
page (EEXTEND).
quoted
quoted
quoted
quoted
+ * The range of pages must be virtually contiguous.  The
+SECINFO and
+ * measurement maskare applied to all pages, i.e. pages with
+different
+ * properties must be added in separate calls.
+ *
+ * EADD and EEXTEND are done asynchronously via worker threads.
+A successful
+ * sgx_ioc_enclave_add_page() only indicates the pages have
+been added to the
+ * work queue, it does not guarantee adding the pages to the
+enclave will
+ * succeed.
+ *
+ * Return:
+ *   0 on success,
+ *   -errno otherwise
+ */
+static long sgx_ioc_enclave_add_pages(struct file *filep,
unsigned int cmd,
quoted
quoted
quoted
quoted
+                               unsigned long arg) {  struct
+sgx_enclave_add_pages *addp = (void *)arg;  struct sgx_encl
+*encl = filep->private_data;  struct sgx_secinfo secinfo;
+unsigned int i;  int ret;
+
+ if (copy_from_user(&secinfo, (void __user *)addp->secinfo,
+                    sizeof(secinfo)))
+         return -EFAULT;
+
+ for (i = 0, ret = 0; i < addp->nr_pages && !ret; i++) {
+         if (signal_pending(current))
+                 return -ERESTARTSYS;
If interrupted, how would user mode code know how many pages have
been EADD'ed?
quoted
quoted
Hmm, updating nr_pages would be fairly simple and shouldn't confuse
userspace, e.g. as opposed to overloading the return value.
Or maybe update @addr and @src as well?  That would allow userspace to
re-invoke the ioctl() without having to modify the struct.
If you're going to use -ERESTARTSYS, that's the way to go.  -EINTR would
be an alternative.  A benefit of -ERESTARTSYS is that, with -EINTR, it
wouldn't be that surprising for user code to simply fail to handle it.
-EINTR means the call was interrupted before anything could be done. Am I correct?

But in this case some pages have been processed already so I guess we cannot return any error code. I think it more reasonable to return the number of pages (or bytes) processed.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help