diff mbox

[PATCHv2] mac80211: Reject setting masked mac addresses

Message ID 1354036986-30027-1-git-send-email-helmut.schaa@googlemail.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Helmut Schaa Nov. 27, 2012, 5:23 p.m. UTC
If a driver registers an address mask we should ensure that no interface
gets an address assigned that isn't covered by the registered address
mask.

Signed-off-by: Helmut Schaa <helmut.schaa@googlemail.com>
---

Changes since v1:
* Don't match against perm address, just verify if all virtual interface
  addresses fit within registered mask.

 net/mac80211/iface.c |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)

Comments

Johannes Berg Nov. 28, 2012, 12:53 p.m. UTC | #1
On Tue, 2012-11-27 at 18:23 +0100, Helmut Schaa wrote:
> If a driver registers an address mask we should ensure that no interface
> gets an address assigned that isn't covered by the registered address
> mask.

Applied with a few changes, please check.

johannes

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Helmut Schaa Nov. 28, 2012, 1:40 p.m. UTC | #2
On Wed, Nov 28, 2012 at 1:53 PM, Johannes Berg
<johannes@sipsolutions.net> wrote:
> On Tue, 2012-11-27 at 18:23 +0100, Helmut Schaa wrote:
>> If a driver registers an address mask we should ensure that no interface
>> gets an address assigned that isn't covered by the registered address
>> mask.
>
> Applied with a few changes, please check.

Yep, looks good. Thanks for fixing up the locking!
Helmut
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index bc3e3e1..6b116a0 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -188,6 +188,41 @@  static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
 	return 0;
 }
 
+static int ieee80211_verify_mac(struct ieee80211_local *local, u8 *addr)
+{
+	struct ieee80211_sub_if_data *sdata;
+	u64 new, mask, tmp;
+	u8 *m;
+
+	if (!is_zero_ether_addr(local->hw.wiphy->addr_mask)) {
+		m = addr;
+		new =	((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
+			((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
+			((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
+
+		m = local->hw.wiphy->addr_mask;
+		mask =	((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
+			((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
+			((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
+
+
+		list_for_each_entry(sdata, &local->interfaces, list) {
+			if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
+				continue;
+
+			m = sdata->vif.addr;
+			tmp =	((u64)m[0] << 5*8) | ((u64)m[1] << 4*8) |
+				((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
+				((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
+
+			if ((new & ~mask) != (tmp & ~mask))
+				return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
 static int ieee80211_change_mac(struct net_device *dev, void *addr)
 {
 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
@@ -197,6 +232,10 @@  static int ieee80211_change_mac(struct net_device *dev, void *addr)
 	if (ieee80211_sdata_running(sdata))
 		return -EBUSY;
 
+	ret = ieee80211_verify_mac(sdata->local, sa->sa_data);
+	if (ret)
+		return ret;
+
 	ret = eth_mac_addr(dev, sa);
 
 	if (ret == 0)