public inbox for linux-sgx@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: jarkko@kernel.org
Cc: linux-sgx@vger.kernel.org
Subject: [bug report] x86/sgx: Add SGX_IOC_ENCLAVE_ADD_PAGES
Date: Wed, 2 Dec 2020 17:14:26 +0300	[thread overview]
Message-ID: <X8ehQssnslm194ld@mwanda> (raw)

Hello Jarkko Sakkinen,

The patch c6d26d370767: "x86/sgx: Add SGX_IOC_ENCLAVE_ADD_PAGES" from
Nov 13, 2020, leads to the following static checker warning:

	arch/x86/kernel/cpu/sgx/ioctl.c:466 sgx_ioc_enclave_add_pages()
	error: uninitialized symbol 'ret'.

arch/x86/kernel/cpu/sgx/ioctl.c
   413  static long sgx_ioc_enclave_add_pages(struct sgx_encl *encl, void __user *arg)
   414  {
   415          struct sgx_enclave_add_pages add_arg;
   416          struct sgx_secinfo secinfo;
   417          unsigned long c;
   418          int ret;
   419  
   420          if (!test_bit(SGX_ENCL_CREATED, &encl->flags) ||
   421              test_bit(SGX_ENCL_INITIALIZED, &encl->flags))
   422                  return -EINVAL;
   423  
   424          if (copy_from_user(&add_arg, arg, sizeof(add_arg)))
   425                  return -EFAULT;
   426  
   427          if (!IS_ALIGNED(add_arg.offset, PAGE_SIZE) ||
   428              !IS_ALIGNED(add_arg.src, PAGE_SIZE))
   429                  return -EINVAL;
   430  
   431          if (add_arg.length & (PAGE_SIZE - 1))
   432                  return -EINVAL;
   433  
   434          if (add_arg.offset + add_arg.length - PAGE_SIZE >= encl->size)
   435                  return -EINVAL;
   436  
   437          if (copy_from_user(&secinfo, (void __user *)add_arg.secinfo,
   438                             sizeof(secinfo)))
   439                  return -EFAULT;
   440  
   441          if (sgx_validate_secinfo(&secinfo))
   442                  return -EINVAL;
   443  
   444          for (c = 0 ; c < add_arg.length; c += PAGE_SIZE) {

If the user passes in an "add_arg.length" value of zero then "ret" isn't
initialized.

   445                  if (signal_pending(current)) {
   446                          if (!c)
   447                                  ret = -ERESTARTSYS;
   448  
   449                          break;
   450                  }
   451  
   452                  if (need_resched())
   453                          cond_resched();
   454  
   455                  ret = sgx_encl_add_page(encl, add_arg.src + c, add_arg.offset + c,
   456                                          &secinfo, add_arg.flags);
   457                  if (ret)
   458                          break;
   459          }
   460  
   461          add_arg.count = c;
   462  
   463          if (copy_to_user(arg, &add_arg, sizeof(add_arg)))
   464                  return -EFAULT;
   465  
   466          return ret;
                ^^^^^^^^^^

   467  }

regards,
dan carpenter

             reply	other threads:[~2020-12-02 14:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-02 14:14 Dan Carpenter [this message]
2020-12-02 16:23 ` [bug report] x86/sgx: Add SGX_IOC_ENCLAVE_ADD_PAGES Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=X8ehQssnslm194ld@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=jarkko@kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox