Skip to contentSkip to conversation

arp: Do not update neighbours from ARP in L2 multicast/broadcast frames

PATCH Superseded Star Chang 2 participants 3 messages Nov 23

Subsystems (4)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Star Chang

author
#0 lore raw

PATCH v6 1/1 arp: Do not update neighbours from ARP in L2 multicast/broadcast frames

The drop_unicast_in_l2_multicast sysctl drops unicast IP packets that are received in link-layer multicast or broadcast frames. On Wi-Fi this protects against the "Hole-196" attack, where any station that knows the group key injects frames as group-addressed traffic.

ARP is not covered. A broadcast ARP request or reply with sip set to the gateway address and sha set to the attacker MAC still creates or updates the gateway neighbour entry, so the attacker can poison the ARP cache of other stations. ARP requests are legitimately broadcast and cannot be dropped, and drop_gratuitous_arp only catches sip == tip.

When drop_unicast_in_l2_multicast is set, do not pass ARP packets received in L2 multicast/broadcast frames to neigh_event_ns() or neigh_update(), so they can neither create nor change neighbour entries. Requests for local and proxied addresses are still answered; neighbours are learned from unicast replies to our own requests.

Fixes 12b74dfadb5a ("ipv4: add option to drop unicast encapsulated in L2 multicast")

---
v6:
- Instead of dropping L2 BMC ARP replies, skip neigh_event_ns() and neigh_update() for any ARP received in L2 BMC frames, which also covers broadcast requests with sip = gateway (Julian)
- Drop the frame and release reply_dst on that path (Julian)
v5: https://lore.kernel.org/netdev/[email protected]/
v4: https://lore.kernel.org/netdev/[email protected]/
v3: https://lore.kernel.org/netdev/[email protected]/

 Documentation/networking/ip-sysctl.rst |  4 ++-
 net/ipv4/arp.c                         | 38 +++++++++++++++++++-------
 2 files changed, 31 insertions(+), 11 deletions(-)
Documentation/networking/ip-sysctl.rst +3 -1
index 208f46967ee5..d603588266b4 100644
@@ -2298,7 +2298,9 @@ promote_secondaries - BOOLEAN
 
 drop_unicast_in_l2_multicast - BOOLEAN
 	Drop any unicast IP packets that are received in link-layer
-	multicast (or broadcast) frames.
+	multicast (or broadcast) frames. ARP packets received in such
+	frames are not used to create or update neighbour entries,
+	but ARP requests for local addresses are still answered.
 
 	This behavior (for multicast) is actually a SHOULD in RFC
 	1122, but is disabled by default for compatibility reasons.
net/ipv4/arp.c +28 -10
index d409f606aec0..17b5f32736aa 100644
@@ -714,6 +714,7 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
 	struct neighbour *n;
 	struct dst_entry *reply_dst = NULL;
 	bool is_garp = false;
+	bool bmc_no_learn;
 
 	/* arp_rcv below verifies the ARP header and verifies the device
 	 * is ARP'able.
@@ -791,6 +792,10 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
 	    (!IN_DEV_ROUTE_LOCALNET(in_dev) && ipv4_is_loopback(tip)))
 		goto out_free_skb;
 
+	bmc_no_learn = (skb->pkt_type == PACKET_BROADCAST ||
+			   skb->pkt_type == PACKET_MULTICAST) &&
+			  IN_DEV_ORCONF(in_dev, DROP_UNICAST_IN_L2_MULTICAST);
+
  /*
   *	For some 802.11 wireless deployments (and possibly other networks),
   *	there will be an ARP proxy and gratuitous ARP frames are attacks
@@ -850,14 +855,19 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
 			if (!dont_send && IN_DEV_ARPFILTER(in_dev))
 				dont_send = arp_filter(sip, tip, dev);
 			if (!dont_send) {
-				n = neigh_event_ns(&arp_tbl, sha, &sip, dev);
-				if (n) {
-					arp_send_dst(ARPOP_REPLY, ETH_P_ARP,
-						     sip, dev, tip, sha,
-						     dev->dev_addr, sha,
-						     reply_dst);
-					neigh_release(n);
+				n = NULL;
+				/* Do not learn the sender from a BMC frame */
+				if (!bmc_no_learn) {
+					n = neigh_event_ns(&arp_tbl, sha, &sip, dev);
+					if (!n)
+						goto out_consume_skb;
 				}
+				arp_send_dst(ARPOP_REPLY, ETH_P_ARP,
+					     sip, dev, tip, sha,
+					     dev->dev_addr, sha,
+					     reply_dst);
+				if (n)
+					neigh_release(n);
 			}
 			goto out_consume_skb;
 		} else if (IN_DEV_FORWARD(in_dev)) {
@@ -866,9 +876,11 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
 			     arp_fwd_pvlan(in_dev, dev, rt, sip, tip) ||
 			     (rt->dst.dev != dev &&
 			      pneigh_lookup(&arp_tbl, net, &tip, dev)))) {
-				n = neigh_event_ns(&arp_tbl, sha, &sip, dev);
-				if (n)
-					neigh_release(n);
+				if (!bmc_no_learn) {
+					n = neigh_event_ns(&arp_tbl, sha, &sip, dev);
+					if (n)
+						neigh_release(n);
+				}
 
 				if (NEIGH_CB(skb)->flags & LOCALLY_ENQUEUED ||
 				    skb->pkt_type == PACKET_HOST ||
@@ -887,6 +899,10 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
 		}
 	}
 
+	/* ARP received in L2 BMC frames must not change the neighbour table */
+	if (bmc_no_learn)
+		goto out_drop_dst;
+
 	/* Update our ARP tables */
 
 	n = __neigh_lookup(&arp_tbl, &sip, dev, 0);
@@ -945,6 +961,8 @@ static int arp_process(struct net *net, struct sock *sk, struct sk_buff *skb)
 	dst_release(reply_dst);
 	return NET_RX_SUCCESS;
 
+out_drop_dst:
+	dst_release(reply_dst);
 out_free_skb:
 	kfree_skb(skb);
 	return NET_RX_DROP;
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.

Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
author
#2 lore raw

Hi,

How it was found: internal security review of Wi-Fi "Hole-196" mitigations, which found that drop_unicast_in_l2_multicast does not cover ARP.

Triggered: yes, reproduced in a lab setup on a WPA2-PSK network. Another station injected a group-addressed ARP reply (sip = gateway, sha = attacker MAC), and after the locktime the victim's gateway neighbour entry was changed to the attacker MAC (seen with "ip neigh"). There are no kernel messages or crashes, only the wrong neighbour entry. The broadcast request variant (sip = gateway, tip = other host) was pointed out by Julian during review; it goes through the same neigh_event_ns() path.

Best regards,
Star