Commit b2e253cf authored by Luis R. Rodriguez's avatar Luis R. Rodriguez Committed by John W. Linville
Browse files

cfg80211: Fix regulatory bug with multiple cards and delays

When two cards are connected with the same regulatory domain
if CRDA had a delayed response then cfg80211's own set regulatory
domain would still be the world regulatory domain. There was a bug
on cfg80211's logic such that it assumed that once you pegged a
request as the last request it was already the currently set
regulatory domain. This would mean we would race setting a stale
regulatory domain to secondary cards which had the same regulatory
domain since the alpha2 would match.

We fix this by processing each regulatory request atomically,
and only move on to the next one once we get it fully processed.
In the case CRDA is not present we will simply world roam.

This issue is only present when you have a slow system and the
CRDA processing is delayed. Because of this it is not a known

Without this fix when a delay is present with CRDA the second card
would end up with an intersected regulatory domain and not allow it
to use the channels it really is designed for. When two cards with
two different regulatory domains were inserted you'd end up
rejecting the second card's regulatory domain request.
This fails with mac80211_hswim's regtest=2 (two requests, same alpha2)
and regtest=3 (two requests, different alpha2) module parameter

This was reproduced and tested against mac80211_hwsim using this
CRDA delayer:

       echo $COUNTRY >> /tmp/log
       sleep 2

And these regulatory tests:

       modprobe mac80211_hwsim regtest=2
       modprobe mac80211_hwsim regtest=3
Reported-by: default avatarMark Mentovai <>
Signed-off-by: default avatarLuis R. Rodriguez <>
Tested-by: default avatarMark Mentovai <>
Tested-by: default avatarBruno Randolf <>
Signed-off-by: default avatarJohn W. Linville <>
parent b0e2880b
......@@ -43,6 +43,12 @@ enum environment_cap {
* @intersect: indicates whether the wireless core should intersect
* the requested regulatory domain with the presently set regulatory
* domain.
* @processed: indicates whether or not this requests has already been
* processed. When the last request is processed it means that the
* currently regulatory domain set on cfg80211 is updated from
* CRDA and can be used by other regulatory requests. When a
* the last request is not yet processed we must yield until it
* is processed before processing any new requests.
* @country_ie_checksum: checksum of the last processed and accepted
* country IE
* @country_ie_env: lets us know if the AP is telling us we are outdoor,
......@@ -54,6 +60,7 @@ struct regulatory_request {
enum nl80211_reg_initiator initiator;
char alpha2[2];
bool intersect;
bool processed;
enum environment_cap country_ie_env;
struct list_head list;
......@@ -1320,6 +1320,21 @@ static int ignore_request(struct wiphy *wiphy,
return -EINVAL;
static void reg_set_request_processed(void)
bool need_more_processing = false;
last_request->processed = true;
if (!list_empty(&reg_requests_list))
need_more_processing = true;
if (need_more_processing)
* __regulatory_hint - hint to the wireless core a regulatory domain
* @wiphy: if the hint comes from country information from an AP, this
......@@ -1395,8 +1410,10 @@ new_request:
* have applied the requested regulatory domain before we just
* inform userspace we have processed the request
if (r == -EALREADY)
if (r == -EALREADY) {
return r;
......@@ -1428,7 +1445,11 @@ static void reg_process_hint(struct regulatory_request *reg_request)
wiphy_update_regulatory(wiphy, initiator);
/* Processes regulatory hints, this is all the NL80211_REGDOM_SET_BY_* */
* Processes regulatory hints, this is all the NL80211_REGDOM_SET_BY_*
* Regulatory hints come on a first come first serve basis and we
* must process each one atomically.
static void reg_process_pending_hints(void)
struct regulatory_request *reg_request;
......@@ -1436,19 +1457,30 @@ static void reg_process_pending_hints(void)
/* When last_request->processed becomes true this will be rescheduled */
if (last_request && !last_request->processed) {
REG_DBG_PRINT("Pending regulatory request, waiting "
"for it to be processed...");
goto out;
while (!list_empty(&reg_requests_list)) {
reg_request = list_first_entry(&reg_requests_list,
struct regulatory_request,
if (list_empty(&reg_requests_list)) {
goto out;
reg_request = list_first_entry(&reg_requests_list,
struct regulatory_request,
......@@ -2057,6 +2089,8 @@ int set_regdom(const struct ieee80211_regdomain *rd)
return r;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment