Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ipv4: add option to drop unicast encapsulated in L2 multicast

In order to solve a problem with 802.11, the so-called hole-196 attack,
add an option (sysctl) called "drop_unicast_in_l2_multicast" which, if
enabled, causes the stack to drop IPv4 unicast packets encapsulated in
link-layer multi- or broadcast frames. Such frames can (as an attack)
be created by any member of the same wireless network and transmitted
as valid encrypted frames since the symmetric key for broadcast frames
is shared between all stations.

Additionally, enabling this option provides compliance with a SHOULD
clause of RFC 1122.

Reviewed-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Johannes Berg and committed by
David S. Miller
12b74dfa ccad0993

+34 -1
+7
Documentation/networking/ip-sysctl.txt
··· 1216 1216 promote a corresponding secondary IP address instead of 1217 1217 removing all the corresponding secondary IP addresses. 1218 1218 1219 + drop_unicast_in_l2_multicast - BOOLEAN 1220 + Drop any unicast IP packets that are received in link-layer 1221 + multicast (or broadcast) frames. 1222 + This behavior (for multicast) is actually a SHOULD in RFC 1223 + 1122, but is disabled by default for compatibility reasons. 1224 + Default: off (0) 1225 + 1219 1226 1220 1227 tag - INTEGER 1221 1228 Allows you to write a number, which can be used as required.
+1
include/uapi/linux/ip.h
··· 165 165 IPV4_DEVCONF_IGMPV2_UNSOLICITED_REPORT_INTERVAL, 166 166 IPV4_DEVCONF_IGMPV3_UNSOLICITED_REPORT_INTERVAL, 167 167 IPV4_DEVCONF_IGNORE_ROUTES_WITH_LINKDOWN, 168 + IPV4_DEVCONF_DROP_UNICAST_IN_L2_MULTICAST, 168 169 __IPV4_DEVCONF_MAX 169 170 }; 170 171
+2
net/ipv4/devinet.c
··· 2192 2192 "promote_secondaries"), 2193 2193 DEVINET_SYSCTL_FLUSHING_ENTRY(ROUTE_LOCALNET, 2194 2194 "route_localnet"), 2195 + DEVINET_SYSCTL_FLUSHING_ENTRY(DROP_UNICAST_IN_L2_MULTICAST, 2196 + "drop_unicast_in_l2_multicast"), 2195 2197 }, 2196 2198 }; 2197 2199
+24 -1
net/ipv4/ip_input.c
··· 362 362 rt = skb_rtable(skb); 363 363 if (rt->rt_type == RTN_MULTICAST) { 364 364 IP_UPD_PO_STATS_BH(net, IPSTATS_MIB_INMCAST, skb->len); 365 - } else if (rt->rt_type == RTN_BROADCAST) 365 + } else if (rt->rt_type == RTN_BROADCAST) { 366 366 IP_UPD_PO_STATS_BH(net, IPSTATS_MIB_INBCAST, skb->len); 367 + } else if (skb->pkt_type == PACKET_BROADCAST || 368 + skb->pkt_type == PACKET_MULTICAST) { 369 + struct in_device *in_dev = __in_dev_get_rcu(skb->dev); 370 + 371 + /* RFC 1122 3.3.6: 372 + * 373 + * When a host sends a datagram to a link-layer broadcast 374 + * address, the IP destination address MUST be a legal IP 375 + * broadcast or IP multicast address. 376 + * 377 + * A host SHOULD silently discard a datagram that is received 378 + * via a link-layer broadcast (see Section 2.4) but does not 379 + * specify an IP multicast or broadcast destination address. 380 + * 381 + * This doesn't explicitly say L2 *broadcast*, but broadcast is 382 + * in a way a form of multicast and the most common use case for 383 + * this is 802.11 protecting against cross-station spoofing (the 384 + * so-called "hole-196" attack) so do it for both. 385 + */ 386 + if (in_dev && 387 + IN_DEV_ORCONF(in_dev, DROP_UNICAST_IN_L2_MULTICAST)) 388 + goto drop; 389 + } 367 390 368 391 return dst_input(skb); 369 392