diff mbox series

[lvc-project] wifi: mac80211: fix buffer overflow in ieee80211_rx_get_bigtk()

Message ID 20231004143740.40933-1-Igor.A.Artemiev@mcst.ru (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series [lvc-project] wifi: mac80211: fix buffer overflow in ieee80211_rx_get_bigtk() | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1340 this patch: 1340
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 1363 this patch: 1363
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1363 this patch: 1363
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 17 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Igor Artemiev Oct. 4, 2023, 2:37 p.m. UTC
If 'idx' is 0, then 'idx2' is -1, and arrays 
will be accessed by a negative index. 

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Igor Artemiev <Igor.A.Artemiev@mcst.ru>
---
 net/mac80211/rx.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Johannes Berg Oct. 4, 2023, 2:58 p.m. UTC | #1
On Wed, 2023-10-04 at 17:37 +0300, Igor Artemiev wrote:
> If 'idx' is 0

And ... how exactly do you propose that is going to happen?

johannes
Igor Artemiev Oct. 5, 2023, 12:31 p.m. UTC | #2
On 10/4/23 17:58, Johannes Berg wrote:
> And ... how exactly do you propose that is going to happen?

'conf.keyidx', the value that is passed to the function, can be 0. But I 
missed checking the second argument of the ieee80211_rx_get_bigtk() 
function before calling it. Sorry to bother you.

Thanks,
Igor
diff mbox series

Patch

diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index e751cda5eef6..e686380434bd 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -1868,10 +1868,13 @@  ieee80211_rx_get_bigtk(struct ieee80211_rx_data *rx, int idx)
 		key = rcu_dereference(rx->link_sta->gtk[idx]);
 	if (!key)
 		key = rcu_dereference(rx->link->gtk[idx]);
-	if (!key && rx->link_sta)
-		key = rcu_dereference(rx->link_sta->gtk[idx2]);
-	if (!key)
-		key = rcu_dereference(rx->link->gtk[idx2]);
+
+	if (idx2 >= 0) {
+		if (!key && rx->link_sta)
+			key = rcu_dereference(rx->link_sta->gtk[idx2]);
+		if (!key)
+			key = rcu_dereference(rx->link->gtk[idx2]);
+	}
 
 	return key;
 }