Re: [PATCH] KVM: x86: Replace 0-length arrays with flexible arrays

From: Kees Cook
Date: Thu Jan 12 2023 - 17:44:55 EST


On Mon, Jan 09, 2023 at 05:30:48PM +0000, Sean Christopherson wrote:
> 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".
[...]
> >
> > /*
> > - * 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.

Oh, dur, I can read the comment. :)

It has to stay the old size -- this was a way to add an optional extra
struct to the end. Got it!

--
Kees Cook