b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Erick Archer <erick.archer@outlook.com>
To: Kees Cook <keescook@chromium.org>
Cc: Erick Archer <erick.archer@outlook.com>,
	Marek Lindner <mareklindner@neomailbox.ch>,
	Simon Wunderlich <sw@simonwunderlich.de>,
	Antonio Quartulli <a@unstable.cc>,
	Sven Eckelmann <sven@narfation.org>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	b.a.t.m.a.n@lists.open-mesh.org, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org, linux-hardening@vger.kernel.org,
	llvm@lists.linux.dev
Subject: Re: [PATCH v2] batman-adv: Add flex array to struct batadv_tvlv_tt_data
Date: Wed, 1 May 2024 15:35:57 +0200	[thread overview]
Message-ID: <AS8PR02MB7237099D421106BC1EF10BDB8B192@AS8PR02MB7237.eurprd02.prod.outlook.com> (raw)
In-Reply-To: <202404291030.F760C26@keescook>

Hi Kees,

On Mon, Apr 29, 2024 at 10:36:23AM -0700, Kees Cook wrote:
> On Fri, Apr 26, 2024 at 07:22:47PM +0200, Erick Archer wrote:
> >  
> > @@ -3957,17 +3947,18 @@ static void batadv_tt_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
> >  
> >  	num_vlan = ntohs(tt_data->num_vlan);
> >  
> > -	if (tvlv_value_len < sizeof(*tt_vlan) * num_vlan)
> > +	flex_size = flex_array_size(tt_data, vlan_data, num_vlan);
> > +	if (tvlv_value_len < flex_size)
> >  		return;
> >  
> > -	tt_vlan = (struct batadv_tvlv_tt_vlan_data *)(tt_data + 1);
> > -	tt_change = (struct batadv_tvlv_tt_change *)(tt_vlan + num_vlan);
> > -	tvlv_value_len -= sizeof(*tt_vlan) * num_vlan;
> > +	tt_change = (struct batadv_tvlv_tt_change *)(tt_data->vlan_data +
> > +						     num_vlan);
> 
> This is the only part I'm a little worried about. The math all checks
> out, but the compiler may get bothered about performing a pointer
> calculation using the vlan_data flexible array memory. As in, this may
> be calculated as an array offset, since it is the same as:
> 
> 	&tt_data->vlan_data[num_vlan]
> 
> Which, for big endian where __counted_by is in effect, the bounds
> checker may throw a fit since we're going past the end of the array. In
> other "multiple trailing flexible array" situations, we've done the
> addressing from the base pointer, since the compiler either knows the
> full allocation size or it knows nothing about it (this case, since it
> came from a "void *" function argument). I would suggest:
> 
> tt_change = (struct batadv_tvlv_tt_change *)((void *)tt_data + flex_size);
> 
First of all thanks for the review and the great explanation. The change
looks reasonable to me. I will send a new version with this suggestion.

Regards,
Erick


      reply	other threads:[~2024-05-01 14:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-26 17:22 [PATCH v2] batman-adv: Add flex array to struct batadv_tvlv_tt_data Erick Archer
2024-04-29 17:36 ` Kees Cook
2024-05-01 13:35   ` Erick Archer [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=AS8PR02MB7237099D421106BC1EF10BDB8B192@AS8PR02MB7237.eurprd02.prod.outlook.com \
    --to=erick.archer@outlook.com \
    --cc=a@unstable.cc \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gustavoars@kernel.org \
    --cc=justinstitt@google.com \
    --cc=keescook@chromium.org \
    --cc=kuba@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mareklindner@neomailbox.ch \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sven@narfation.org \
    --cc=sw@simonwunderlich.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 read-only IMAP folder(s) and NNTP newsgroup(s).