netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iwlwifi: out-of-bounds access in iwl_init_sband_channels
@ 2015-08-14  0:35 Adrien Schildknecht
  2015-08-14  4:31 ` Grumbach, Emmanuel
  0 siblings, 1 reply; 5+ messages in thread
From: Adrien Schildknecht @ 2015-08-14  0:35 UTC (permalink / raw)
  To: johannes.berg, emmanuel.grumbach
  Cc: ilw, kvalo, linux-wireless, netdev, linux-kernel,
	Adrien Schildknecht

Both loops of this function compare data from the 'chan' array and then
check if the index is valid.

The 2 conditions should be inverted to avoid an out-of-bounds access.

Signed-off-by: Adrien Schildknecht <adrien+dev@schischi.me>
---
 drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c b/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
index 21302b6..acc3d18 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
@@ -713,12 +713,12 @@ int iwl_init_sband_channels(struct iwl_nvm_data *data,
 	struct ieee80211_channel *chan = &data->channels[0];
 	int n = 0, idx = 0;
 
-	while (chan->band != band && idx < n_channels)
+	while (idx < n_channels && chan->band != band)
 		chan = &data->channels[++idx];
 
 	sband->channels = &data->channels[idx];
 
-	while (chan->band == band && idx < n_channels) {
+	while (idx < n_channels && chan->band == band) {
 		chan = &data->channels[++idx];
 		n++;
 	}
-- 
2.5.0

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

* Re: [PATCH] iwlwifi: out-of-bounds access in iwl_init_sband_channels
  2015-08-14  0:35 [PATCH] iwlwifi: out-of-bounds access in iwl_init_sband_channels Adrien Schildknecht
@ 2015-08-14  4:31 ` Grumbach, Emmanuel
  2015-08-14  7:04   ` Adrien Schildknecht
  0 siblings, 1 reply; 5+ messages in thread
From: Grumbach, Emmanuel @ 2015-08-14  4:31 UTC (permalink / raw)
  To: Adrien Schildknecht, Berg, Johannes
  Cc: ilw@linux.intel.com, kvalo@codeaurora.org,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org

Hi,

On 08/14/2015 03:36 AM, Adrien Schildknecht wrote:
> Both loops of this function compare data from the 'chan' array and then
> check if the index is valid.
> 
> The 2 conditions should be inverted to avoid an out-of-bounds access.
> 

Was that found by a static analyzer or any other automated tool, or was
that the result of your very careful review?

> Signed-off-by: Adrien Schildknecht <adrien+dev@schischi.me>
> ---
>  drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c b/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
> index 21302b6..acc3d18 100644
> --- a/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
> +++ b/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
> @@ -713,12 +713,12 @@ int iwl_init_sband_channels(struct iwl_nvm_data *data,
>  	struct ieee80211_channel *chan = &data->channels[0];
>  	int n = 0, idx = 0;
>  
> -	while (chan->band != band && idx < n_channels)
> +	while (idx < n_channels && chan->band != band)
>  		chan = &data->channels[++idx];
>  
>  	sband->channels = &data->channels[idx];
>  
> -	while (chan->band == band && idx < n_channels) {
> +	while (idx < n_channels && chan->band == band) {
>  		chan = &data->channels[++idx];
>  		n++;
>  	}
> 

Looks fine - I'll pick it up.

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

* Re: [PATCH] iwlwifi: out-of-bounds access in iwl_init_sband_channels
  2015-08-14  4:31 ` Grumbach, Emmanuel
@ 2015-08-14  7:04   ` Adrien Schildknecht
  2015-08-14  7:14     ` Kalle Valo
  0 siblings, 1 reply; 5+ messages in thread
From: Adrien Schildknecht @ 2015-08-14  7:04 UTC (permalink / raw)
  To: Grumbach, Emmanuel
  Cc: Berg, Johannes, ilw@linux.intel.com, kvalo@codeaurora.org,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org

Hi,

> On 08/14/2015 03:36 AM, Adrien Schildknecht wrote:
> > Both loops of this function compare data from the 'chan' array and
> > then check if the index is valid.
> > 
> > The 2 conditions should be inverted to avoid an out-of-bounds
> > access.
> > 
> 
> Was that found by a static analyzer or any other automated tool, or
> was that the result of your very careful review?

The error has been reported by KASan:
==================================================================
BUG: KASan: out of bounds access in iwl_init_sband_channels+0x207/0x260 [iwlwifi] at addr ffff8800c2d0aac8
Read of size 4 by task modprobe/329
==================================================================

-- 
Adrien Schildknecht

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

* Re: [PATCH] iwlwifi: out-of-bounds access in iwl_init_sband_channels
  2015-08-14  7:04   ` Adrien Schildknecht
@ 2015-08-14  7:14     ` Kalle Valo
  2015-08-14  9:05       ` [PATCH v2] " Adrien Schildknecht
  0 siblings, 1 reply; 5+ messages in thread
From: Kalle Valo @ 2015-08-14  7:14 UTC (permalink / raw)
  To: Adrien Schildknecht
  Cc: Grumbach, Emmanuel, Berg, Johannes, ilw@linux.intel.com,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org

Adrien Schildknecht <adrien+dev@schischi.me> writes:

> Hi,
>
>> On 08/14/2015 03:36 AM, Adrien Schildknecht wrote:
>> > Both loops of this function compare data from the 'chan' array and
>> > then check if the index is valid.
>> > 
>> > The 2 conditions should be inverted to avoid an out-of-bounds
>> > access.
>> > 
>> 
>> Was that found by a static analyzer or any other automated tool, or
>> was that the result of your very careful review?
>
> The error has been reported by KASan:
> ==================================================================
> BUG: KASan: out of bounds access in iwl_init_sband_channels+0x207/0x260 [iwlwifi] at addr ffff8800c2d0aac8
> Read of size 4 by task modprobe/329
> ==================================================================

Always try to add information like this to the commit log, it's very
useful.

-- 
Kalle Valo

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

* [PATCH v2] iwlwifi: out-of-bounds access in iwl_init_sband_channels
  2015-08-14  7:14     ` Kalle Valo
@ 2015-08-14  9:05       ` Adrien Schildknecht
  0 siblings, 0 replies; 5+ messages in thread
From: Adrien Schildknecht @ 2015-08-14  9:05 UTC (permalink / raw)
  To: johannes.berg, emmanuel.grumbach
  Cc: ilw, kvalo, linux-wireless, netdev, linux-kernel,
	Adrien Schildknecht

KASan error report:
==================================================================
BUG: KASan: out of bounds access in iwl_init_sband_channels+0x207/0x260 [iwlwifi] at addr ffff8800c2d0aac8
Read of size 4 by task modprobe/329
==================================================================

Both loops of this function compare data from the 'chan' array and then
check if the index is valid.

The 2 conditions should be inverted to avoid an out-of-bounds access.

Signed-off-by: Adrien Schildknecht <adrien+dev@schischi.me>
---
 drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c b/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
index 21302b6..acc3d18 100644
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
@@ -713,12 +713,12 @@ int iwl_init_sband_channels(struct iwl_nvm_data *data,
 	struct ieee80211_channel *chan = &data->channels[0];
 	int n = 0, idx = 0;
 
-	while (chan->band != band && idx < n_channels)
+	while (idx < n_channels && chan->band != band)
 		chan = &data->channels[++idx];
 
 	sband->channels = &data->channels[idx];
 
-	while (chan->band == band && idx < n_channels) {
+	while (idx < n_channels && chan->band == band) {
 		chan = &data->channels[++idx];
 		n++;
 	}
-- 
2.5.0

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

end of thread, other threads:[~2015-08-14  9:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-14  0:35 [PATCH] iwlwifi: out-of-bounds access in iwl_init_sband_channels Adrien Schildknecht
2015-08-14  4:31 ` Grumbach, Emmanuel
2015-08-14  7:04   ` Adrien Schildknecht
2015-08-14  7:14     ` Kalle Valo
2015-08-14  9:05       ` [PATCH v2] " Adrien Schildknecht

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).