Skip to content

Commit 4a9c294

Browse files
computersforpeacegregkh
authored andcommitted
mwifiex: correct channel stat buffer overflows
commit 4b5dde2d6234ff5bc68e97e6901d1f2a0a7f3749 upstream. mwifiex records information about various channels as it receives scan information. It does this by appending to a buffer that was sized to the max number of supported channels on any band, but there are numerous problems: (a) scans can return info from more than one band (e.g., both 2.4 and 5 GHz), so the determined "max" is not large enough (b) some firmware appears to return multiple results for a given channel, so the max *really* isn't large enough (c) there is no bounds checking when stashing these stats, so problems (a) and (b) can easily lead to buffer overflows Let's patch this by setting a slightly-more-correct max (that accounts for a combination of both 2.4G and 5G bands) and adding a bounds check when writing to our statistics buffer. Due to problem (b), we still might not properly report all known survey information (e.g., with "iw <dev> survey dump"), since duplicate results (or otherwise "larger than expected" results) will cause some truncation. But that's a problem for a future bugfix. (And because of this known deficiency, only log the excess at the WARN level, since that isn't visible by default in this driver and would otherwise be a bit too noisy.) Fixes: bf35443 ("mwifiex: channel statistics support for mwifiex") Cc: Avinash Patil <patila@marvell.com> Cc: Xinming Hu <huxm@marvell.com> Signed-off-by: Brian Norris <briannorris@chromium.org> Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Reviewed-by: Ganapathi Bhat <gbhat@marvell.com> Signed-off-by: Kalle Valo <kvalo@codeaurora.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 926374f commit 4a9c294

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

drivers/net/wireless/mwifiex/cfg80211.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3740,7 +3740,7 @@ int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter)
37403740
if (adapter->config_bands & BAND_A)
37413741
n_channels_a = mwifiex_band_5ghz.n_channels;
37423742

3743-
adapter->num_in_chan_stats = max_t(u32, n_channels_bg, n_channels_a);
3743+
adapter->num_in_chan_stats = n_channels_bg + n_channels_a;
37443744
adapter->chan_stats = vmalloc(sizeof(*adapter->chan_stats) *
37453745
adapter->num_in_chan_stats);
37463746

drivers/net/wireless/mwifiex/scan.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,12 @@ mwifiex_update_chan_statistics(struct mwifiex_private *priv,
21702170
sizeof(struct mwifiex_chan_stats);
21712171

21722172
for (i = 0 ; i < num_chan; i++) {
2173+
if (adapter->survey_idx >= adapter->num_in_chan_stats) {
2174+
mwifiex_dbg(adapter, WARN,
2175+
"FW reported too many channel results (max %d)\n",
2176+
adapter->num_in_chan_stats);
2177+
return;
2178+
}
21732179
chan_stats.chan_num = fw_chan_stats->chan_num;
21742180
chan_stats.bandcfg = fw_chan_stats->bandcfg;
21752181
chan_stats.flags = fw_chan_stats->flags;

0 commit comments

Comments
 (0)