linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Dan Carpenter <dan.carpenter@oracle.com>,
	linux-kernel@vger.kernel.org, Yong Zhi <yong.zhi@intel.com>,
	Bingbu Cao <bingbu.cao@intel.com>,
	Tianshu Qiu <tian.shu.qiu@intel.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-media@vger.kernel.org, linux-staging@lists.linux.dev,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH 2/2][next] media: staging/intel-ipu3: css: Replace one-element array and use struct_size() helper
Date: Mon, 2 Aug 2021 09:00:42 +0300	[thread overview]
Message-ID: <20210802060042.GK3@paasikivi.fi.intel.com> (raw)
In-Reply-To: <20210730084009.GA5422@embeddedor>

Hi Gustavo,

On Fri, Jul 30, 2021 at 03:40:09AM -0500, Gustavo A. R. Silva wrote:
> On Fri, Jul 30, 2021 at 10:49:50AM +0300, Dan Carpenter wrote:
> > On Thu, Jul 29, 2021 at 06:22:40PM -0500, Gustavo A. R. Silva wrote:
> > > There is a regular need in the kernel to provide a way to declare having
> > > a dynamically sized set of trailing elements in a structure. Kernel code
> > > should always use “flexible array members”[1] for these cases. The older
> > > style of one-element or zero-length arrays should no longer be used[2].
> > > 
> > > Replace a one-element array with a flexible-array member in struct
> > > imgu_fw_header and use the struct_size() helper.
> > > 
> > > This also helps with the ongoing efforts to globally enable
> > > -Warray-bounds and get us closer to being able to tighten the
> > > FORTIFY_SOURCE routines on memcpy().
> > > 
> > > [1] https://en.wikipedia.org/wiki/Flexible_array_member
> > > [2] https://www.kernel.org/doc/html/v5.10/process/deprecated.html#zero-length-and-one-element-arrays
> > > 
> > > Link: https://github.com/KSPP/linux/issues/79
> > > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> > > ---
> > >  drivers/staging/media/ipu3/ipu3-css-fw.c | 5 ++---
> > >  drivers/staging/media/ipu3/ipu3-css-fw.h | 2 +-
> > >  2 files changed, 3 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/drivers/staging/media/ipu3/ipu3-css-fw.c b/drivers/staging/media/ipu3/ipu3-css-fw.c
> > > index ab021afff954..3b7df1128840 100644
> > > --- a/drivers/staging/media/ipu3/ipu3-css-fw.c
> > > +++ b/drivers/staging/media/ipu3/ipu3-css-fw.c
> > > @@ -127,9 +127,8 @@ int imgu_css_fw_init(struct imgu_css *css)
> > >  	if (css->fw->size < sizeof(struct imgu_fw_header) ||
> >                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > Originally this was sizeof() the pointer which is clearly wrong.  Then
> > patch 1 changed it to force that binary_header[] had at least one
> > element, but now it's changed again to say that binary_header[] can have
> > zero elements.  So either patch 1 or patch 2 is wrong.
> > 
> > I feel like the probably the correct fix is to just fold these two
> > patches together and say that binary_header[] with zero elements is
> > allowed.  But I don't know this code well.
> 
> Oops... I forgot to tag this one for stable, too. But it would probably
> be better to fold both of these into a single patch as you suggest.
> 
> To me these two pieces of code suggest that binary_header[] should not
> be declared as a one-element array, but a flexible one instead:

I guess if you look at the data structure alone, you're right.

But you'll need at least one binary for the firmware to be useful. So if
you'd change the struct as in this patch, an additional check for the
number of binaries will be needed.

I think I'd keep the patches separate, the first one is a bugfix but the
second one is just about making the code a little nicer.

-- 
Kind regards,

Sakari Ailus

      reply	other threads:[~2021-08-02  6:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-29 23:19 [PATCH 0/2][next] Fix size comparison bug and use flexible array Gustavo A. R. Silva
2021-07-29 23:20 ` [PATCH 1/2][next] media: staging/intel-ipu3: css: Fix wrong size comparison Gustavo A. R. Silva
2021-07-29 23:22 ` [PATCH 2/2][next] media: staging/intel-ipu3: css: Replace one-element array and use struct_size() helper Gustavo A. R. Silva
2021-07-30  7:49   ` Dan Carpenter
2021-07-30  8:40     ` Gustavo A. R. Silva
2021-08-02  6:00       ` Sakari Ailus [this message]

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=20210802060042.GK3@paasikivi.fi.intel.com \
    --to=sakari.ailus@linux.intel.com \
    --cc=bingbu.cao@intel.com \
    --cc=dan.carpenter@oracle.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gustavoars@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=mchehab@kernel.org \
    --cc=tian.shu.qiu@intel.com \
    --cc=yong.zhi@intel.com \
    /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).