linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Cc: Brian Norris <briannorris@chromium.org>,
	Kalle Valo <kvalo@kernel.org>,
	Dmitry Antipov <dmantipov@yandex.ru>,
	Johannes Berg <johannes.berg@intel.com>,
	zuoqilin <zuoqilin@yulong.com>,
	Ruan Jinjie <ruanjinjie@huawei.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	"Gustavo A . R . Silva" <gustavoars@kernel.org>,
	linux-wireless@vger.kernel.org, Dan Carpenter <error27@gmail.com>,
	Rafael Beims <rafael.beims@toradex.com>,
	David Lin <yu-hao.lin@nxp.com>, Lukas Wunner <lukas@wunner.de>,
	Simon Horman <horms@kernel.org>,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH v2] wifi: mwifiex: Refactor 1-element array into flexible array in struct mwifiex_ie_types_chan_list_param_set
Date: Wed, 7 Feb 2024 01:56:55 -0800	[thread overview]
Message-ID: <202402070156.189B1D8@keescook> (raw)
In-Reply-To: <fb9ec7de-7c8a-4e94-94c2-eeea6369550e@embeddedor.com>

On Tue, Feb 06, 2024 at 02:32:32PM -0600, Gustavo A. R. Silva wrote:
> 
> 
> On 2/6/24 12:39, Kees Cook wrote:
> > struct mwifiex_ie_types_chan_list_param_set::chan_scan_param is treated
> > as a flexible array, so convert it into one so that it doesn't trip the
> > array bounds sanitizer[1]. Only once place was using sizeof() on the
> > whole struct (in 11n.c), so adjust it to follow the calculation pattern
> > used by scan.c to avoid including the trailing single element.
> > 
> > Link: https://github.com/KSPP/linux/issues/51 [1]
> > Cc: Brian Norris <briannorris@chromium.org>
> > Cc: Kalle Valo <kvalo@kernel.org>
> > Cc: Dmitry Antipov <dmantipov@yandex.ru>
> > Cc: Johannes Berg <johannes.berg@intel.com>
> > Cc: zuoqilin <zuoqilin@yulong.com>
> > Cc: Ruan Jinjie <ruanjinjie@huawei.com>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
> > Cc: linux-wireless@vger.kernel.org
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> > ---
> >   drivers/net/wireless/marvell/mwifiex/11n.c  |  8 +++-----
> >   drivers/net/wireless/marvell/mwifiex/fw.h   |  2 +-
> >   drivers/net/wireless/marvell/mwifiex/scan.c | 14 ++++++--------
> >   3 files changed, 10 insertions(+), 14 deletions(-)
> > 
> > diff --git a/drivers/net/wireless/marvell/mwifiex/11n.c b/drivers/net/wireless/marvell/mwifiex/11n.c
> > index 90e401100898..9ed90da4dfcf 100644
> > --- a/drivers/net/wireless/marvell/mwifiex/11n.c
> > +++ b/drivers/net/wireless/marvell/mwifiex/11n.c
> > @@ -392,12 +392,10 @@ mwifiex_cmd_append_11n_tlv(struct mwifiex_private *priv,
> >   		chan_list =
> >   			(struct mwifiex_ie_types_chan_list_param_set *) *buffer;
> > -		memset(chan_list, 0,
> > -		       sizeof(struct mwifiex_ie_types_chan_list_param_set));
> > +		memset(chan_list, 0, struct_size(chan_list, chan_scan_param, 1));
> >   		chan_list->header.type = cpu_to_le16(TLV_TYPE_CHANLIST);
> > -		chan_list->header.len = cpu_to_le16(
> > -			sizeof(struct mwifiex_ie_types_chan_list_param_set) -
> > -			sizeof(struct mwifiex_ie_types_header));
> > +		chan_list->header.len =
> > +			cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set));
> >   		chan_list->chan_scan_param[0].chan_number =
> >   			bss_desc->bcn_ht_oper->primary_chan;
> >   		chan_list->chan_scan_param[0].radio_type =
> This probably still needs a bit more work.
> 
> There are a couple more instances of `sizeof()` that should probably be
> audited and adjusted:
> 
> drivers/net/wireless/marvell/mwifiex/11n.c:414:         *buffer += sizeof(struct mwifiex_ie_types_chan_list_param_set);
> drivers/net/wireless/marvell/mwifiex/11n.c:415:         ret_len += sizeof(struct mwifiex_ie_types_chan_list_param_set);

Good call. I think this is the right delta:

-               *buffer += sizeof(struct mwifiex_ie_types_chan_list_param_set);
-               ret_len += sizeof(struct mwifiex_ie_types_chan_list_param_set);
+               *buffer += struct_size(chan_list, chan_scan_param, 1);
+               ret_len += struct_size(chan_list, chan_scan_param, 1);

I will send a v3.

-- 
Kees Cook

      reply	other threads:[~2024-02-07  9:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-06 18:39 [PATCH v2] wifi: mwifiex: Refactor 1-element array into flexible array in struct mwifiex_ie_types_chan_list_param_set Kees Cook
2024-02-06 20:32 ` Gustavo A. R. Silva
2024-02-07  9:56   ` Kees Cook [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=202402070156.189B1D8@keescook \
    --to=keescook@chromium.org \
    --cc=briannorris@chromium.org \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=dmantipov@yandex.ru \
    --cc=error27@gmail.com \
    --cc=gustavo@embeddedor.com \
    --cc=gustavoars@kernel.org \
    --cc=horms@kernel.org \
    --cc=johannes.berg@intel.com \
    --cc=kvalo@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=rafael.beims@toradex.com \
    --cc=ruanjinjie@huawei.com \
    --cc=tglx@linutronix.de \
    --cc=yu-hao.lin@nxp.com \
    --cc=zuoqilin@yulong.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).