Skip to contentSkip to conversation

x86/sgx: Remove checks for platform limits from sgx_validate_secs()

PATCH Superseded Jarkko Sakkinen 3 participants 7 messages Oct 5, 2020 – Oct 6, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/sgx: Remove checks for platform limits from sgx_validate_secs()

Remove from sgx_validate_secs():

	if (secs->miscselect & sgx_misc_reserved_mask ||
	    secs->attributes & sgx_attributes_reserved_mask ||
	    secs->xfrm & sgx_xfrm_reserved_mask)
		return -EINVAL;

SECS can surpass the platform limits because it's the SIGSTRUCT that defines the limits that are used at run-time.

What SECS does is that it defines the overall limits that must apply for any platform, i.e. SECS limits and platform limits are orthogonal. They are not dependent.

Cc Sean Christopherson <[email protected]>
Cc Jethro Beekman <[email protected]>
Cc Dave Hansen <[email protected]>
---
 arch/x86/kernel/cpu/sgx/ioctl.c | 5 -----
 1 file changed, 5 deletions(-)
arch/x86/kernel/cpu/sgx/ioctl.c +0 -5
index 6b3cc8483008..008752cb54f0 100644
@@ -86,11 +86,6 @@ static int sgx_validate_secs(const struct sgx_secs *secs)
 	if (secs->base & (secs->size - 1))
 		return -EINVAL;
 
-	if (secs->miscselect & sgx_misc_reserved_mask ||
-	    secs->attributes & sgx_attributes_reserved_mask ||
-	    secs->xfrm & sgx_xfrm_reserved_mask)
-		return -EINVAL;
-
 	if (secs->size > max_size)
 		return -EINVAL;
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 14 lines · Jarkko Sakkinen

Remove from sgx_validate_secs():

	if (secs->miscselect & sgx_misc_reserved_mask ||
	    secs->attributes & sgx_attributes_reserved_mask ||
	    secs->xfrm & sgx_xfrm_reserved_mask)
		return -EINVAL;

SECS can surpass the platform limits because it's the SIGSTRUCT that defines the limits that are used at run-time.

What SECS does is that it defines the overall limits that must apply for any platform, i.e. SECS limits and platform limits are orthogonal. They are not dependent.

Quoted 5 lines
Cc Sean Christopherson <[email protected]>
Cc Jethro Beekman <[email protected]>
Cc Dave Hansen <[email protected]>

I think I got this now.

I think it would be less confusing if the variables were renamed as:

- sgx_cpu_misc
- sgx_cpu_attributes
- sgx_cpu_xfrm

These names nail their role better and do not imply any possible dependency with SIGSTRUCT masks.

'cpu' is better than 'platform' because it is more exact.

Does anyone mind if I do these renames?

/Jarkko

Quoted 23 lines
---
 arch/x86/kernel/cpu/sgx/ioctl.c | 5 -----
 1 file changed, 5 deletions(-)
arch/x86/kernel/cpu/sgx/ioctl.c +0 -5
index 6b3cc8483008..008752cb54f0 100644
@@ -86,11 +86,6 @@ static int sgx_validate_secs(const struct sgx_secs *secs)
 	if (secs->base & (secs->size - 1))
 		return -EINVAL;
 
-	if (secs->miscselect & sgx_misc_reserved_mask ||
-	    secs->attributes & sgx_attributes_reserved_mask ||
-	    secs->xfrm & sgx_xfrm_reserved_mask)
-		return -EINVAL;
-
 	if (secs->size > max_size)
 		return -EINVAL;
 
Signature · 1 line
2.25.1
#2 lore raw
In reply to Jarkko Sakkinen
Quoted 29 lines · Jarkko Sakkinen

Remove from sgx_validate_secs():

	if (secs->miscselect & sgx_misc_reserved_mask ||
	    secs->attributes & sgx_attributes_reserved_mask ||
	    secs->xfrm & sgx_xfrm_reserved_mask)
		return -EINVAL;

SECS can surpass the platform limits because it's the SIGSTRUCT that defines the limits that are used at run-time.

What SECS does is that it defines the overall limits that must apply for any platform, i.e. SECS limits and platform limits are orthogonal. They are not dependent.

Cc Sean Christopherson <[email protected]>
Cc Jethro Beekman <[email protected]>
Cc Dave Hansen <[email protected]>
---
 arch/x86/kernel/cpu/sgx/ioctl.c | 5 -----
 1 file changed, 5 deletions(-)
arch/x86/kernel/cpu/sgx/ioctl.c +0 -0
index 6b3cc8483008..008752cb54f0 100644
@@ -86,11 +86,6 @@ static int sgx_validate_secs(const struct sgx_secs  
 *secs)

arch/x86/kernel/cpu/sgx/ioctl.c static int sgx_validate_secs(const struct sgx_secs · line 91

Quoted 10 lines
arch/x86/kernel/cpu/sgx/ioctl.c +0 -5
 	if (secs->base & (secs->size - 1))
 		return -EINVAL;
-	if (secs->miscselect & sgx_misc_reserved_mask ||
-	    secs->attributes & sgx_attributes_reserved_mask ||
-	    secs->xfrm & sgx_xfrm_reserved_mask)
-		return -EINVAL;
-
 	if (secs->size > max_size)
 		return -EINVAL;
 

Looks good to me.
Thanks
Haitao

#3 lore raw
Quoted 39 lines · Haitao Huang
Quoted 36 lines · Jarkko Sakkinen

Remove from sgx_validate_secs():

	if (secs->miscselect & sgx_misc_reserved_mask ||
	    secs->attributes & sgx_attributes_reserved_mask ||
	    secs->xfrm & sgx_xfrm_reserved_mask)
		return -EINVAL;

SECS can surpass the platform limits because it's the SIGSTRUCT that defines the limits that are used at run-time.

What SECS does is that it defines the overall limits that must apply for any platform, i.e. SECS limits and platform limits are orthogonal. They are not dependent.

Cc Sean Christopherson <[email protected]>
Cc Jethro Beekman <[email protected]>
Cc Dave Hansen <[email protected]>
---
 arch/x86/kernel/cpu/sgx/ioctl.c | 5 -----
 1 file changed, 5 deletions(-)
arch/x86/kernel/cpu/sgx/ioctl.c +0 -4
index 6b3cc8483008..008752cb54f0 100644
@@ -86,11 +86,6 @@ static int sgx_validate_secs(const struct sgx_secs
 *secs)
 	if (secs->base & (secs->size - 1))
 		return -EINVAL;
-	if (secs->miscselect & sgx_misc_reserved_mask ||
-	    secs->attributes & sgx_attributes_reserved_mask ||
-	    secs->xfrm & sgx_xfrm_reserved_mask)
-		return -EINVAL;
Quoted 8 lines

arch/x86/kernel/cpu/sgx/ioctl.c static int sgx_validate_secs(const struct sgx_secs *secs) · line 91

Quoted 4 lines
arch/x86/kernel/cpu/sgx/ioctl.c +0 -1
-
 	if (secs->size > max_size)
 		return -EINVAL;
 

Looks good to me.
Thanks
Haitao

Thanks, I'll merge it then.

/JArkko

#4 lore raw
Quoted 49 lines · Jarkko Sakkinen
Quoted 39 lines · Haitao Huang
Quoted 36 lines · Jarkko Sakkinen

Remove from sgx_validate_secs():

	if (secs->miscselect & sgx_misc_reserved_mask ||
	    secs->attributes & sgx_attributes_reserved_mask ||
	    secs->xfrm & sgx_xfrm_reserved_mask)
		return -EINVAL;

SECS can surpass the platform limits because it's the SIGSTRUCT that defines the limits that are used at run-time.

What SECS does is that it defines the overall limits that must apply for any platform, i.e. SECS limits and platform limits are orthogonal. They are not dependent.

Cc Sean Christopherson <[email protected]>
Cc Jethro Beekman <[email protected]>
Cc Dave Hansen <[email protected]>
---
 arch/x86/kernel/cpu/sgx/ioctl.c | 5 -----
 1 file changed, 5 deletions(-)
arch/x86/kernel/cpu/sgx/ioctl.c +0 -4
index 6b3cc8483008..008752cb54f0 100644
@@ -86,11 +86,6 @@ static int sgx_validate_secs(const struct sgx_secs
 *secs)
 	if (secs->base & (secs->size - 1))
 		return -EINVAL;
-	if (secs->miscselect & sgx_misc_reserved_mask ||
-	    secs->attributes & sgx_attributes_reserved_mask ||
-	    secs->xfrm & sgx_xfrm_reserved_mask)
-		return -EINVAL;
Quoted 8 lines

arch/x86/kernel/cpu/sgx/ioctl.c static int sgx_validate_secs(const struct sgx_secs *secs) · line 91

Quoted 4 lines
arch/x86/kernel/cpu/sgx/ioctl.c +0 -1
-
 	if (secs->size > max_size)
 		return -EINVAL;
 

Looks good to me.
Thanks
Haitao

Quoted 1 line

Thanks, I'll merge it then.

You can't remove this wholesale, the kernel should still disallow access to features that are unknown to the kernel and/or are explicitly disallowed by the kernel. E.g. see SGX_ATTR_RESERVED_MASK and SGX_MISC_RESERVED_MASK.

Dropping sgx_xfrm_reserved_mask is ok because the CPU explicitly checks that XFRM is a strict subset of the current XCR0, though that makes me wonder what it does with XSS...

#5 lore raw
Quoted 52 lines · Sean Christopherson
Quoted 49 lines · Jarkko Sakkinen
Quoted 39 lines · Haitao Huang
Quoted 36 lines · Jarkko Sakkinen

Remove from sgx_validate_secs():

	if (secs->miscselect & sgx_misc_reserved_mask ||
	    secs->attributes & sgx_attributes_reserved_mask ||
	    secs->xfrm & sgx_xfrm_reserved_mask)
		return -EINVAL;

SECS can surpass the platform limits because it's the SIGSTRUCT that defines the limits that are used at run-time.

What SECS does is that it defines the overall limits that must apply for any platform, i.e. SECS limits and platform limits are orthogonal. They are not dependent.

Cc Sean Christopherson <[email protected]>
Cc Jethro Beekman <[email protected]>
Cc Dave Hansen <[email protected]>
---
 arch/x86/kernel/cpu/sgx/ioctl.c | 5 -----
 1 file changed, 5 deletions(-)
arch/x86/kernel/cpu/sgx/ioctl.c +0 -4
index 6b3cc8483008..008752cb54f0 100644
@@ -86,11 +86,6 @@ static int sgx_validate_secs(const struct sgx_secs
 *secs)
 	if (secs->base & (secs->size - 1))
 		return -EINVAL;
-	if (secs->miscselect & sgx_misc_reserved_mask ||
-	    secs->attributes & sgx_attributes_reserved_mask ||
-	    secs->xfrm & sgx_xfrm_reserved_mask)
-		return -EINVAL;
Quoted 8 lines

arch/x86/kernel/cpu/sgx/ioctl.c static int sgx_validate_secs(const struct sgx_secs *secs) · line 91

Quoted 4 lines
arch/x86/kernel/cpu/sgx/ioctl.c +0 -1
-
 	if (secs->size > max_size)
 		return -EINVAL;
 

Looks good to me.
Thanks
Haitao

Quoted 1 line

Thanks, I'll merge it then.

Quoted 7 lines

You can't remove this wholesale, the kernel should still disallow access to features that are unknown to the kernel and/or are explicitly disallowed by the kernel. E.g. see SGX_ATTR_RESERVED_MASK and SGX_MISC_RESERVED_MASK.

Dropping sgx_xfrm_reserved_mask is ok because the CPU explicitly checks that XFRM is a strict subset of the current XCR0, though that makes me wonder what it does with XSS...

If possible send a patch so I can get a changelog reference.

Only thing you need to put as long description is permlink to my response in this thread.

Thank you.

/Jarkko

#6 lore raw
Quoted 57 lines · Jarkko Sakkinen
Quoted 56 lines · Sean Christopherson
Quoted 49 lines · Jarkko Sakkinen
Quoted 39 lines · Haitao Huang
Quoted 36 lines · Jarkko Sakkinen

Remove from sgx_validate_secs():

	if (secs->miscselect & sgx_misc_reserved_mask ||
	    secs->attributes & sgx_attributes_reserved_mask ||
	    secs->xfrm & sgx_xfrm_reserved_mask)
		return -EINVAL;

SECS can surpass the platform limits because it's the SIGSTRUCT that defines the limits that are used at run-time.

What SECS does is that it defines the overall limits that must apply for any platform, i.e. SECS limits and platform limits are orthogonal. They are not dependent.

Cc Sean Christopherson <[email protected]>
Cc Jethro Beekman <[email protected]>
Cc Dave Hansen <[email protected]>
---
 arch/x86/kernel/cpu/sgx/ioctl.c | 5 -----
 1 file changed, 5 deletions(-)
arch/x86/kernel/cpu/sgx/ioctl.c +0 -4
index 6b3cc8483008..008752cb54f0 100644
@@ -86,11 +86,6 @@ static int sgx_validate_secs(const struct sgx_secs
 *secs)
 	if (secs->base & (secs->size - 1))
 		return -EINVAL;
-	if (secs->miscselect & sgx_misc_reserved_mask ||
-	    secs->attributes & sgx_attributes_reserved_mask ||
-	    secs->xfrm & sgx_xfrm_reserved_mask)
-		return -EINVAL;
Quoted 8 lines

arch/x86/kernel/cpu/sgx/ioctl.c static int sgx_validate_secs(const struct sgx_secs *secs) · line 91

Quoted 4 lines
arch/x86/kernel/cpu/sgx/ioctl.c +0 -1
-
 	if (secs->size > max_size)
 		return -EINVAL;
 

Looks good to me.
Thanks
Haitao

Quoted 1 line

Thanks, I'll merge it then.

You can't remove this wholesale, the kernel should still disallow access to features that are unknown to the kernel and/or are explicitly disallowed by the kernel. E.g. see SGX_ATTR_RESERVED_MASK and SGX_MISC_RESERVED_MASK.

Quoted 8 lines
Quoted 3 lines

Dropping sgx_xfrm_reserved_mask is ok because the CPU explicitly checks that XFRM is a strict subset of the current XCR0, though that makes me wonder what it does with XSS...

If possible send a patch so I can get a changelog reference.

Only thing you need to put as long description is permlink to my response in this thread.

Sean, I can do the fix, don't worry about it but before I make a backlog entry I need to challenge this just a bit.

SIGSTRUCT will tell what features we want to run the enclave with, not SECS, so why you see it a problem that the features are not validated in SGX_IOC_ENCLAVE_CREATE? I.e. the enclave binary could potentially be used in different platforms with different kernel versions.

/Jarkko