Blame SOURCES/rh1434434-wpa_supplicant-Don-t-reply-to-EAPOL-if-pkt_type-is-P.patch

b645d2
From d89edb6112f54fb65036c31eba291bda5fcad2b3 Mon Sep 17 00:00:00 2001
b645d2
Message-Id: <d89edb6112f54fb65036c31eba291bda5fcad2b3.1522770749.git.davide.caratti@gmail.com>
b645d2
From: Davide Caratti <davide.caratti@gmail.com>
b645d2
Date: Wed, 28 Mar 2018 16:34:56 +0200
b645d2
Subject: [PATCH] wpa_supplicant: Don't reply to EAPOL if pkt_type is
b645d2
 PACKET_OTHERHOST
b645d2
b645d2
When wpa_supplicant is running on a Linux interface that is configured in
b645d2
promiscuous mode, and it is not a member of a bridge, incoming EAPOL
b645d2
packets are processed regardless of the Destination Address in the frame.
b645d2
As a consequence, there are situations where wpa_supplicant replies to
b645d2
EAPOL packets that are not destined for it.
b645d2
b645d2
This behavior seems undesired (see IEEE Std 802.1X-2010, 11.4.a), and can
b645d2
be avoided by attaching a BPF filter that lets the kernel discard packets
b645d2
having pkt_type equal to PACKET_OTHERHOST.
b645d2
b645d2
Signed-off-by: Davide Caratti <davide.caratti@gmail.com>
b645d2
---
b645d2
 src/l2_packet/l2_packet.h       |  1 +
b645d2
 src/l2_packet/l2_packet_linux.c | 23 +++++++++++++++++++++++
b645d2
 wpa_supplicant/wpa_supplicant.c |  5 +++++
b645d2
 3 files changed, 29 insertions(+)
b645d2
b645d2
diff --git a/src/l2_packet/l2_packet.h b/src/l2_packet/l2_packet.h
b645d2
index 2a4524582..53871774b 100644
b645d2
--- a/src/l2_packet/l2_packet.h
b645d2
+++ b/src/l2_packet/l2_packet.h
b645d2
@@ -42,6 +42,7 @@ struct l2_ethhdr {
b645d2
 enum l2_packet_filter_type {
b645d2
 	L2_PACKET_FILTER_DHCP,
b645d2
 	L2_PACKET_FILTER_NDISC,
b645d2
+	L2_PACKET_FILTER_PKTTYPE,
b645d2
 };
b645d2
 
b645d2
 /**
b645d2
diff --git a/src/l2_packet/l2_packet_linux.c b/src/l2_packet/l2_packet_linux.c
b645d2
index 65b490679..291c9dd26 100644
b645d2
--- a/src/l2_packet/l2_packet_linux.c
b645d2
+++ b/src/l2_packet/l2_packet_linux.c
b645d2
@@ -84,6 +84,26 @@ static const struct sock_fprog ndisc_sock_filter = {
b645d2
 	.filter = ndisc_sock_filter_insns,
b645d2
 };
b645d2
 
b645d2
+/* drop packet if skb->pkt_type is PACKET_OTHERHOST (0x03). Generated by:
b645d2
+ * $ bpfc - <
b645d2
+ * > ldb #type
b645d2
+ * > jeq #0x03, drop
b645d2
+ * > pass: ret #-1
b645d2
+ * > drop: ret #0
b645d2
+ * > EOF
b645d2
+ */
b645d2
+static struct sock_filter pkt_type_filter_insns[] = {
b645d2
+	{ 0x30, 0, 0, 0xfffff004 },
b645d2
+	{ 0x15, 1, 0, 0x00000003 },
b645d2
+	{ 0x6, 0, 0, 0xffffffff },
b645d2
+	{ 0x6, 0, 0, 0x00000000 },
b645d2
+};
b645d2
+
b645d2
+static const struct sock_fprog pkt_type_sock_filter = {
b645d2
+	.len = ARRAY_SIZE(pkt_type_filter_insns),
b645d2
+	.filter = pkt_type_filter_insns,
b645d2
+};
b645d2
+
b645d2
 
b645d2
 int l2_packet_get_own_addr(struct l2_packet_data *l2, u8 *addr)
b645d2
 {
b645d2
@@ -471,6 +491,9 @@ int l2_packet_set_packet_filter(struct l2_packet_data *l2,
b645d2
 	case L2_PACKET_FILTER_NDISC:
b645d2
 		sock_filter = &ndisc_sock_filter;
b645d2
 		break;
b645d2
+	case L2_PACKET_FILTER_PKTTYPE:
b645d2
+		sock_filter = &pkt_type_sock_filter;
b645d2
+		break;
b645d2
 	default:
b645d2
 		return -1;
b645d2
 	}
b645d2
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
b645d2
index 2a05ef910..dcec68a03 100644
b645d2
--- a/wpa_supplicant/wpa_supplicant.c
b645d2
+++ b/wpa_supplicant/wpa_supplicant.c
b645d2
@@ -4014,6 +4014,11 @@ int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s)
b645d2
 					   wpa_supplicant_rx_eapol, wpa_s, 0);
b645d2
 		if (wpa_s->l2 == NULL)
b645d2
 			return -1;
b645d2
+
b645d2
+		if (l2_packet_set_packet_filter(wpa_s->l2,
b645d2
+						L2_PACKET_FILTER_PKTTYPE))
b645d2
+			wpa_dbg(wpa_s, MSG_DEBUG,
b645d2
+				"Failed to attach pkt_type filter");
b645d2
 	} else {
b645d2
 		const u8 *addr = wpa_drv_get_mac_addr(wpa_s);
b645d2
 		if (addr)
b645d2
-- 
b645d2
2.14.3
b645d2