All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: linux-sgx@vger.kernel.org
Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
	Sean Christopherson <sean.j.christpherson@intel.com>,
	Shay Katz-zamir <shay.katz-zamir@intel.com>,
	Serge Ayoun <serge.ayoun@intel.com>
Subject: [PATCH 3/5] x86/sgx: Make sgx_validate_secinfo() more readable
Date: Mon, 19 Aug 2019 18:25:42 +0300	[thread overview]
Message-ID: <20190819152544.7296-4-jarkko.sakkinen@linux.intel.com> (raw)
In-Reply-To: <20190819152544.7296-1-jarkko.sakkinen@linux.intel.com>

Split the huge conditional statement to three separate ones in
order to make it easier to understand what is going on in the
validation code.

Cc: Sean Christopherson <sean.j.christpherson@intel.com>
Cc: Shay Katz-zamir <shay.katz-zamir@intel.com>
Cc: Serge Ayoun <serge.ayoun@intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 arch/x86/kernel/cpu/sgx/driver/ioctl.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/sgx/driver/ioctl.c b/arch/x86/kernel/cpu/sgx/driver/ioctl.c
index d5f326411df0..99b1b9776c3a 100644
--- a/arch/x86/kernel/cpu/sgx/driver/ioctl.c
+++ b/arch/x86/kernel/cpu/sgx/driver/ioctl.c
@@ -415,10 +415,15 @@ static int sgx_validate_secinfo(struct sgx_secinfo *secinfo)
 	u64 page_type = secinfo->flags & SGX_SECINFO_PAGE_TYPE_MASK;
 	u64 perm = secinfo->flags & SGX_SECINFO_PERMISSION_MASK;
 
-	if ((secinfo->flags & SGX_SECINFO_RESERVED_MASK) ||
-	    ((perm & SGX_SECINFO_W) && !(perm & SGX_SECINFO_R)) ||
-	    (page_type != SGX_SECINFO_TCS && page_type != SGX_SECINFO_TRIM &&
-	     page_type != SGX_SECINFO_REG))
+	if ((page_type != SGX_SECINFO_REG &&
+	     page_type != SGX_SECINFO_TCS &&
+	     page_type != SGX_SECINFO_TRIM))
+		return -EINVAL;
+
+	if ((perm & SGX_SECINFO_W) && !(perm & SGX_SECINFO_R))
+		return -EINVAL;
+
+	if (secinfo->flags & SGX_SECINFO_RESERVED_MASK)
 		return -EINVAL;
 
 	if (memchr_inv(secinfo->reserved, 0, SGX_SECINFO_RESERVED_SIZE))
-- 
2.20.1


  parent reply	other threads:[~2019-08-19 15:26 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-19 15:25 [PATCH 0/5] x86/sgx: Improve permission handing Jarkko Sakkinen
2019-08-19 15:25 ` [PATCH 1/5] x86/sgx: Document permission handling better Jarkko Sakkinen
2019-08-22  3:43   ` Sean Christopherson
2019-08-22 16:04     ` Jarkko Sakkinen
2019-08-19 15:25 ` [PATCH 2/5] x86/sgx: Use memchr_inv() in sgx_validate_secinfo() Jarkko Sakkinen
2019-08-22  3:47   ` Sean Christopherson
2019-08-22 16:20     ` Jarkko Sakkinen
2019-08-19 15:25 ` Jarkko Sakkinen [this message]
2019-08-22  3:48   ` [PATCH 3/5] x86/sgx: Make sgx_validate_secinfo() more readable Sean Christopherson
2019-08-22 16:26     ` Jarkko Sakkinen
2019-08-22 10:39   ` Ayoun, Serge
2019-08-22 16:45     ` Jarkko Sakkinen
2019-08-19 15:25 ` [PATCH 4/5] x86/sgx: Validate TCS permssions in sgx_validate_secinfo() Jarkko Sakkinen
2019-08-21 18:45   ` Jarkko Sakkinen
2019-08-22 11:33     ` Ayoun, Serge
2019-08-22 14:27       ` Sean Christopherson
2019-08-22 16:46       ` Jarkko Sakkinen
2019-08-22 16:59         ` Jarkko Sakkinen
2019-08-22  3:55   ` Sean Christopherson
2019-08-22 16:31     ` Jarkko Sakkinen
2019-08-22 16:34       ` Sean Christopherson
2019-08-23  0:39         ` Jarkko Sakkinen
2019-08-23  0:57           ` Jarkko Sakkinen
2019-08-23  2:05             ` Sean Christopherson
2019-08-23 13:41               ` Jarkko Sakkinen
2019-08-22 16:38       ` Jarkko Sakkinen
2019-08-19 15:25 ` [PATCH 5/5] x86/sgx: Rename vm_prot_bits as max_vm_flags Jarkko Sakkinen
2019-08-22  4:00   ` Sean Christopherson
2019-08-22 16:43     ` 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=20190819152544.7296-4-jarkko.sakkinen@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=linux-sgx@vger.kernel.org \
    --cc=sean.j.christpherson@intel.com \
    --cc=serge.ayoun@intel.com \
    --cc=shay.katz-zamir@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.