lkml.org 
[lkml]   [2011]   [Dec]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[088/104] cfg80211: fix race on init and driver registration
3.1-stable review patch.  If anyone has any objections, please let me know.

------------------

From: "Luis R. Rodriguez" <mcgrof@qca.qualcomm.com>

commit a042994dd377d86bff9446ee76151ceb6267c9ba upstream.

There is a theoretical race that if hit will trigger
a crash. The race is between when we issue the first
regulatory hint, regulatory_hint_core(), gets processed
by the workqueue and between when the first device
gets registered to the wireless core. This is not easy
to reproduce but it was easy to do so through the
regulatory simulator I have been working on. This
is a port of the fix I implemented there [1].

[1] https://github.com/mcgrof/regsim/commit/a246ccf81f059cb662eee288aa13100f631e4cc8

Cc: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Luis R. Rodriguez <mcgrof@qca.qualcomm.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
net/wireless/reg.c | 43 +++++++++++++++++++++++++++----------------
1 file changed, 27 insertions(+), 16 deletions(-)

--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -57,8 +57,17 @@
#define REG_DBG_PRINT(args...)
#endif

+static struct regulatory_request core_request_world = {
+ .initiator = NL80211_REGDOM_SET_BY_CORE,
+ .alpha2[0] = '0',
+ .alpha2[1] = '0',
+ .intersect = false,
+ .processed = true,
+ .country_ie_env = ENVIRON_ANY,
+};
+
/* Receipt of information from last regulatory request */
-static struct regulatory_request *last_request;
+static struct regulatory_request *last_request = &core_request_world;

/* To trigger userspace events */
static struct platform_device *reg_pdev;
@@ -150,7 +159,7 @@ static char user_alpha2[2];
module_param(ieee80211_regdom, charp, 0444);
MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code");

-static void reset_regdomains(void)
+static void reset_regdomains(bool full_reset)
{
/* avoid freeing static information or freeing something twice */
if (cfg80211_regdomain == cfg80211_world_regdom)
@@ -165,6 +174,13 @@ static void reset_regdomains(void)

cfg80211_world_regdom = &world_regdom;
cfg80211_regdomain = NULL;
+
+ if (!full_reset)
+ return;
+
+ if (last_request != &core_request_world)
+ kfree(last_request);
+ last_request = &core_request_world;
}

/*
@@ -175,7 +191,7 @@ static void update_world_regdomain(const
{
BUG_ON(!last_request);

- reset_regdomains();
+ reset_regdomains(false);

cfg80211_world_regdom = rd;
cfg80211_regdomain = rd;
@@ -1396,7 +1412,8 @@ static int __regulatory_hint(struct wiph
}

new_request:
- kfree(last_request);
+ if (last_request != &core_request_world)
+ kfree(last_request);

last_request = pending_request;
last_request->intersect = intersect;
@@ -1566,9 +1583,6 @@ static int regulatory_hint_core(const ch
{
struct regulatory_request *request;

- kfree(last_request);
- last_request = NULL;
-
request = kzalloc(sizeof(struct regulatory_request),
GFP_KERNEL);
if (!request)
@@ -1766,7 +1780,7 @@ static void restore_regulatory_settings(
mutex_lock(&cfg80211_mutex);
mutex_lock(&reg_mutex);

- reset_regdomains();
+ reset_regdomains(true);
restore_alpha2(alpha2, reset_user);

/*
@@ -2035,7 +2049,7 @@ static int __set_regdom(const struct iee
int r;

if (last_request->initiator != NL80211_REGDOM_SET_BY_DRIVER) {
- reset_regdomains();
+ reset_regdomains(false);
cfg80211_regdomain = rd;
return 0;
}
@@ -2056,7 +2070,7 @@ static int __set_regdom(const struct iee
if (r)
return r;

- reset_regdomains();
+ reset_regdomains(false);
cfg80211_regdomain = rd;
return 0;
}
@@ -2081,7 +2095,7 @@ static int __set_regdom(const struct iee

rd = NULL;

- reset_regdomains();
+ reset_regdomains(false);
cfg80211_regdomain = intersected_rd;

return 0;
@@ -2101,7 +2115,7 @@ static int __set_regdom(const struct iee
kfree(rd);
rd = NULL;

- reset_regdomains();
+ reset_regdomains(false);
cfg80211_regdomain = intersected_rd;

return 0;
@@ -2254,11 +2268,8 @@ void /* __init_or_exit */ regulatory_exi
mutex_lock(&cfg80211_mutex);
mutex_lock(&reg_mutex);

- reset_regdomains();
-
- kfree(last_request);
+ reset_regdomains(true);

- last_request = NULL;
dev_set_uevent_suppress(&reg_pdev->dev, true);

platform_device_unregister(reg_pdev);



\
 
 \ /
  Last update: 2011-12-07 17:35    [W:0.400 / U:0.736 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site