lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y7xPSEMOWqz+3kgD@google.com>
Date:   Mon, 9 Jan 2023 17:30:48 +0000
From:   Sean Christopherson <seanjc@...gle.com>
To:     Kees Cook <keescook@...omium.org>
Cc:     Paolo Bonzini <pbonzini@...hat.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        "Gustavo A. R. Silva" <gustavoars@...nel.org>, x86@...nel.org,
        "H. Peter Anvin" <hpa@...or.com>, kvm@...r.kernel.org,
        linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org
Subject: Re: [PATCH] KVM: x86: Replace 0-length arrays with flexible arrays

On Thu, Jan 05, 2023, Kees Cook wrote:
> Zero-length arrays are deprecated[1]. Replace struct kvm_nested_state's
> "data" union 0-length arrays with flexible arrays. (How are the
> sizes of these arrays verified?)

It's not really interpreted as an array, it's a mandatory single-entry "array".

	if (copy_from_user(vmcs12, user_vmx_nested_state->vmcs12, sizeof(*vmcs12)))
		return -EFAULT;

> Detected with GCC 13, using -fstrict-flex-arrays=3:
> 
> arch/x86/kvm/svm/nested.c: In function 'svm_get_nested_state':
> arch/x86/kvm/svm/nested.c:1536:17: error: array subscript 0 is outside array bounds of 'struct kvm_svm_nested_state_data[0]' [-Werror=array-bounds=]
>  1536 |                 &user_kvm_nested_state->data.svm[0];
>       |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> In file included from include/uapi/linux/kvm.h:15,
>                  from include/linux/kvm_host.h:40,
>                  from arch/x86/kvm/svm/nested.c:18:
> arch/x86/include/uapi/asm/kvm.h:511:50: note: while referencing 'svm'
>   511 |                 struct kvm_svm_nested_state_data svm[0];
>       |                                                  ^~~
> 
> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
> 
> Cc: Sean Christopherson <seanjc@...gle.com>
> Cc: Paolo Bonzini <pbonzini@...hat.com>
> Cc: Thomas Gleixner <tglx@...utronix.de>
> Cc: Ingo Molnar <mingo@...hat.com>
> Cc: Borislav Petkov <bp@...en8.de>
> Cc: Dave Hansen <dave.hansen@...ux.intel.com>
> Cc: "Gustavo A. R. Silva" <gustavoars@...nel.org>
> Cc: x86@...nel.org
> Cc: "H. Peter Anvin" <hpa@...or.com>
> Cc: kvm@...r.kernel.org
> Signed-off-by: Kees Cook <keescook@...omium.org>
> ---

Nit on the comment aside,

Reviewed-by: Sean Christopherson <seanjc@...gle.com>

>  arch/x86/include/uapi/asm/kvm.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h
> index e48deab8901d..8ec3dfd641b0 100644
> --- a/arch/x86/include/uapi/asm/kvm.h
> +++ b/arch/x86/include/uapi/asm/kvm.h
> @@ -502,13 +502,13 @@ struct kvm_nested_state {
>  	} hdr;
>  
>  	/*
> -	 * Define data region as 0 bytes to preserve backwards-compatability
> +	 * Define union of flexible arrays to preserve backwards-compatability

I think I'd actually prefer the "as 0 bytes" comment.  The important part is that
the size of "data" be zero, how that happens is immaterial.

>  	 * to old definition of kvm_nested_state in order to avoid changing
>  	 * KVM_{GET,PUT}_NESTED_STATE ioctl values.
>  	 */
>  	union {
> -		struct kvm_vmx_nested_state_data vmx[0];
> -		struct kvm_svm_nested_state_data svm[0];
> +		__DECLARE_FLEX_ARRAY(struct kvm_vmx_nested_state_data, vmx);
> +		__DECLARE_FLEX_ARRAY(struct kvm_svm_nested_state_data, svm);
>  	} data;
>  };
>  
> -- 
> 2.34.1
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ