Skip to content

Commit 31db78a

Browse files
committed
wifi: mac80211: fix potential key use-after-free
When ieee80211_key_link() is called by ieee80211_gtk_rekey_add() but returns 0 due to KRACK protection (identical key reinstall), ieee80211_gtk_rekey_add() will still return a pointer into the key, in a potential use-after-free. This normally doesn't happen since it's only called by iwlwifi in case of WoWLAN rekey offload which has its own KRACK protection, but still better to fix, do that by returning an error code and converting that to success on the cfg80211 boundary only, leaving the error for bad callers of ieee80211_gtk_rekey_add(). Reported-by: Dan Carpenter <[email protected]> Fixes: fdf7cb4 ("mac80211: accept key reinstall without changing anything") Signed-off-by: Johannes Berg <[email protected]>
1 parent 684e45e commit 31db78a

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

net/mac80211/cfg.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,9 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
566566
}
567567

568568
err = ieee80211_key_link(key, link, sta);
569+
/* KRACK protection, shouldn't happen but just silently accept key */
570+
if (err == -EALREADY)
571+
err = 0;
569572

570573
out_unlock:
571574
mutex_unlock(&local->sta_mtx);

net/mac80211/key.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ int ieee80211_key_link(struct ieee80211_key *key,
905905
*/
906906
if (ieee80211_key_identical(sdata, old_key, key)) {
907907
ieee80211_key_free_unused(key);
908-
ret = 0;
908+
ret = -EALREADY;
909909
goto out;
910910
}
911911

0 commit comments

Comments
 (0)