Skip to content

Commit cfaf703

Browse files
jmberg-intelgregkh
authored andcommitted
cfg80211: always free wiphy specific regdomain
[ Upstream commit e53e982 ] In the (somewhat unlikely) event that we allocate a wiphy, then add a regdomain to it, and then fail registration, we leak the regdomain. Fix this by just always freeing it at the end, in the normal cases we'll free (and NULL) it during wiphy_unregister(). This happened when the wiphy settings were bad, and since they can be controlled by userspace with hwsim, syzbot was able to find this issue. Reported-by: syzbot+1638e7c770eef6b6c0d0@syzkaller.appspotmail.com Fixes: 3e0c3ff ("cfg80211: allow multiple driver regulatory_hints()") Signed-off-by: Johannes Berg <johannes.berg@intel.com> Link: https://lore.kernel.org/r/20210927131105.68b70cef4674.I4b9f0aa08c2af28555963b9fe3d34395bb72e0cc@changeid Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6adf16c commit cfaf703

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

net/wireless/core.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,16 @@ void cfg80211_dev_free(struct cfg80211_registered_device *rdev)
10811081
list_for_each_entry_safe(scan, tmp, &rdev->bss_list, list)
10821082
cfg80211_put_bss(&rdev->wiphy, &scan->pub);
10831083
mutex_destroy(&rdev->wiphy.mtx);
1084+
1085+
/*
1086+
* The 'regd' can only be non-NULL if we never finished
1087+
* initializing the wiphy and thus never went through the
1088+
* unregister path - e.g. in failure scenarios. Thus, it
1089+
* cannot have been visible to anyone if non-NULL, so we
1090+
* can just free it here.
1091+
*/
1092+
kfree(rcu_dereference_raw(rdev->wiphy.regd));
1093+
10841094
kfree(rdev);
10851095
}
10861096

0 commit comments

Comments
 (0)