Oops and other problems in cfg80211
If cfg80211 is compiled with CONFIG_WIRELESS_OLD_REGULATORY defined, if insmod is loaded with "insmod cfg80211 ieee80211_regdom=EU" then the execution of insmod mac80211, executing insmod ath5k causes an oops. This is caused by wiphy_update_regulatory being called when last_request == NULL, and the call of reg_is_world_roaming (via reg_process_beacons) causes the oops at last_request->initiator != REGDOM_SET_BY_COUNTRY_IE.
If reg_is_world_roaming is modified to check for last_request not being NULL, e.g.
if (last_request && last_request->initiator != REGDOM_SET_BY_COUNTRY_IE &&
then I also get an oops in reg_device_remove where last_request is referenced and there is only a subsequent check for it being NULL.
Even if the above two are fixed, it will not associate with the access point, and iwlist wlan0 channels produces a rather confused list. It appears that, despite the comment, in regulatory_init it is necessary to call regulatory_hint_core even for the pseudo country EU.
Patch1 below covers the points above, although I am not sure how useful the BUG_ON (!last_request) in reg_is_world_roaming is.
Having modified the above, I then found that the regulatory domain was not being updated from the Country IE sent by the access point. It appears that the code following the comment "so we optimize an early check ..." in regulatory_hint_11d is a little over optimized, since if the following if statement is true, every path through that block ends in "goto out;". Patch 2 below allows the Country IE to be processed (note it also needs an extra check around a WARN_ON, and so the preceeding comment to that needs considering).
Quentin Armitage
========= Patch 1 ================================================
net/wireless/reg.c +8 -5
@@ -1128,6 +1128,8 @@ static bool reg_is_world_roaming(structif (is_world_regdom (cfg80211_regdomain->alpha2) || (wiphy->regd &&is_world_regdom (wiphy->regd->alpha2)))return true; + +BUG_ON (!last_request) ;if (last_request->initiator !=NL80211_REGDOM_SET_BY_COUNTRY_IE && wiphy->custom_regulatory)return true;
@@ -2105,7 +2107,8 @@ void reg_device_remove(struct wiphy *wipassert_cfg80211_lock (); - request_wiphy =wiphy_idx_to_wiphy (last_request->wiphy_idx); +if ( last_request ) + request_wiphy =wiphy_idx_to_wiphy (last_request->wiphy_idx);kfree (wiphy->regd);if (!last_request || !request_wiphy)
@@ -2135,11 +2138,11 @@ int regulatory_init(void)/* * The old code still requests for a new regdomain and if * you have CRDA you get it updated, otherwise you get -* stuck with the static values. We ignore "EU" code as -* that is not a valid ISO / IEC 3166 alpha2 +* stuck with the static values. We process "EU" code even though +* that is not a valid ISO / IEC 3166 alpha2, since otherwise the +* channels don't get set properly, and last_request is not set. */ -if (ieee80211_regdom[0 ] !='E' || ieee80211_regdom[1 ] !='U' ) - err =regulatory_hint_core (ieee80211_regdom); + err =regulatory_hint_core (ieee80211_regdom);#else cfg80211_regdomain = cfg80211_world_regdom;
===============================================================
============= Patch 2 =======================================
net/wireless/reg.c +1 -1
@@ -1692,7 +1692,8 @@ void regulatory_hint_11d(struct wiphy *w* to another country, and then gets IEs from an * AP with different settings */ - goto out; + if (likely(last_request->initiator ==
NL80211_REGDOM_SET_BY_COUNTRY_IE))
+ goto out;
} else {
/*
* Ignore IEs coming in on two separate wiphys with
@@ -1721,8 +1722,11 @@ void regulatory_hint_11d(struct wiphy *w
* If we hit this before we add this support we want to be informed of
* it as it would indicate a mistake in the current design */
- if (WARN_ON(reg_same_country_ie_hint(wiphy, checksum)))
- goto free_rd_out;
+ if (likely(last_request->initiator ==NL80211_REGDOM_SET_BY_COUNTRY_IE))
+ {
+ if (WARN_ON(reg_same_country_ie_hint(wiphy, checksum)))
+ goto free_rd_out;
+ }
request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL); if (!request)
=============================================================
Quoted 14 lines · Quentin Armitage
If cfg80211 is compiled with
CONFIG_WIRELESS_OLD_REGULATORYdefined, if insmod is loaded with "insmod cfg80211 ieee80211_regdom=EU" then the execution of insmod mac80211, executing insmod ath5k causes an oops. This is caused bywiphy_update_regulatorybeing called whenlast_request== NULL, and the call ofreg_is_world_roaming(viareg_process_beacons) causes the oops atlast_request->initiator!=REGDOM_SET_BY_COUNTRY_IE.If
reg_is_world_roamingis modified to check forlast_requestnot being NULL, e.g.
if (last_request&&last_request->initiator!=REGDOM_SET_BY_COUNTRY_IE&&
then I also get an oops inreg_device_removewherelast_requestis referenced and there is only a subsequent check for it being NULL.
Quoted 4 lines
Even if the above two are fixed, it will not associate with the access point, and
iwlist wlan0 channelsproduces a rather confused list. It appears that, despite the comment, inregulatory_initit is necessary to callregulatory_hint_coreeven for the pseudo country EU.
Yes, good catch, the entire code in reg.c assumes this was always done. We overlooked the fact when "EU" became the only exemption.
Quoted 2 lines
Patch1 below covers the points above, although I am not sure how useful the
BUG_ON(!last_request) inreg_is_world_roamingis.
Its better to understand the code than sprinkle random BUG_ONs, and in this particular case you've already found the issue. So lets address and fix that appropriately.
Quoted 9 lines
Having modified the above, I then found that the regulatory domain was not being updated from the Country IE sent by the access point.
It
appears that the code following the comment "so we optimize an early check ..." inregulatory_hint_11dis a little over optimized, since if the following if statement is true, every path through that block ends in "goto out;". Patch 2 below allows the Country IE to be processed (note it also needs an extra check around aWARN_ON, and so the preceeding comment to that needs considering).
Thanks for reporting this as well, as you noted we didn't check for the last_request type and just made an assumption. The check should go on earlier.
Will spin some patches to address this. The right solution really is to abandon OLD_REG, but that won't happen for stable right now so will spin some patches to address this for stable.
Thanks,
Luis
Quoted 6 lines · Luis R. Rodriguez
Quoted 6 lines
If
reg_is_world_roamingis modified to check forlast_requestnot being NULL, e.g.
if (last_request&&last_request->initiator!=REGDOM_SET_BY_COUNTRY_IE&&
then I also get an oops inreg_device_removewherelast_requestis referenced and there is only a subsequent check for it being NULL.
Following the commits included in master-2009-03-23, in function reg_device_remove in net/wireless/reg.c there is still a dereference via last_request (request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);) prior to the test for last_request != NULL (if (!last_request || !request_wiphy) )
I suspect that following the patches applied, last_request cannot be NULL, and therefore the check !last_request is not required; otherwise the check needs to be made before the call to wiphy_idx_to_wiphy.
One way or the other, as it stands the code looks wrong.
Quoted 8 lines · Quentin Armitage
Quoted 6 lines · Luis R. Rodriguez
Quoted 6 lines
If
reg_is_world_roamingis modified to check forlast_requestnot being NULL, e.g.
if (last_request&&last_request->initiator!=REGDOM_SET_BY_COUNTRY_IE&&
then I also get an oops inreg_device_removewherelast_requestis referenced and there is only a subsequent check for it being NULL.
Quoted 9 lines
Following the commits included in master-2009-03-23, in function
reg_device_removeinnet/wireless/reg.cthere is still a dereference vialast_request(request_wiphy=wiphy_idx_to_wiphy(last_request->wiphy_idx);) prior to the test forlast_request!= NULL (if (!last_request || !request_wiphy) )
I suspect that following the patches applied,last_requestcannot be NULL, and therefore the check !last_request is not required; otherwise the check needs to be made before the call towiphy_idx_to_wiphy.
One way or the other, as it stands the code looks wrong.
Heh yeah its impossible to get that but I'll send a patch. Thanks.
Luis