diff mbox

mac80211: Reject setting masked mac addresses

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

Commit Message

Helmut Schaa Nov. 27, 2012, 3:43 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>
---

As far as I could see addr_mask is not used by any driver yetbut we're
going to use it in rt2x00 in a follow-up patch.
Helmut

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

Comments

Johannes Berg Nov. 27, 2012, 4:07 p.m. UTC | #1
On Tue, 2012-11-27 at 16:43 +0100, Helmut Schaa wrote:

> +	if (!is_zero_ether_addr(local->hw.wiphy->addr_mask)) {
> +		m = local->hw.wiphy->perm_addr;

I'm not sure I like using perm_addr here. You might actually want to use
a totally different address, but fit all of them into the mask, no?

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. 27, 2012, 5:01 p.m. UTC | #2
On Tue, Nov 27, 2012 at 5:07 PM, Johannes Berg
<johannes@sipsolutions.net> wrote:
> On Tue, 2012-11-27 at 16:43 +0100, Helmut Schaa wrote:
>
>> +     if (!is_zero_ether_addr(local->hw.wiphy->addr_mask)) {
>> +             m = local->hw.wiphy->perm_addr;
>
> I'm not sure I like using perm_addr here. You might actually want to use
> a totally different address, but fit all of them into the mask, no?

Agreed, I'll respin.

Thanks,
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..1f84dd1 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -191,12 +191,35 @@  static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
 static int ieee80211_change_mac(struct net_device *dev, void *addr)
 {
 	struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+	struct ieee80211_local *local = sdata->local;
 	struct sockaddr *sa = addr;
 	int ret;
+	u64 perm, new, mask;
+	u8 *m;
 
 	if (ieee80211_sdata_running(sdata))
 		return -EBUSY;
 
+	if (!is_zero_ether_addr(local->hw.wiphy->addr_mask)) {
+		m = local->hw.wiphy->perm_addr;
+		perm =	((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);
+
+		m = sa->sa_data;
+		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);
+
+		if ((new & ~mask) != (perm & ~mask))
+			return -EINVAL;
+	}
+
 	ret = eth_mac_addr(dev, sa);
 
 	if (ret == 0)