All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mwifiex: correct channel stat buffer overflows
@ 2017-06-30  1:23 Brian Norris
  2017-06-30 18:04 ` Dmitry Torokhov
  2017-07-27  9:36 ` Kalle Valo
  0 siblings, 2 replies; 4+ messages in thread
From: Brian Norris @ 2017-06-30  1:23 UTC (permalink / raw)
  To: Ganapathi Bhat, Nishant Sarmukadam, Kalle Valo
  Cc: linux-kernel, Dmitry Torokhov, Amitkumar Karwar, linux-wireless,
	Brian Norris, stable, Avinash Patil, Xinming Hu

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: bf35443314ac ("mwifiex: channel statistics support for mwifiex")
Cc: <stable@vger.kernel.org>
Cc: Avinash Patil <patila@marvell.com>
Cc: Xinming Hu <huxm@marvell.com>
Signed-off-by: Brian Norris <briannorris@chromium.org>
---
I've got a ton of other patches still queued up locally, and I hope to send
them soon. But I realized this one is a nasty bug (with a trivial fix), so it's
probably best to get this out the door quickly.

 drivers/net/wireless/marvell/mwifiex/cfg80211.c | 2 +-
 drivers/net/wireless/marvell/mwifiex/scan.c     | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/marvell/mwifiex/cfg80211.c b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
index a850ec0054e2..82f4e796ed39 100644
--- a/drivers/net/wireless/marvell/mwifiex/cfg80211.c
+++ b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
@@ -4219,7 +4219,7 @@ int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter)
 	if (adapter->config_bands & BAND_A)
 		n_channels_a = mwifiex_band_5ghz.n_channels;
 
-	adapter->num_in_chan_stats = max_t(u32, n_channels_bg, n_channels_a);
+	adapter->num_in_chan_stats = n_channels_bg + n_channels_a;
 	adapter->chan_stats = vmalloc(sizeof(*adapter->chan_stats) *
 				      adapter->num_in_chan_stats);
 
diff --git a/drivers/net/wireless/marvell/mwifiex/scan.c b/drivers/net/wireless/marvell/mwifiex/scan.c
index ae9630b49342..9900855746ac 100644
--- a/drivers/net/wireless/marvell/mwifiex/scan.c
+++ b/drivers/net/wireless/marvell/mwifiex/scan.c
@@ -2492,6 +2492,12 @@ mwifiex_update_chan_statistics(struct mwifiex_private *priv,
 					      sizeof(struct mwifiex_chan_stats);
 
 	for (i = 0 ; i < num_chan; i++) {
+		if (adapter->survey_idx >= adapter->num_in_chan_stats) {
+			mwifiex_dbg(adapter, WARN,
+				    "FW reported too many channel results (max %d)\n",
+				    adapter->num_in_chan_stats);
+			return;
+		}
 		chan_stats.chan_num = fw_chan_stats->chan_num;
 		chan_stats.bandcfg = fw_chan_stats->bandcfg;
 		chan_stats.flags = fw_chan_stats->flags;
-- 
2.13.2.725.g09c95d1e9-goog

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mwifiex: correct channel stat buffer overflows
  2017-06-30  1:23 [PATCH] mwifiex: correct channel stat buffer overflows Brian Norris
@ 2017-06-30 18:04 ` Dmitry Torokhov
  2017-06-30 18:13   ` [EXT] " Ganapathi Bhat
  2017-07-27  9:36 ` Kalle Valo
  1 sibling, 1 reply; 4+ messages in thread
From: Dmitry Torokhov @ 2017-06-30 18:04 UTC (permalink / raw)
  To: Brian Norris
  Cc: Ganapathi Bhat, Nishant Sarmukadam, Kalle Valo, linux-kernel,
	Amitkumar Karwar, linux-wireless, stable, Avinash Patil,
	Xinming Hu

On Thu, Jun 29, 2017 at 06:23:54PM -0700, Brian Norris wrote:
> 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: bf35443314ac ("mwifiex: channel statistics support for mwifiex")
> Cc: <stable@vger.kernel.org>
> Cc: Avinash Patil <patila@marvell.com>
> Cc: Xinming Hu <huxm@marvell.com>
> Signed-off-by: Brian Norris <briannorris@chromium.org>
> ---
> I've got a ton of other patches still queued up locally, and I hope to send
> them soon. But I realized this one is a nasty bug (with a trivial fix), so it's
> probably best to get this out the door quickly.

This does make sense to me.

Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

> 
>  drivers/net/wireless/marvell/mwifiex/cfg80211.c | 2 +-
>  drivers/net/wireless/marvell/mwifiex/scan.c     | 6 ++++++
>  2 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/wireless/marvell/mwifiex/cfg80211.c b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
> index a850ec0054e2..82f4e796ed39 100644
> --- a/drivers/net/wireless/marvell/mwifiex/cfg80211.c
> +++ b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
> @@ -4219,7 +4219,7 @@ int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter)
>  	if (adapter->config_bands & BAND_A)
>  		n_channels_a = mwifiex_band_5ghz.n_channels;
>  
> -	adapter->num_in_chan_stats = max_t(u32, n_channels_bg, n_channels_a);
> +	adapter->num_in_chan_stats = n_channels_bg + n_channels_a;
>  	adapter->chan_stats = vmalloc(sizeof(*adapter->chan_stats) *
>  				      adapter->num_in_chan_stats);
>  
> diff --git a/drivers/net/wireless/marvell/mwifiex/scan.c b/drivers/net/wireless/marvell/mwifiex/scan.c
> index ae9630b49342..9900855746ac 100644
> --- a/drivers/net/wireless/marvell/mwifiex/scan.c
> +++ b/drivers/net/wireless/marvell/mwifiex/scan.c
> @@ -2492,6 +2492,12 @@ mwifiex_update_chan_statistics(struct mwifiex_private *priv,
>  					      sizeof(struct mwifiex_chan_stats);
>  
>  	for (i = 0 ; i < num_chan; i++) {
> +		if (adapter->survey_idx >= adapter->num_in_chan_stats) {
> +			mwifiex_dbg(adapter, WARN,
> +				    "FW reported too many channel results (max %d)\n",
> +				    adapter->num_in_chan_stats);
> +			return;
> +		}
>  		chan_stats.chan_num = fw_chan_stats->chan_num;
>  		chan_stats.bandcfg = fw_chan_stats->bandcfg;
>  		chan_stats.flags = fw_chan_stats->flags;
> -- 
> 2.13.2.725.g09c95d1e9-goog
> 

-- 
Dmitry

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [EXT] Re: [PATCH] mwifiex: correct channel stat buffer overflows
  2017-06-30 18:04 ` Dmitry Torokhov
@ 2017-06-30 18:13   ` Ganapathi Bhat
  0 siblings, 0 replies; 4+ messages in thread
From: Ganapathi Bhat @ 2017-06-30 18:13 UTC (permalink / raw)
  To: Brian Norris
  Cc: Nishant Sarmukadam, Kalle Valo, linux-kernel, Amitkumar Karwar,
	linux-wireless, stable, Avinash Patil, Xinming Hu,
	Dmitry Torokhov

Hi Brian,

> ----------------------------------------------------------------------
> On Thu, Jun 29, 2017 at 06:23:54PM -0700, Brian Norris wrote:
> > 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: bf35443314ac ("mwifiex: channel statistics support for
> > mwifiex")
> > Cc: <stable@vger.kernel.org>
> > Cc: Avinash Patil <patila@marvell.com>
> > Cc: Xinming Hu <huxm@marvell.com>
> > Signed-off-by: Brian Norris <briannorris@chromium.org>
> > ---
> > I've got a ton of other patches still queued up locally, and I hope
> to
> > send them soon. But I realized this one is a nasty bug (with a
> trivial
> > fix), so it's probably best to get this out the door quickly.
> 
> This does make sense to me.
> 
> Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> 
Changes look good.
Reviewed-by: Ganapathi Bhat <gbhat@marvell.com>
> >
> >  drivers/net/wireless/marvell/mwifiex/cfg80211.c | 2 +-
> >  drivers/net/wireless/marvell/mwifiex/scan.c     | 6 ++++++
> >  2 files changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/wireless/marvell/mwifiex/cfg80211.c
> > b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
> > index a850ec0054e2..82f4e796ed39 100644
> > --- a/drivers/net/wireless/marvell/mwifiex/cfg80211.c
> > +++ b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
> > @@ -4219,7 +4219,7 @@ int mwifiex_init_channel_scan_gap(struct
> mwifiex_adapter *adapter)
> >  	if (adapter->config_bands & BAND_A)
> >  		n_channels_a = mwifiex_band_5ghz.n_channels;
> >
> > -	adapter->num_in_chan_stats = max_t(u32, n_channels_bg,
> n_channels_a);
> > +	adapter->num_in_chan_stats = n_channels_bg + n_channels_a;
> >  	adapter->chan_stats = vmalloc(sizeof(*adapter->chan_stats) *
> >  				      adapter->num_in_chan_stats);
> >
> > diff --git a/drivers/net/wireless/marvell/mwifiex/scan.c
> > b/drivers/net/wireless/marvell/mwifiex/scan.c
> > index ae9630b49342..9900855746ac 100644
> > --- a/drivers/net/wireless/marvell/mwifiex/scan.c
> > +++ b/drivers/net/wireless/marvell/mwifiex/scan.c
> > @@ -2492,6 +2492,12 @@ mwifiex_update_chan_statistics(struct
> mwifiex_private *priv,
> >  					      sizeof(struct mwifiex_chan_stats);
> >
> >  	for (i = 0 ; i < num_chan; i++) {
> > +		if (adapter->survey_idx >= adapter->num_in_chan_stats) {
> > +			mwifiex_dbg(adapter, WARN,
> > +				    "FW reported too many channel results (max
> %d)\n",
> > +				    adapter->num_in_chan_stats);
> > +			return;
> > +		}
> >  		chan_stats.chan_num = fw_chan_stats->chan_num;
> >  		chan_stats.bandcfg = fw_chan_stats->bandcfg;
> >  		chan_stats.flags = fw_chan_stats->flags;
> > --
> > 2.13.2.725.g09c95d1e9-goog
> >
> 
> --
> Dmitry

Regards,
Ganapathi

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: mwifiex: correct channel stat buffer overflows
  2017-06-30  1:23 [PATCH] mwifiex: correct channel stat buffer overflows Brian Norris
  2017-06-30 18:04 ` Dmitry Torokhov
@ 2017-07-27  9:36 ` Kalle Valo
  1 sibling, 0 replies; 4+ messages in thread
From: Kalle Valo @ 2017-07-27  9:36 UTC (permalink / raw)
  To: Brian Norris
  Cc: Ganapathi Bhat, Nishant Sarmukadam, linux-kernel,
	Dmitry Torokhov, Amitkumar Karwar, linux-wireless, Brian Norris,
	stable, Avinash Patil, Xinming Hu

Brian Norris <briannorris@chromium.org> wrote:

> 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: bf35443314ac ("mwifiex: channel statistics support for mwifiex")
> Cc: <stable@vger.kernel.org>
> 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>

Patch applied to wireless-drivers-next.git, thanks.

4b5dde2d6234 mwifiex: correct channel stat buffer overflows

-- 
https://patchwork.kernel.org/patch/9818269/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-07-27  9:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-30  1:23 [PATCH] mwifiex: correct channel stat buffer overflows Brian Norris
2017-06-30 18:04 ` Dmitry Torokhov
2017-06-30 18:13   ` [EXT] " Ganapathi Bhat
2017-07-27  9:36 ` Kalle Valo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.