Skip to contentSkip to conversation

ipv6: Fix MLD Query message check

PATCH Superseded Hangbin Liu 2 participants 3 messages Jun 25, 2014 – Jun 27, 2014

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ipv6: Fix MLD Query message check

Based on RFC3810 6.2, we also need to check the hop limit and router alert option besides source address.

---
 net/ipv6/mcast.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
net/ipv6/mcast.c +12 -2
index 08b367c..fe27a77 100644
@@ -1301,8 +1301,18 @@ int igmp6_event_query(struct sk_buff *skb)
 	len = ntohs(ipv6_hdr(skb)->payload_len) + sizeof(struct ipv6hdr);
 	len -= skb_network_header_len(skb);
 
-	/* Drop queries with not link local source */
-	if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL))
+	/* RFC3810 6.2
+	 * Upon reception of an MLD message that contains a Query, the node
+	 * checks if the source address of the message is a valid link-local
+	 * address, if the Hop Limit is set to 1, and if the Router Alert
+	 * option is present in the Hop-By-Hop Options header of the IPv6
+	 * packet.  If any of these checks fails, the packet is dropped.
+	 */
+	if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL) ||
+	    ipv6_hdr(skb)->hop_limit != 1 ||
+	    ipv6_hdr(skb)->nexthdr != NEXTHDR_HOP ||
+	    !(IP6CB(skb)->flags & IP6SKB_ROUTERALERT) ||
+	    IP6CB(skb)->ra != htons(IPV6_OPT_ROUTERALERT_MLD))
 		return -EINVAL;
 
 	idev = __in6_dev_get(skb->dev);
Signature · 1 line
1.8.1.4
maintainer
#1 lore raw

From: Hangbin Liu <[email protected]>
Date: Wed, 25 Jun 2014 09:31:07 +0800

Quoted 10 lines
net/ipv6/mcast.c +4 -2
@@ -1301,8 +1301,18 @@ int igmp6_event_query(struct sk_buff *skb)
 	len = ntohs(ipv6_hdr(skb)->payload_len) + sizeof(struct ipv6hdr);
 	len -= skb_network_header_len(skb);
 
-	/* Drop queries with not link local source */
-	if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL))
+	/* RFC3810 6.2
+	 * Upon reception of an MLD message that contains a Query, the node
+	 * checks if the source address of the message is a valid link-local
+	 * address, if the Hop Limit is set to 1, and if the Router Alert

net/ipv6/mcast.c int igmp6_event_query(struct sk_buff *skb) · line 1317

Quoted 10 lines
net/ipv6/mcast.c +8 -0
+	 * option is present in the Hop-By-Hop Options header of the IPv6
+	 * packet.  If any of these checks fails, the packet is dropped.
+	 */
+	if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL) ||
+	    ipv6_hdr(skb)->hop_limit != 1 ||
+	    ipv6_hdr(skb)->nexthdr != NEXTHDR_HOP ||
+	    !(IP6CB(skb)->flags & IP6SKB_ROUTERALERT) ||
+	    IP6CB(skb)->ra != htons(IPV6_OPT_ROUTERALERT_MLD))
 		return -EINVAL;
 

Does the NEXTHDR_HOP have the be exactly the next extension header present? I think you need to allow for more flexibility here.

In any event, the only way the IP6SKB_ROUTERALERT bit can be set is if there were hop-by-hop options present, so testing only the bit itself is sufficient.

The forwarding path simplifies the check in this way too.

So please adjust this to only check the bit and remove the NEXTHDR_HOP test.

Thanks.

#2 lore raw

2014-06-27 8:33 GMT+08:00 David Miller <[email protected]>:

Quoted 27 lines

From: Hangbin Liu <[email protected]>
Date: Wed, 25 Jun 2014 09:31:07 +0800

Quoted 10 lines
net/ipv6/mcast.c +4 -2
@@ -1301,8 +1301,18 @@ int igmp6_event_query(struct sk_buff *skb)
      len = ntohs(ipv6_hdr(skb)->payload_len) + sizeof(struct ipv6hdr);
      len -= skb_network_header_len(skb);
 
-     /* Drop queries with not link local source */
-     if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL))
+     /* RFC3810 6.2
+      * Upon reception of an MLD message that contains a Query, the node
+      * checks if the source address of the message is a valid link-local
+      * address, if the Hop Limit is set to 1, and if the Router Alert

net/ipv6/mcast.c int igmp6_event_query(struct sk_buff *skb) · line 1317

Quoted 10 lines
net/ipv6/mcast.c +8 -0
+      * option is present in the Hop-By-Hop Options header of the IPv6
+      * packet.  If any of these checks fails, the packet is dropped.
+      */
+     if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL) ||
+         ipv6_hdr(skb)->hop_limit != 1 ||
+         ipv6_hdr(skb)->nexthdr != NEXTHDR_HOP ||
+         !(IP6CB(skb)->flags & IP6SKB_ROUTERALERT) ||
+         IP6CB(skb)->ra != htons(IPV6_OPT_ROUTERALERT_MLD))
              return -EINVAL;
 

Does the NEXTHDR_HOP have the be exactly the next extension header present? I think you need to allow for more flexibility here.

Quoted 9 lines

In any event, the only way the IP6SKB_ROUTERALERT bit can be set is if there were hop-by-hop options present, so testing only the bit itself is sufficient.

The forwarding path simplifies the check in this way too.

So please adjust this to only check the bit and remove the NEXTHDR_HOP test.

Thanks for this advise, will send a v3 patch

Best regards
Hangbin Liu