Skip to content

Commit 0b78088

Browse files
committed
wifi: cfg80211: fix BSS refcounting bugs
There are multiple refcounting bugs related to multi-BSSID: - In bss_ref_get(), if the BSS has a hidden_beacon_bss, then the bss pointer is overwritten before checking for the transmitted BSS, which is clearly wrong. Fix this by using the bss_from_pub() macro. - In cfg80211_bss_update() we copy the transmitted_bss pointer from tmp into new, but then if we release new, we'll unref it erroneously. We already set the pointer and ref it, but need to NULL it since it was copied from the tmp data. - In cfg80211_inform_single_bss_data(), if adding to the non- transmitted list fails, we unlink the BSS and yet still we return it, but this results in returning an entry without a reference. We shouldn't return it anyway if it was broken enough to not get added there. This fixes CVE-2022-42720. Reported-by: Sönke Huster <[email protected]> Tested-by: Sönke Huster <[email protected]> Fixes: a3584f5 ("cfg80211: Properly track transmitting and non-transmitting BSS") Signed-off-by: Johannes Berg <[email protected]>
1 parent 567e14e commit 0b78088

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

net/wireless/scan.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,12 @@ static inline void bss_ref_get(struct cfg80211_registered_device *rdev,
143143
lockdep_assert_held(&rdev->bss_lock);
144144

145145
bss->refcount++;
146-
if (bss->pub.hidden_beacon_bss) {
147-
bss = container_of(bss->pub.hidden_beacon_bss,
148-
struct cfg80211_internal_bss,
149-
pub);
150-
bss->refcount++;
151-
}
152-
if (bss->pub.transmitted_bss) {
153-
bss = container_of(bss->pub.transmitted_bss,
154-
struct cfg80211_internal_bss,
155-
pub);
156-
bss->refcount++;
157-
}
146+
147+
if (bss->pub.hidden_beacon_bss)
148+
bss_from_pub(bss->pub.hidden_beacon_bss)->refcount++;
149+
150+
if (bss->pub.transmitted_bss)
151+
bss_from_pub(bss->pub.transmitted_bss)->refcount++;
158152
}
159153

160154
static inline void bss_ref_put(struct cfg80211_registered_device *rdev,
@@ -1741,6 +1735,8 @@ cfg80211_bss_update(struct cfg80211_registered_device *rdev,
17411735
new->refcount = 1;
17421736
INIT_LIST_HEAD(&new->hidden_list);
17431737
INIT_LIST_HEAD(&new->pub.nontrans_list);
1738+
/* we'll set this later if it was non-NULL */
1739+
new->pub.transmitted_bss = NULL;
17441740

17451741
if (rcu_access_pointer(tmp->pub.proberesp_ies)) {
17461742
hidden = rb_find_bss(rdev, tmp, BSS_CMP_HIDE_ZLEN);
@@ -2023,10 +2019,15 @@ cfg80211_inform_single_bss_data(struct wiphy *wiphy,
20232019
spin_lock_bh(&rdev->bss_lock);
20242020
if (cfg80211_add_nontrans_list(non_tx_data->tx_bss,
20252021
&res->pub)) {
2026-
if (__cfg80211_unlink_bss(rdev, res))
2022+
if (__cfg80211_unlink_bss(rdev, res)) {
20272023
rdev->bss_generation++;
2024+
res = NULL;
2025+
}
20282026
}
20292027
spin_unlock_bh(&rdev->bss_lock);
2028+
2029+
if (!res)
2030+
return NULL;
20302031
}
20312032

20322033
trace_cfg80211_return_bss(&res->pub);

0 commit comments

Comments
 (0)