Skip to content

Commit 29d5fba

Browse files
jmberg-inteldinguyen702
authored andcommitted
wifi: cfg80211: fix BSS refcounting bugs
[upstream 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]>
1 parent 9504a70 commit 29d5fba

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);
@@ -1981,10 +1977,15 @@ cfg80211_inform_single_bss_data(struct wiphy *wiphy,
19811977
spin_lock_bh(&rdev->bss_lock);
19821978
if (cfg80211_add_nontrans_list(non_tx_data->tx_bss,
19831979
&res->pub)) {
1984-
if (__cfg80211_unlink_bss(rdev, res))
1980+
if (__cfg80211_unlink_bss(rdev, res)) {
19851981
rdev->bss_generation++;
1982+
res = NULL;
1983+
}
19861984
}
19871985
spin_unlock_bh(&rdev->bss_lock);
1986+
1987+
if (!res)
1988+
return NULL;
19881989
}
19891990

19901991
trace_cfg80211_return_bss(&res->pub);

0 commit comments

Comments
 (0)