Commit 458f4f9e authored by Johannes Berg's avatar Johannes Berg

regulatory: use RCU to protect global and wiphy regdomains

To simplify the locking and not require cfg80211_mutex
(which nl80211 uses to access the global regdomain) and
also to make it possible for drivers to access their
wiphy->regd safely, use RCU to protect these pointers.
Acked-by: default avatarLuis R. Rodriguez <mcgrof@do-not-panic.com>
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 379b82f4
...@@ -2369,7 +2369,7 @@ struct wiphy { ...@@ -2369,7 +2369,7 @@ struct wiphy {
/* fields below are read-only, assigned by cfg80211 */ /* fields below are read-only, assigned by cfg80211 */
const struct ieee80211_regdomain *regd; const struct ieee80211_regdomain __rcu *regd;
/* the item in /sys/class/ieee80211/ points to this, /* the item in /sys/class/ieee80211/ points to this,
* you need use set_wiphy_dev() (see below) */ * you need use set_wiphy_dev() (see below) */
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <linux/rcupdate.h>
/** /**
* enum environment_cap - Environment parsed from country IE * enum environment_cap - Environment parsed from country IE
...@@ -101,6 +102,7 @@ struct ieee80211_reg_rule { ...@@ -101,6 +102,7 @@ struct ieee80211_reg_rule {
}; };
struct ieee80211_regdomain { struct ieee80211_regdomain {
struct rcu_head rcu_head;
u32 n_reg_rules; u32 n_reg_rules;
char alpha2[2]; char alpha2[2];
u8 dfs_region; u8 dfs_region;
......
...@@ -3787,12 +3787,8 @@ static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) ...@@ -3787,12 +3787,8 @@ static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
* window between nl80211_init() and regulatory_init(), if that is * window between nl80211_init() and regulatory_init(), if that is
* even possible. * even possible.
*/ */
mutex_lock(&cfg80211_mutex); if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
if (unlikely(!cfg80211_regdomain)) {
mutex_unlock(&cfg80211_mutex);
return -EINPROGRESS; return -EINPROGRESS;
}
mutex_unlock(&cfg80211_mutex);
if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
return -EINVAL; return -EINVAL;
...@@ -4152,6 +4148,7 @@ static int nl80211_update_mesh_config(struct sk_buff *skb, ...@@ -4152,6 +4148,7 @@ static int nl80211_update_mesh_config(struct sk_buff *skb,
static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
{ {
const struct ieee80211_regdomain *regdom;
struct sk_buff *msg; struct sk_buff *msg;
void *hdr = NULL; void *hdr = NULL;
struct nlattr *nl_reg_rules; struct nlattr *nl_reg_rules;
...@@ -4174,35 +4171,36 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) ...@@ -4174,35 +4171,36 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
if (!hdr) if (!hdr)
goto put_failure; goto put_failure;
if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
cfg80211_regdomain->alpha2) ||
(cfg80211_regdomain->dfs_region &&
nla_put_u8(msg, NL80211_ATTR_DFS_REGION,
cfg80211_regdomain->dfs_region)))
goto nla_put_failure;
if (reg_last_request_cell_base() && if (reg_last_request_cell_base() &&
nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
NL80211_USER_REG_HINT_CELL_BASE)) NL80211_USER_REG_HINT_CELL_BASE))
goto nla_put_failure; goto nla_put_failure;
rcu_read_lock();
regdom = rcu_dereference(cfg80211_regdomain);
if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
(regdom->dfs_region &&
nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
goto nla_put_failure_rcu;
nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
if (!nl_reg_rules) if (!nl_reg_rules)
goto nla_put_failure; goto nla_put_failure_rcu;
for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { for (i = 0; i < regdom->n_reg_rules; i++) {
struct nlattr *nl_reg_rule; struct nlattr *nl_reg_rule;
const struct ieee80211_reg_rule *reg_rule; const struct ieee80211_reg_rule *reg_rule;
const struct ieee80211_freq_range *freq_range; const struct ieee80211_freq_range *freq_range;
const struct ieee80211_power_rule *power_rule; const struct ieee80211_power_rule *power_rule;
reg_rule = &cfg80211_regdomain->reg_rules[i]; reg_rule = &regdom->reg_rules[i];
freq_range = &reg_rule->freq_range; freq_range = &reg_rule->freq_range;
power_rule = &reg_rule->power_rule; power_rule = &reg_rule->power_rule;
nl_reg_rule = nla_nest_start(msg, i); nl_reg_rule = nla_nest_start(msg, i);
if (!nl_reg_rule) if (!nl_reg_rule)
goto nla_put_failure; goto nla_put_failure_rcu;
if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
reg_rule->flags) || reg_rule->flags) ||
...@@ -4216,10 +4214,11 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) ...@@ -4216,10 +4214,11 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
power_rule->max_antenna_gain) || power_rule->max_antenna_gain) ||
nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
power_rule->max_eirp)) power_rule->max_eirp))
goto nla_put_failure; goto nla_put_failure_rcu;
nla_nest_end(msg, nl_reg_rule); nla_nest_end(msg, nl_reg_rule);
} }
rcu_read_unlock();
nla_nest_end(msg, nl_reg_rules); nla_nest_end(msg, nl_reg_rules);
...@@ -4227,6 +4226,8 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) ...@@ -4227,6 +4226,8 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
err = genlmsg_reply(msg, info); err = genlmsg_reply(msg, info);
goto out; goto out;
nla_put_failure_rcu:
rcu_read_unlock();
nla_put_failure: nla_put_failure:
genlmsg_cancel(msg, hdr); genlmsg_cancel(msg, hdr);
put_failure: put_failure:
......
This diff is collapsed.
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
extern const struct ieee80211_regdomain *cfg80211_regdomain; extern const struct ieee80211_regdomain __rcu *cfg80211_regdomain;
bool is_world_regdom(const char *alpha2); bool is_world_regdom(const char *alpha2);
bool reg_supported_dfs_region(u8 dfs_region); bool reg_supported_dfs_region(u8 dfs_region);
......
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