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

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