ipv6: add option to drop unicast encapsulated in L2 multicast
authorJohannes Berg <johannes.berg@intel.com>
Thu, 4 Feb 2016 12:31:19 +0000 (13:31 +0100)
committerStricted <info@stricted.net>
Sat, 28 Jul 2018 05:08:06 +0000 (07:08 +0200)
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 IPv6 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.

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>
Documentation/networking/ip-sysctl.txt
include/linux/ipv6.h
include/uapi/linux/ipv6.h
net/ipv6/addrconf.c
net/ipv6/ip6_input.c

index ce81223e8e78ccfbdf864ac810a0f1b7afb8c5ab..dc5cd37f158025a9ad119fd241080a4e5d002a0f 100644 (file)
@@ -720,6 +720,11 @@ icmp_echo_ignore_broadcasts - BOOLEAN
        TIMESTAMP requests sent to it via broadcast/multicast.
        Default: 1
 
+drop_unicast_in_l2_multicast - BOOLEAN
+       Drop any unicast IPv6 packets that are received in link-layer
+       multicast (or broadcast) frames.
+       By default this is turned off.
+
 icmp_ratelimit - INTEGER
        Limit the maximal rates for sending ICMP packets whose type matches
        icmp_ratemask (see below) to specific targets.
index 9231803c385a75afb5eea0dbffc1a6410a17d7bf..975675000e8418174fc8fa3f98c97b2f7287bc2c 100644 (file)
@@ -48,6 +48,7 @@ struct ipv6_devconf {
        __s32           mc_forwarding;
 #endif
        __s32           disable_ipv6;
+       __s32           drop_unicast_in_l2_multicast;
        __s32           accept_dad;
        __s32           force_tllao;
        __s32           ndisc_notify;
index 8c71e588c6e037c1a9aa7e3f45a52a2c76eb3b4b..396472ee6359d83c9df9e64fa99a3deb882833dd 100644 (file)
@@ -162,6 +162,7 @@ enum {
        DEVCONF_NDISC_NOTIFY,
        DEVCONF_ACCEPT_RA_RT_TABLE,
        DEVCONF_RA_INFO_FLAG,
+       DEVCONF_DROP_UNICAST_IN_L2_MULTICAST,
        DEVCONF_MAX
 };
 
index 7f7768b40e31237239d7c1fe087ff3f4b6018b6d..dc18dc71f4a116ce1bc71d1b30fff5baaf78b96d 100644 (file)
@@ -4342,7 +4342,8 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
        array[DEVCONF_NDISC_NOTIFY] = cnf->ndisc_notify;
 #ifdef CONFIG_MTK_DHCPV6C_WIFI 
        array[DEVCONF_RA_INFO_FLAG] = cnf->ra_info_flag;
-#endif 
+#endif
+       array[DEVCONF_DROP_UNICAST_IN_L2_MULTICAST] = cnf->drop_unicast_in_l2_multicast;
 }
 
 static inline size_t inet6_ifla6_size(void)
@@ -5120,6 +5121,13 @@ static struct addrconf_sysctl_table
                        .proc_handler   = proc_dointvec
                },
 #endif
+               {
+                       .procname       = "drop_unicast_in_l2_multicast",
+                       .data           = &ipv6_devconf.drop_unicast_in_l2_multicast,
+                       .maxlen         = sizeof(int),
+                       .mode           = 0644,
+                       .proc_handler   = proc_dointvec,
+               },
                {
                        /* sentinel */
                }
index 63264c9a15cb4083ad465fadcbc399f35bacf76f..ce45c2b9cddc00401e286d487c9db8283fe53660 100644 (file)
@@ -130,6 +130,16 @@ int ipv6_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
            IPV6_ADDR_MC_SCOPE(&hdr->daddr) == 1)
                goto err;
 
+       /* If enabled, drop unicast packets that were encapsulated in link-layer
+        * multicast or broadcast to protected against the so-called "hole-196"
+        * attack in 802.11 wireless.
+        */
+       if (!ipv6_addr_is_multicast(&hdr->daddr) &&
+           (skb->pkt_type == PACKET_BROADCAST ||
+            skb->pkt_type == PACKET_MULTICAST) &&
+           idev->cnf.drop_unicast_in_l2_multicast)
+               goto err;
+
        /* RFC4291 2.7
         * Nodes must not originate a packet to a multicast address whose scope
         * field contains the reserved value 0; if such a packet is received, it