Skip to content

Commit 3cb9f84

Browse files
committed
wifi: cfg80211: fix BSS refcounting bugs
jira VULN-3807 cve CVE-2022-42720 commit-author Johannes Berg <[email protected]> commit 0b78088 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]> (cherry picked from commit 0b78088) Signed-off-by: Marcin Wcisło <[email protected]>
1 parent 8a610cf commit 3cb9f84

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,
@@ -1734,6 +1728,8 @@ cfg80211_bss_update(struct cfg80211_registered_device *rdev,
17341728
new->refcount = 1;
17351729
INIT_LIST_HEAD(&new->hidden_list);
17361730
INIT_LIST_HEAD(&new->pub.nontrans_list);
1731+
/* we'll set this later if it was non-NULL */
1732+
new->pub.transmitted_bss = NULL;
17371733

17381734
if (rcu_access_pointer(tmp->pub.proberesp_ies)) {
17391735
hidden = rb_find_bss(rdev, tmp, BSS_CMP_HIDE_ZLEN);
@@ -1985,10 +1981,15 @@ cfg80211_inform_single_bss_data(struct wiphy *wiphy,
19851981
spin_lock_bh(&rdev->bss_lock);
19861982
if (cfg80211_add_nontrans_list(non_tx_data->tx_bss,
19871983
&res->pub)) {
1988-
if (__cfg80211_unlink_bss(rdev, res))
1984+
if (__cfg80211_unlink_bss(rdev, res)) {
19891985
rdev->bss_generation++;
1986+
res = NULL;
1987+
}
19901988
}
19911989
spin_unlock_bh(&rdev->bss_lock);
1990+
1991+
if (!res)
1992+
return NULL;
19921993
}
19931994

19941995
trace_cfg80211_return_bss(&res->pub);

0 commit comments

Comments
 (0)