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 <briannor...@chromium.org> > > Cc: Kalle Valo <kv...@kernel.org> > > Cc: Dmitry Antipov <dmanti...@yandex.ru> > > Cc: Johannes Berg <johannes.b...@intel.com> > > Cc: zuoqilin <zuoqi...@yulong.com> > > Cc: Ruan Jinjie <ruanjin...@huawei.com> > > Cc: Thomas Gleixner <t...@linutronix.de> > > Cc: Christophe JAILLET <christophe.jail...@wanadoo.fr> > > Cc: Gustavo A. R. Silva <gustavo...@kernel.org> > > Cc: linux-wirel...@vger.kernel.org > > Signed-off-by: Kees Cook <keesc...@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