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

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