All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: igmp: Use correct source address on IGMPv3 reports
@ 2017-12-11 19:13 Kevin Cernekee
  2017-12-13 17:15 ` Andrew Lunn
  2017-12-13 18:52 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Kevin Cernekee @ 2017-12-11 19:13 UTC (permalink / raw)
  To: davem, kuznet, yoshfuji; +Cc: netdev, andrew, linux-kernel

Closing a multicast socket after the final IPv4 address is deleted
from an interface can generate a membership report that uses the
source IP from a different interface.  The following test script, run
from an isolated netns, reproduces the issue:

    #!/bin/bash

    ip link add dummy0 type dummy
    ip link add dummy1 type dummy
    ip link set dummy0 up
    ip link set dummy1 up
    ip addr add 10.1.1.1/24 dev dummy0
    ip addr add 192.168.99.99/24 dev dummy1

    tcpdump -U -i dummy0 &
    socat EXEC:"sleep 2" \
        UDP4-DATAGRAM:239.101.1.68:8889,ip-add-membership=239.0.1.68:10.1.1.1 &

    sleep 1
    ip addr del 10.1.1.1/24 dev dummy0
    sleep 5
    kill %tcpdump

RFC 3376 specifies that the report must be sent with a valid IP source
address from the destination subnet, or from address 0.0.0.0.  Add an
extra check to make sure this is the case.

Signed-off-by: Kevin Cernekee <cernekee@chromium.org>
---
 net/ipv4/igmp.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index d1f8f302dbf3..0672264c9d93 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -89,6 +89,7 @@
 #include <linux/rtnetlink.h>
 #include <linux/times.h>
 #include <linux/pkt_sched.h>
+#include <linux/byteorder/generic.h>
 
 #include <net/net_namespace.h>
 #include <net/arp.h>
@@ -321,6 +322,23 @@ igmp_scount(struct ip_mc_list *pmc, int type, int gdeleted, int sdeleted)
 	return scount;
 }
 
+/* source address selection per RFC 3376 section 4.2.13 */
+static __be32 igmpv3_get_srcaddr(struct net_device *dev,
+				 const struct flowi4 *fl4)
+{
+	struct in_device *in_dev = __in_dev_get_rcu(dev);
+
+	if (!in_dev)
+		return htonl(INADDR_ANY);
+
+	for_ifa(in_dev) {
+		if (inet_ifa_match(fl4->saddr, ifa))
+			return fl4->saddr;
+	} endfor_ifa(in_dev);
+
+	return htonl(INADDR_ANY);
+}
+
 static struct sk_buff *igmpv3_newpack(struct net_device *dev, unsigned int mtu)
 {
 	struct sk_buff *skb;
@@ -368,7 +386,7 @@ static struct sk_buff *igmpv3_newpack(struct net_device *dev, unsigned int mtu)
 	pip->frag_off = htons(IP_DF);
 	pip->ttl      = 1;
 	pip->daddr    = fl4.daddr;
-	pip->saddr    = fl4.saddr;
+	pip->saddr    = igmpv3_get_srcaddr(dev, &fl4);
 	pip->protocol = IPPROTO_IGMP;
 	pip->tot_len  = 0;	/* filled in later */
 	ip_select_ident(net, skb, NULL);
-- 
2.15.1.424.g9478a66081-goog

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: igmp: Use correct source address on IGMPv3 reports
  2017-12-11 19:13 [PATCH] net: igmp: Use correct source address on IGMPv3 reports Kevin Cernekee
@ 2017-12-13 17:15 ` Andrew Lunn
  2017-12-13 18:52 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2017-12-13 17:15 UTC (permalink / raw)
  To: Kevin Cernekee; +Cc: davem, kuznet, yoshfuji, netdev, linux-kernel

On Mon, Dec 11, 2017 at 11:13:45AM -0800, Kevin Cernekee wrote:
> Closing a multicast socket after the final IPv4 address is deleted
> from an interface can generate a membership report that uses the
> source IP from a different interface.  The following test script, run
> from an isolated netns, reproduces the issue:
> 
>     #!/bin/bash
> 
>     ip link add dummy0 type dummy
>     ip link add dummy1 type dummy
>     ip link set dummy0 up
>     ip link set dummy1 up
>     ip addr add 10.1.1.1/24 dev dummy0
>     ip addr add 192.168.99.99/24 dev dummy1
> 
>     tcpdump -U -i dummy0 &
>     socat EXEC:"sleep 2" \
>         UDP4-DATAGRAM:239.101.1.68:8889,ip-add-membership=239.0.1.68:10.1.1.1 &
> 
>     sleep 1
>     ip addr del 10.1.1.1/24 dev dummy0
>     sleep 5
>     kill %tcpdump
> 
> RFC 3376 specifies that the report must be sent with a valid IP source
> address from the destination subnet, or from address 0.0.0.0.  Add an
> extra check to make sure this is the case.
> 
> Signed-off-by: Kevin Cernekee <cernekee@chromium.org>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: igmp: Use correct source address on IGMPv3 reports
  2017-12-11 19:13 [PATCH] net: igmp: Use correct source address on IGMPv3 reports Kevin Cernekee
  2017-12-13 17:15 ` Andrew Lunn
@ 2017-12-13 18:52 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-12-13 18:52 UTC (permalink / raw)
  To: cernekee; +Cc: kuznet, yoshfuji, netdev, andrew, linux-kernel

From: Kevin Cernekee <cernekee@chromium.org>
Date: Mon, 11 Dec 2017 11:13:45 -0800

> Closing a multicast socket after the final IPv4 address is deleted
> from an interface can generate a membership report that uses the
> source IP from a different interface.  The following test script, run
> from an isolated netns, reproduces the issue:
> 
>     #!/bin/bash
> 
>     ip link add dummy0 type dummy
>     ip link add dummy1 type dummy
>     ip link set dummy0 up
>     ip link set dummy1 up
>     ip addr add 10.1.1.1/24 dev dummy0
>     ip addr add 192.168.99.99/24 dev dummy1
> 
>     tcpdump -U -i dummy0 &
>     socat EXEC:"sleep 2" \
>         UDP4-DATAGRAM:239.101.1.68:8889,ip-add-membership=239.0.1.68:10.1.1.1 &
> 
>     sleep 1
>     ip addr del 10.1.1.1/24 dev dummy0
>     sleep 5
>     kill %tcpdump
> 
> RFC 3376 specifies that the report must be sent with a valid IP source
> address from the destination subnet, or from address 0.0.0.0.  Add an
> extra check to make sure this is the case.
> 
> Signed-off-by: Kevin Cernekee <cernekee@chromium.org>
...
> +	return htonl(INADDR_ANY);
> +}
> +
>  static struct sk_buff *igmpv3_newpack(struct net_device *dev, unsigned int mtu)
>  {
>  	struct sk_buff *skb;
> @@ -368,7 +386,7 @@ static struct sk_buff *igmpv3_newpack(struct net_device *dev, unsigned int mtu)
>  	pip->frag_off = htons(IP_DF);
>  	pip->ttl      = 1;
>  	pip->daddr    = fl4.daddr;
> -	pip->saddr    = fl4.saddr;
> +	pip->saddr    = igmpv3_get_srcaddr(dev, &fl4);
>  	pip->protocol = IPPROTO_IGMP;
>  	pip->tot_len  = 0;	/* filled in later */
>  	ip_select_ident(net, skb, NULL);

Ok, and I checked that MC source address validation on the receiver
will pass because:

	if (ipv4_is_zeronet(saddr)) {
		if (!ipv4_is_local_multicast(daddr))
			return -EINVAL;

that check in ip_mc_validate_source() won't trigger.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-12-13 18:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-11 19:13 [PATCH] net: igmp: Use correct source address on IGMPv3 reports Kevin Cernekee
2017-12-13 17:15 ` Andrew Lunn
2017-12-13 18:52 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.