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

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