From fda018f288254294b5f744bc1db946626669a911 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 1 Apr 2024 09:32:51 +0800 Subject: [PATCH] mac80211: fix locking in ieee80211_start_ap error path mainline inclusion from mainline-v5.16-rc7 commit 87a270625a89fc841f1a7e21aae6176543d8385c category: bugfix bugzilla: https://gitee.com/src-openeuler/kernel/issues/I95REH CVE: CVE-2021-47091 -------------------------------- We need to hold the local->mtx to release the channel context, as even encoded by the lockdep_assert_held() there. Fix it. Cc: stable@vger.kernel.org Fixes: 295b02c4be74 ("mac80211: Add FILS discovery support") Reported-and-tested-by: syzbot+11c342e5e30e9539cabd@syzkaller.appspotmail.com Link: https://lore.kernel.org/r/20211220090836.cee3d59a1915.I36bba9b79dc2ff4d57c3c7aa30dff9a003fe8c5c@changeid Signed-off-by: Johannes Berg Signed-off-by: David S. Miller Conflicts: net/mac80211/cfg.c Signed-off-by: Ziyang Xuan --- net/mac80211/cfg.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c index 2201923238ed..16998a022818 100644 --- a/net/mac80211/cfg.c +++ b/net/mac80211/cfg.c @@ -972,10 +972,8 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev, IEEE80211_P2P_OPPPS_ENABLE_BIT; err = ieee80211_assign_beacon(sdata, ¶ms->beacon, NULL); - if (err < 0) { - ieee80211_vif_release_channel(sdata); - return err; - } + if (err < 0) + goto error; changed |= err; err = drv_start_ap(sdata->local, sdata); @@ -985,8 +983,7 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev, if (old) kfree_rcu(old, rcu_head); RCU_INIT_POINTER(sdata->u.ap.beacon, NULL); - ieee80211_vif_release_channel(sdata); - return err; + goto error; } ieee80211_recalc_dtim(local, sdata); @@ -997,6 +994,13 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev, netif_carrier_on(vlan->dev); return 0; + +error: + mutex_lock(&local->mtx); + ieee80211_vif_release_channel(sdata); + mutex_unlock(&local->mtx); + + return err; } static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev, -- Gitee