diff mbox series

[RFC,1/4] x86/vdso: x86/sgx: Explicitly force 8-byte CMP for detecting user handler

Message ID 20200818042405.12871-2-sean.j.christopherson@intel.com (mailing list archive)
State New, archived
Headers show
Series x86/vdso: x86/sgx: Rework SGX vDSO API | expand

Commit Message

Sean Christopherson Aug. 18, 2020, 4:24 a.m. UTC
Use 'cmpq' to force an 8-byte CMP when checking for a user provided exit
handler.  The handler is a pointer, which is guaranteed to be an 8-byte
value since SGX is 64-bit mode only, and gcc defaults to 'cmpl' given a
bare 'cmp', i.e. is only checking the lower 32 bits.  This could cause
a false negative when detecting a user exit handler.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/entry/vdso/vsgx_enter_enclave.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jarkko Sakkinen Aug. 18, 2020, 4:46 p.m. UTC | #1
On Mon, Aug 17, 2020 at 09:24:02PM -0700, Sean Christopherson wrote:
> Use 'cmpq' to force an 8-byte CMP when checking for a user provided exit
> handler.  The handler is a pointer, which is guaranteed to be an 8-byte
> value since SGX is 64-bit mode only, and gcc defaults to 'cmpl' given a
> bare 'cmp', i.e. is only checking the lower 32 bits.  This could cause
> a false negative when detecting a user exit handler.
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
>  arch/x86/entry/vdso/vsgx_enter_enclave.S | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/entry/vdso/vsgx_enter_enclave.S b/arch/x86/entry/vdso/vsgx_enter_enclave.S
> index be7e467e1efb3..2d88acd408d4e 100644
> --- a/arch/x86/entry/vdso/vsgx_enter_enclave.S
> +++ b/arch/x86/entry/vdso/vsgx_enter_enclave.S
> @@ -48,7 +48,7 @@ SYM_FUNC_START(__vdso_sgx_enter_enclave)
>  
>  	/* Invoke userspace's exit handler if one was provided. */
>  .Lhandle_exit:
> -	cmp	$0, 0x20(%rbp)
> +	cmpq	$0, 0x20(%rbp)
>  	jne	.Linvoke_userspace_handler
>  
>  .Lout:
> -- 
> 2.28.0
> 

Acked-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>

BR,
/Jarkko
Jethro Beekman Aug. 20, 2020, 11:13 a.m. UTC | #2
Acked-by: Jethro Beekman <jethro@fortanix.com>

--
Jethro Beekman | Fortanix

On 2020-08-18 06:24, Sean Christopherson wrote:
> Use 'cmpq' to force an 8-byte CMP when checking for a user provided exit
> handler.  The handler is a pointer, which is guaranteed to be an 8-byte
> value since SGX is 64-bit mode only, and gcc defaults to 'cmpl' given a
> bare 'cmp', i.e. is only checking the lower 32 bits.  This could cause
> a false negative when detecting a user exit handler.
> 
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
>  arch/x86/entry/vdso/vsgx_enter_enclave.S | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/entry/vdso/vsgx_enter_enclave.S b/arch/x86/entry/vdso/vsgx_enter_enclave.S
> index be7e467e1efb3..2d88acd408d4e 100644
> --- a/arch/x86/entry/vdso/vsgx_enter_enclave.S
> +++ b/arch/x86/entry/vdso/vsgx_enter_enclave.S
> @@ -48,7 +48,7 @@ SYM_FUNC_START(__vdso_sgx_enter_enclave)
>  
>  	/* Invoke userspace's exit handler if one was provided. */
>  .Lhandle_exit:
> -	cmp	$0, 0x20(%rbp)
> +	cmpq	$0, 0x20(%rbp)
>  	jne	.Linvoke_userspace_handler
>  
>  .Lout:
>
diff mbox series

Patch

diff --git a/arch/x86/entry/vdso/vsgx_enter_enclave.S b/arch/x86/entry/vdso/vsgx_enter_enclave.S
index be7e467e1efb3..2d88acd408d4e 100644
--- a/arch/x86/entry/vdso/vsgx_enter_enclave.S
+++ b/arch/x86/entry/vdso/vsgx_enter_enclave.S
@@ -48,7 +48,7 @@  SYM_FUNC_START(__vdso_sgx_enter_enclave)
 
 	/* Invoke userspace's exit handler if one was provided. */
 .Lhandle_exit:
-	cmp	$0, 0x20(%rbp)
+	cmpq	$0, 0x20(%rbp)
 	jne	.Linvoke_userspace_handler
 
 .Lout: