Re: [PATCH] iwlwifi: out-of-bounds access in iwl_init_sband_channels

2 messages, 2 authors, 2015-08-14 · open the first message on its own page

Re: [PATCH] iwlwifi: out-of-bounds access in iwl_init_sband_channels

From: Kalle Valo <hidden>
Date: 2015-08-14 07:14:34

Adrien Schildknecht [off-list ref] writes:
Hi,
quoted
On 08/14/2015 03:36 AM, Adrien Schildknecht wrote:
quoted
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

[PATCH v2] iwlwifi: out-of-bounds access in iwl_init_sband_channels

From: Adrien Schildknecht <hidden>
Date: 2015-08-14 09:06:06

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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help