Re: [PATCH 2/5] x86/sgx: Use memchr_inv() in sgx_validate_secinfo()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Aug 19, 2019 at 06:25:41PM +0300, Jarkko Sakkinen wrote:
> Instead of looping through the array of reserved bytes use memchr_inv()
> to check the bytes.
> 
> Cc: Sean Christopherson <sean.j.christpherson@xxxxxxxxx>
> Cc: Shay Katz-zamir <shay.katz-zamir@xxxxxxxxx>
> Cc: Serge Ayoun <serge.ayoun@xxxxxxxxx>
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@xxxxxxxxxxxxxxx>
> ---
>  arch/x86/kernel/cpu/sgx/driver/ioctl.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/sgx/driver/ioctl.c b/arch/x86/kernel/cpu/sgx/driver/ioctl.c
> index 64d3286f3324..d5f326411df0 100644
> --- a/arch/x86/kernel/cpu/sgx/driver/ioctl.c
> +++ b/arch/x86/kernel/cpu/sgx/driver/ioctl.c
> @@ -414,7 +414,6 @@ 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;
> -	int i;
>  
>  	if ((secinfo->flags & SGX_SECINFO_RESERVED_MASK) ||
>  	    ((perm & SGX_SECINFO_W) && !(perm & SGX_SECINFO_R)) ||
> @@ -422,9 +421,8 @@ static int sgx_validate_secinfo(struct sgx_secinfo *secinfo)
>  	     page_type != SGX_SECINFO_REG))
>  		return -EINVAL;
>  
> -	for (i = 0; i < SGX_SECINFO_RESERVED_SIZE; i++)
> -		if (secinfo->reserved[i])
> -			return -EINVAL;
> +	if (memchr_inv(secinfo->reserved, 0, SGX_SECINFO_RESERVED_SIZE))

Doing 'sizeof(secinfo->reserved)' would be preferable, that way we're not
dependent on SGX_SECINFO_RESERVED_SIZE being in bytes (I had to check).

Obviously not in this patch, but the same cleanup can be applied to
sgx_validate_secs().

> +		return -EINVAL;
>  
>  	return 0;
>  }
> -- 
> 2.20.1
> 



[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux