public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/sgx: Allow RW for TCS pages
@ 2022-03-19 16:30 Jarkko Sakkinen
  2022-03-28 20:28 ` Reinette Chatre
  0 siblings, 1 reply; 3+ messages in thread
From: Jarkko Sakkinen @ 2022-03-19 16:30 UTC (permalink / raw)
  To: linux-sgx
  Cc: Jarkko Sakkinen, Dave Hansen, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	H. Peter Anvin, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)

Not allowing to set RW for added TCS pages leads only to a special case
to be handled in the user space run-time. Thus, allow permissions to be
set RW. Originally, it would have probably made more sense to check up
that the permissions are RW.

Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
---
 arch/x86/kernel/cpu/sgx/ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c
index 83df20e3e633..f79761ad0400 100644
--- a/arch/x86/kernel/cpu/sgx/ioctl.c
+++ b/arch/x86/kernel/cpu/sgx/ioctl.c
@@ -215,7 +215,7 @@ static int sgx_validate_secinfo(struct sgx_secinfo *secinfo)
 	 * CPU will silently overwrite the permissions as zero, which means
 	 * that we need to validate it ourselves.
 	 */
-	if (pt == SGX_SECINFO_TCS && perm)
+	if (pt == SGX_SECINFO_TCS && (perm != 0 || perm != (PROT_READ | PROT_WRITE)))
 		return -EINVAL;
 
 	if (secinfo->flags & SGX_SECINFO_RESERVED_MASK)
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/sgx: Allow RW for TCS pages
  2022-03-19 16:30 [PATCH] x86/sgx: Allow RW for TCS pages Jarkko Sakkinen
@ 2022-03-28 20:28 ` Reinette Chatre
  2022-03-30 15:07   ` Jarkko Sakkinen
  0 siblings, 1 reply; 3+ messages in thread
From: Reinette Chatre @ 2022-03-28 20:28 UTC (permalink / raw)
  To: Jarkko Sakkinen, linux-sgx
  Cc: Dave Hansen, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), H. Peter Anvin,
	open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)

Hi Jarkko,

On 3/19/2022 9:30 AM, Jarkko Sakkinen wrote:
> Not allowing to set RW for added TCS pages leads only to a special case
> to be handled in the user space run-time. Thus, allow permissions to be
> set RW. Originally, it would have probably made more sense to check up
> that the permissions are RW.
> 
> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
> ---
>  arch/x86/kernel/cpu/sgx/ioctl.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c
> index 83df20e3e633..f79761ad0400 100644
> --- a/arch/x86/kernel/cpu/sgx/ioctl.c
> +++ b/arch/x86/kernel/cpu/sgx/ioctl.c
> @@ -215,7 +215,7 @@ static int sgx_validate_secinfo(struct sgx_secinfo *secinfo)
>  	 * CPU will silently overwrite the permissions as zero, which means
>  	 * that we need to validate it ourselves.
>  	 */
> -	if (pt == SGX_SECINFO_TCS && perm)
> +	if (pt == SGX_SECINFO_TCS && (perm != 0 || perm != (PROT_READ | PROT_WRITE)))
>  		return -EINVAL;
>  
>  	if (secinfo->flags & SGX_SECINFO_RESERVED_MASK)

The comments above sgx_ioc_enclave_add_pages() seem to indicate that zero 
permissions are required:

"A SECINFO for a TCS is required to always contain zero permissions because
 CPU silently zeros them. Allowing anything else would cause a mismatch in
 the measurement."

Reinette

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/sgx: Allow RW for TCS pages
  2022-03-28 20:28 ` Reinette Chatre
@ 2022-03-30 15:07   ` Jarkko Sakkinen
  0 siblings, 0 replies; 3+ messages in thread
From: Jarkko Sakkinen @ 2022-03-30 15:07 UTC (permalink / raw)
  To: Reinette Chatre
  Cc: linux-sgx, Dave Hansen, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	H. Peter Anvin, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)

On Mon, Mar 28, 2022 at 01:28:39PM -0700, Reinette Chatre wrote:
> Hi Jarkko,
> 
> On 3/19/2022 9:30 AM, Jarkko Sakkinen wrote:
> > Not allowing to set RW for added TCS pages leads only to a special case
> > to be handled in the user space run-time. Thus, allow permissions to be
> > set RW. Originally, it would have probably made more sense to check up
> > that the permissions are RW.
> > 
> > Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
> > ---
> >  arch/x86/kernel/cpu/sgx/ioctl.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/arch/x86/kernel/cpu/sgx/ioctl.c b/arch/x86/kernel/cpu/sgx/ioctl.c
> > index 83df20e3e633..f79761ad0400 100644
> > --- a/arch/x86/kernel/cpu/sgx/ioctl.c
> > +++ b/arch/x86/kernel/cpu/sgx/ioctl.c
> > @@ -215,7 +215,7 @@ static int sgx_validate_secinfo(struct sgx_secinfo *secinfo)
> >  	 * CPU will silently overwrite the permissions as zero, which means
> >  	 * that we need to validate it ourselves.
> >  	 */
> > -	if (pt == SGX_SECINFO_TCS && perm)
> > +	if (pt == SGX_SECINFO_TCS && (perm != 0 || perm != (PROT_READ | PROT_WRITE)))
> >  		return -EINVAL;
> >  
> >  	if (secinfo->flags & SGX_SECINFO_RESERVED_MASK)
> 
> The comments above sgx_ioc_enclave_add_pages() seem to indicate that zero 
> permissions are required:
> 
> "A SECINFO for a TCS is required to always contain zero permissions because
>  CPU silently zeros them. Allowing anything else would cause a mismatch in
>  the measurement."

I think this can be left out for now but fixing the relative addressing
is an obvious fix.

BR, Jarkko

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-30 15:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-19 16:30 [PATCH] x86/sgx: Allow RW for TCS pages Jarkko Sakkinen
2022-03-28 20:28 ` Reinette Chatre
2022-03-30 15:07   ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox