From patchwork Tue Nov 27 15:43:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helmut Schaa X-Patchwork-Id: 1811641 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 840A9DF254 for ; Tue, 27 Nov 2012 15:44:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755789Ab2K0PoG (ORCPT ); Tue, 27 Nov 2012 10:44:06 -0500 Received: from mail-we0-f174.google.com ([74.125.82.174]:33540 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755770Ab2K0PoF (ORCPT ); Tue, 27 Nov 2012 10:44:05 -0500 Received: by mail-we0-f174.google.com with SMTP id d7so4020350wer.19 for ; Tue, 27 Nov 2012 07:44:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=xweDbJe9OXNu/WwMwAbgCFxyCxIV/ffmlpT7PTE0W8g=; b=VQmTYyJWeJTZPocIBVTp3+vHG8frX7dXasISjrH9VgVZ2WJ+kqOo9uMXrFTPtbta4R QAnW4yvpRttu1EZMf2Yjv36LqCZhLnuE+OdpkC/uGVGOSu8HcI1MmWPoWyolMTk0ok5T 0OtG1qA+XhKJfer8NYTu7eu2uecZNl7TccAoTafVfsAdiJR7FAexMVX7lbFxcxag436w nX3Dn2veheB2dUkEZlh0Fiyl/JWVa9fU+duUhReZrJZvvmi1vs4Gx5qJIDh6XSlmJ8Xb UFjpH5hDkuTTE07D0QgVDP2GYGCSDopT3VAxkMGiHrYlnXje1+cxAy/p3uiXZYhE4mSz QMhQ== Received: by 10.216.209.27 with SMTP id r27mr6365178weo.145.1354031043273; Tue, 27 Nov 2012 07:44:03 -0800 (PST) Received: from localhost.localdomain (port-92-198-130-130.static.qsc.de. [92.198.130.130]) by mx.google.com with ESMTPS id gz3sm3001123wib.2.2012.11.27.07.44.02 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 27 Nov 2012 07:44:02 -0800 (PST) From: Helmut Schaa To: johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, Helmut Schaa Subject: [PATCH] mac80211: Reject setting masked mac addresses Date: Tue, 27 Nov 2012 16:43:49 +0100 Message-Id: <1354031029-7956-1-git-send-email-helmut.schaa@googlemail.com> X-Mailer: git-send-email 1.7.7 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org 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 --- 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(-) 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)