From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D58DFC38A2A for ; Fri, 8 May 2020 16:01:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC2782173E for ; Fri, 8 May 2020 16:01:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588953699; bh=e/q+X2llUESDXjknVyD37ZTb95TJ/m5mQMoLaK/Zq5s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=bLImo8CsTTEmLo1xDkrIBiiHiehprfqwJnCIrJi9mEd8WQ8HeTI9h5xRyU8V7uJhe XaT5efDATtqQAWQis9xUSO+ma85MmWoOz29rp9KEhHG0ygDUlAU+jwKVJIL/wdmz09 MaojYZ/PxWFDYX9C2Kh0ShngZ4uU3sKWreuQchDY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728038AbgEHQBi (ORCPT ); Fri, 8 May 2020 12:01:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:59286 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727803AbgEHQBh (ORCPT ); Fri, 8 May 2020 12:01:37 -0400 Received: from embeddedor (unknown [189.207.59.248]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BF1F220725; Fri, 8 May 2020 16:01:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588953697; bh=e/q+X2llUESDXjknVyD37ZTb95TJ/m5mQMoLaK/Zq5s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Bu0EOWe3AR5ZE9lofciPSHX8kg17gXFgLXHZhP4cxL90fG3kmEzp+KGkypxpQoBTN bzC20fYQBpgzPgI1cLZUbWrFU4R3x94Z/QlASK96dd66zk6hRxh6oiTi1gDVNRnH36 BSvVZlEPlc8DxFjnegGZxnsM/oOWQsPny7P98ZDc= Date: Fri, 8 May 2020 11:06:04 -0500 From: "Gustavo A. R. Silva" To: Kees Cook Cc: Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe , Arnd Bergmann , Greg Kroah-Hartman , linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: Re: [PATCH RESEND] tpm: eventlog: Replace zero-length array with flexible-array member Message-ID: <20200508160604.GA23375@embeddedor> References: <20200507040912.GA31382@embeddedor> <202005071058.A2234694ED@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202005071058.A2234694ED@keescook> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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