ce782e8
From 8c07fa9eda13e835f3f968b2e1c9a8be3a851ff9 Mon Sep 17 00:00:00 2001
ce782e8
From: Jouni Malinen <j@w1.fi>
ce782e8
Date: Thu, 29 Aug 2019 11:52:04 +0300
ce782e8
Subject: [PATCH] AP: Silently ignore management frame from unexpected source
ce782e8
 address
ce782e8
ce782e8
Do not process any received Management frames with unexpected/invalid SA
ce782e8
so that we do not add any state for unexpected STA addresses or end up
ce782e8
sending out frames to unexpected destination. This prevents unexpected
ce782e8
sequences where an unprotected frame might end up causing the AP to send
ce782e8
out a response to another device and that other device processing the
ce782e8
unexpected response.
ce782e8
ce782e8
In particular, this prevents some potential denial of service cases
ce782e8
where the unexpected response frame from the AP might result in a
ce782e8
connected station dropping its association.
ce782e8
ce782e8
Signed-off-by: Jouni Malinen <j@w1.fi>
ce782e8
---
ce782e8
 src/ap/drv_callbacks.c | 13 +++++++++++++
ce782e8
 src/ap/ieee802_11.c    | 12 ++++++++++++
ce782e8
 2 files changed, 25 insertions(+)
ce782e8
ce782e8
diff --git a/src/ap/drv_callbacks.c b/src/ap/drv_callbacks.c
ce782e8
index 31587685fe3b..34ca379edc3d 100644
ce782e8
--- a/src/ap/drv_callbacks.c
ce782e8
+++ b/src/ap/drv_callbacks.c
ce782e8
@@ -131,6 +131,19 @@ int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
ce782e8
 			   "hostapd_notif_assoc: Skip event with no address");
ce782e8
 		return -1;
ce782e8
 	}
ce782e8
+
ce782e8
+	if (is_multicast_ether_addr(addr) ||
ce782e8
+	    is_zero_ether_addr(addr) ||
ce782e8
+	    os_memcmp(addr, hapd->own_addr, ETH_ALEN) == 0) {
ce782e8
+		/* Do not process any frames with unexpected/invalid SA so that
ce782e8
+		 * we do not add any state for unexpected STA addresses or end
ce782e8
+		 * up sending out frames to unexpected destination. */
ce782e8
+		wpa_printf(MSG_DEBUG, "%s: Invalid SA=" MACSTR
ce782e8
+			   " in received indication - ignore this indication silently",
ce782e8
+			   __func__, MAC2STR(addr));
ce782e8
+		return 0;
ce782e8
+	}
ce782e8
+
ce782e8
 	random_add_randomness(addr, ETH_ALEN);
ce782e8
 
ce782e8
 	hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
ce782e8
diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c
ce782e8
index c85a28db44b7..e7065372e158 100644
ce782e8
--- a/src/ap/ieee802_11.c
ce782e8
+++ b/src/ap/ieee802_11.c
ce782e8
@@ -4626,6 +4626,18 @@ int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
ce782e8
 	fc = le_to_host16(mgmt->frame_control);
ce782e8
 	stype = WLAN_FC_GET_STYPE(fc);
ce782e8
 
ce782e8
+	if (is_multicast_ether_addr(mgmt->sa) ||
ce782e8
+	    is_zero_ether_addr(mgmt->sa) ||
ce782e8
+	    os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
ce782e8
+		/* Do not process any frames with unexpected/invalid SA so that
ce782e8
+		 * we do not add any state for unexpected STA addresses or end
ce782e8
+		 * up sending out frames to unexpected destination. */
ce782e8
+		wpa_printf(MSG_DEBUG, "MGMT: Invalid SA=" MACSTR
ce782e8
+			   " in received frame - ignore this frame silently",
ce782e8
+			   MAC2STR(mgmt->sa));
ce782e8
+		return 0;
ce782e8
+	}
ce782e8
+
ce782e8
 	if (stype == WLAN_FC_STYPE_BEACON) {
ce782e8
 		handle_beacon(hapd, mgmt, len, fi);
ce782e8
 		return 1;
ce782e8
-- 
ce782e8
2.20.1
ce782e8