Linux wireless drivers development
 help / color / mirror / Atom feed
From: "Luis R. Rodriguez" <lrodriguez@atheros.com>
To: linville@tuxdriver.com, johannes@sipsolutions.net
Cc: linux-wireless@vger.kernel.org,
	"Luis R. Rodriguez" <lrodriguez@atheros.com>
Subject: [PATCH v5 04/15] nl80211: disallow user requests prior to regulatory_init()
Date: Fri, 20 Feb 2009 00:42:39 -0500	[thread overview]
Message-ID: <1235108570-17652-5-git-send-email-lrodriguez@atheros.com> (raw)
In-Reply-To: <1235108570-17652-1-git-send-email-lrodriguez@atheros.com>

If cfg80211 is built into the kernel there is perhaps a small
time window betwen nl80211_init() and regulatory_init() where
cfg80211_regdomain hasn't yet been initialized to let the
wireless core do its work. During that rare case and time
frame (if its even possible) we don't allow user regulatory
changes as cfg80211 is working on enabling its first regulatory
domain.

To check for cfg80211_regdomain we now contend the entire operation
using the cfg80211_mutex.

Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
---
 net/wireless/nl80211.c |   34 ++++++++++++++++++++++++++--------
 1 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 8d38609..c99f0be 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -1882,24 +1882,42 @@ static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
 	int r;
 	char *data = NULL;
 
-	if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
-		return -EINVAL;
+	/*
+	 * You should only get this when cfg80211 hasn't yet initialized
+	 * completely when built-in to the kernel right between the time
+	 * window between nl80211_init() and regulatory_init(), if that is
+	 * even possible.
+	 */
+	mutex_lock(&cfg80211_mutex);
+	if (unlikely(!cfg80211_regdomain)) {
+		r = -EINPROGRESS;
+		goto out;
+	}
+
+	if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) {
+		r = -EINVAL;
+		goto out;
+	}
 
 	data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
 
 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
 	/* We ignore world regdom requests with the old regdom setup */
-	if (is_world_regdom(data))
-		return -EINVAL;
+	if (is_world_regdom(data)) {
+		r = -EINVAL;
+		goto out;
+	}
 #endif
-	mutex_lock(&cfg80211_mutex);
 	r = __regulatory_hint(NULL, REGDOM_SET_BY_USER, data, 0, ENVIRON_ANY);
-	mutex_unlock(&cfg80211_mutex);
-	/* This means the regulatory domain was already set, however
+	/*
+	 * This means the regulatory domain was already set, however
 	 * we don't want to confuse userspace with a "successful error"
-	 * message so lets just treat it as a success */
+	 * message so lets just treat it as a success
+	 */
 	if (r == -EALREADY)
 		r = 0;
+out:
+	mutex_unlock(&cfg80211_mutex);
 	return r;
 }
 
-- 
1.6.0.3


  parent reply	other threads:[~2009-02-20  5:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-20  5:42 [PATCH v5 00/15] cfg80211: add a workqueue for regulatory processing Luis R. Rodriguez
2009-02-20  5:42 ` [PATCH v5 01/15] cfg80211: rename cfg80211_registered_device's idx to wiphy_idx Luis R. Rodriguez
2009-02-20  5:42 ` [PATCH v5 02/15] cfg80211: add wiphy_idx_valid to check for wiphy_idx sanity Luis R. Rodriguez
2009-02-20  5:42 ` [PATCH v5 03/15] cfg80211: rename cfg80211_drv_mutex to cfg80211_mutex Luis R. Rodriguez
2009-02-20  5:42 ` Luis R. Rodriguez [this message]
2009-02-20  5:42 ` [PATCH v5 05/15] cfg80211: add regulatory_hint_core() to separate the core reg hint Luis R. Rodriguez
2009-02-20  5:42 ` [PATCH v5 06/15] cfg80211: propagate -ENOMEM during regulatory_init() Luis R. Rodriguez
2009-02-20  5:42 ` [PATCH v5 07/15] cfg80211: add assert_cfg80211_lock() to ensure proper protection Luis R. Rodriguez
2009-02-20  5:42 ` [PATCH v5 08/15] cfg80211: make regulatory_request use wiphy_idx instead of wiphy Luis R. Rodriguez
2009-02-20  5:42 ` [PATCH v5 09/15] cfg80211: protect first access of last_request on 11d hint under mutex Luis R. Rodriguez
2009-02-20  5:42 ` [PATCH v5 10/15] cfg80211: remove likely from an 11d hint case Luis R. Rodriguez
2009-02-20  5:42 ` [PATCH v5 11/15] cfg80211: free rd on unlikely event on 11d hint Luis R. Rodriguez
2009-02-20  5:42 ` [PATCH v5 12/15] cfg80211: move all regulatory hints to workqueue Luis R. Rodriguez
2009-02-20  5:42 ` [PATCH v5 13/15] cfg80211: comments style cleanup Luis R. Rodriguez
2009-02-20  5:42 ` [PATCH v5 14/15] cfg80211: allow drivers that agree on regulatory to agree Luis R. Rodriguez
2009-02-20  5:42 ` [PATCH v5 15/15] cfg80211: rename regdom_changed to regdom_changes() and use it Luis R. Rodriguez
2009-02-20 17:03 ` [PATCH v5 00/15] cfg80211: add a workqueue for regulatory processing Johannes Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1235108570-17652-5-git-send-email-lrodriguez@atheros.com \
    --to=lrodriguez@atheros.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox