Blame SOURCES/rh1447073-nl80211-Fix-race-condition-in-detecting-MAC-change.patch

b645d2
From 290834df69556b903b49f2a45671cc62b44f13bb Mon Sep 17 00:00:00 2001
b645d2
From: Beniamino Galvani <bgalvani@redhat.com>
b645d2
Date: Fri, 28 Apr 2017 17:59:30 +0200
b645d2
Subject: [PATCH] nl80211: Fix race condition in detecting MAC change
b645d2
b645d2
Commit 3e0272ca00ce1df35b45e7d739dd7e935f13fd84 ('nl80211: Re-read MAC
b645d2
address on RTM_NEWLINK') added the detection of external changes to MAC
b645d2
address when the interface is brought up.
b645d2
b645d2
If the interface state is changed quickly enough, wpa_supplicant may
b645d2
receive the netlink message for the !IFF_UP event when the interface
b645d2
has already been brought up and would ignore the next netlink IFF_UP
b645d2
message, missing the MAC change.
b645d2
b645d2
Fix this by also reloading the MAC address when a !IFF_UP event is
b645d2
received with the interface up, because this implies that the
b645d2
interface went down and up again, possibly changing the address.
b645d2
b645d2
Signed-off-by: Beniamino Galvani <bgalvani@redhat.com>
b645d2
---
b645d2
 src/drivers/driver_nl80211.c | 47 +++++++++++++++++++++++++-------------------
b645d2
 1 file changed, 27 insertions(+), 20 deletions(-)
b645d2
b645d2
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
b645d2
index af1cb84..24fad29 100644
b645d2
--- a/src/drivers/driver_nl80211.c
b645d2
+++ b/src/drivers/driver_nl80211.c
b645d2
@@ -933,6 +933,30 @@ nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len)
b645d2
 }
b645d2
 
b645d2
 
b645d2
+static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv,
b645d2
+				int ifindex)
b645d2
+{
b645d2
+	struct i802_bss *bss;
b645d2
+	u8 addr[ETH_ALEN];
b645d2
+
b645d2
+	bss = get_bss_ifindex(drv, ifindex);
b645d2
+	if (bss &&
b645d2
+	    linux_get_ifhwaddr(drv->global->ioctl_sock,
b645d2
+			       bss->ifname, addr) < 0) {
b645d2
+		wpa_printf(MSG_DEBUG,
b645d2
+			   "nl80211: %s: failed to re-read MAC address",
b645d2
+			   bss->ifname);
b645d2
+	} else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) {
b645d2
+		wpa_printf(MSG_DEBUG,
b645d2
+			   "nl80211: Own MAC address on ifindex %d (%s) changed from "
b645d2
+			   MACSTR " to " MACSTR,
b645d2
+			   ifindex, bss->ifname,
b645d2
+			   MAC2STR(bss->addr), MAC2STR(addr));
b645d2
+		os_memcpy(bss->addr, addr, ETH_ALEN);
b645d2
+	}
b645d2
+}
b645d2
+
b645d2
+
b645d2
 static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
b645d2
 						 struct ifinfomsg *ifi,
b645d2
 						 u8 *buf, size_t len)
b645d2
@@ -997,6 +1021,8 @@ static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
b645d2
 		namebuf[0] = '\0';
b645d2
 		if (if_indextoname(ifi->ifi_index, namebuf) &&
b645d2
 		    linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) {
b645d2
+			/* Re-read MAC address as it may have changed */
b645d2
+			nl80211_refresh_mac(drv, ifi->ifi_index);
b645d2
 			wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
b645d2
 				   "event since interface %s is up", namebuf);
b645d2
 			drv->ignore_if_down_event = 0;
b645d2
@@ -1044,27 +1070,8 @@ static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
b645d2
 				   "event since interface %s is marked "
b645d2
 				   "removed", drv->first_bss->ifname);
b645d2
 		} else {
b645d2
-			struct i802_bss *bss;
b645d2
-			u8 addr[ETH_ALEN];
b645d2
-
b645d2
 			/* Re-read MAC address as it may have changed */
b645d2
-			bss = get_bss_ifindex(drv, ifi->ifi_index);
b645d2
-			if (bss &&
b645d2
-			    linux_get_ifhwaddr(drv->global->ioctl_sock,
b645d2
-					       bss->ifname, addr) < 0) {
b645d2
-				wpa_printf(MSG_DEBUG,
b645d2
-					   "nl80211: %s: failed to re-read MAC address",
b645d2
-					   bss->ifname);
b645d2
-			} else if (bss &&
b645d2
-				   os_memcmp(addr, bss->addr, ETH_ALEN) != 0) {
b645d2
-				wpa_printf(MSG_DEBUG,
b645d2
-					   "nl80211: Own MAC address on ifindex %d (%s) changed from "
b645d2
-					   MACSTR " to " MACSTR,
b645d2
-					   ifi->ifi_index, bss->ifname,
b645d2
-					   MAC2STR(bss->addr),
b645d2
-					   MAC2STR(addr));
b645d2
-				os_memcpy(bss->addr, addr, ETH_ALEN);
b645d2
-			}
b645d2
+			nl80211_refresh_mac(drv, ifi->ifi_index);
b645d2
 
b645d2
 			wpa_printf(MSG_DEBUG, "nl80211: Interface up");
b645d2
 			drv->if_disabled = 0;
b645d2
-- 
b645d2
2.9.3
b645d2