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]
Date:   Fri, 8 May 2020 11:06:04 -0500
From:   "Gustavo A. R. Silva" <gustavoars@...nel.org>
To:     Kees Cook <keescook@...omium.org>
Cc:     Peter Huewe <peterhuewe@....de>,
        Jarkko Sakkinen <jarkko.sakkinen@...ux.intel.com>,
        Jason Gunthorpe <jgg@...pe.ca>, Arnd Bergmann <arnd@...db.de>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        linux-integrity@...r.kernel.org, linux-kernel@...r.kernel.org,
        "Gustavo A. R. Silva" <gustavo@...eddedor.com>
Subject: Re: [PATCH RESEND] tpm: eventlog: Replace zero-length array with
 flexible-array member

On Thu, May 07, 2020 at 11:02:18AM -0700, Kees Cook wrote:
> On Wed, May 06, 2020 at 11:09:12PM -0500, Gustavo A. R. Silva wrote:
> > As mentioned above: "Flexible array members have incomplete type, and
> > so the sizeof operator may not be applied. As a quirk of the original
> > implementation of zero-length arrays, sizeof evaluates to zero."[1] So,
> > the sizeof(flexible-array) can be safely removed to fix the error above.
> 
> As in "sizeof(event_header->event) always evaluated to 0, so removing it
> has no effect".
> 

Thanks for this.  I wanted to make a more general statement, but I'll
update the changelog text. :)

> > [...]
> > diff --git a/drivers/char/tpm/eventlog/tpm2.c b/drivers/char/tpm/eventlog/tpm2.c
> > index e741b1157525..351a2989b3c6 100644
> > --- a/drivers/char/tpm/eventlog/tpm2.c
> > +++ b/drivers/char/tpm/eventlog/tpm2.c
> > @@ -51,8 +51,7 @@ static void *tpm2_bios_measurements_start(struct seq_file *m, loff_t *pos)
> >  	int i;
> >  
> >  	event_header = addr;
> > -	size = sizeof(struct tcg_pcr_event) - sizeof(event_header->event)
> > -		+ event_header->event_size;
> > +	size = sizeof(*event_header) + event_header->event_size;
> 
> That said, I think it would be better to stick to the struct_size()
> idiom for dealing with flexible arrays here:
> 
> 	size = struct_size(event_header, event, event_size);
> 

Yep, I agree. I'll add this and send v2, shortly.

Thanks
--
Gustavo

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ