linux-integrity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Peter Huewe <peterhuewe@gmx.de>,
	Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
	Jason Gunthorpe <jgg@ziepe.ca>, Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Gustavo A. R. Silva" <gustavo@embeddedor.com>
Subject: Re: [PATCH RESEND] tpm: eventlog: Replace zero-length array with flexible-array member
Date: Thu, 7 May 2020 11:02:18 -0700	[thread overview]
Message-ID: <202005071058.A2234694ED@keescook> (raw)
In-Reply-To: <20200507040912.GA31382@embeddedor>

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".

> [...]
> 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);

-- 
Kees Cook

  reply	other threads:[~2020-05-07 18:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-07  4:09 [PATCH RESEND] tpm: eventlog: Replace zero-length array with flexible-array member Gustavo A. R. Silva
2020-05-07 18:02 ` Kees Cook [this message]
2020-05-08 16:06   ` Gustavo A. R. Silva
2020-05-13 21:39 ` Jarkko Sakkinen
2020-05-13 23:14   ` Gustavo A. R. Silva
2020-05-14 11:05     ` Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202005071058.A2234694ED@keescook \
    --to=keescook@chromium.org \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=gustavo@embeddedor.com \
    --cc=gustavoars@kernel.org \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).