netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 1/2] bridge: multicast: add sanity check for general query destination
@ 2014-03-10 21:25 Linus Lüssing
  2014-03-10 21:25 ` [PATCHv2 2/2] bridge: multicast: enable snooping on general queries only Linus Lüssing
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Linus Lüssing @ 2014-03-10 21:25 UTC (permalink / raw)
  To: netdev
  Cc: Florian Westphal, bridge, linux-kernel, David S. Miller,
	Stephen Hemminger, Linus Lüssing, Jan Stancek

General IGMP and MLD queries are supposed to have the multicast
link-local all-nodes address as their destination according to RFC2236
section 9, RFC3376 section 4.1.12/9.1, RFC2710 section 8 and RFC3810
section 5.1.15.

Without this check, such malformed IGMP/MLD queries can result in a
denial of service: The queries are ignored by most IGMP/MLD listeners
therefore they will not respond with an IGMP/MLD report. However,
without this patch these malformed MLD queries would enable the
snooping part in the bridge code, potentially shutting down the
according ports towards these hosts for multicast traffic as the
bridge did not learn about these listeners.

Reported-by: Jan Stancek <jstancek@redhat.com>
Signed-off-by: Linus Lüssing <linus.luessing@web.de>
---
v2: simplified is_general_query variable assignment (thanks Cong!)


 net/bridge/br_multicast.c |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index fb0e36f..e56bae4 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -1181,6 +1181,14 @@ static int br_ip4_multicast_query(struct net_bridge *br,
 			    IGMPV3_MRC(ih3->code) * (HZ / IGMP_TIMER_SCALE) : 1;
 	}
 
+	/* RFC2236+RFC3376 (IGMPv2+IGMPv3) require the multicast link layer
+	 * all-systems destination addresses (224.0.0.1) for general queries
+	 */
+	if (!group && iph->daddr != htonl(INADDR_ALLHOSTS_GROUP)) {
+		err = -EINVAL;
+		goto out;
+	}
+
 	br_multicast_query_received(br, port, &br->ip4_querier, !!iph->saddr,
 				    max_delay);
 
@@ -1228,6 +1236,7 @@ static int br_ip6_multicast_query(struct net_bridge *br,
 	unsigned long max_delay;
 	unsigned long now = jiffies;
 	const struct in6_addr *group = NULL;
+	bool is_general_query;
 	int err = 0;
 
 	spin_lock(&br->multicast_lock);
@@ -1262,6 +1271,16 @@ static int br_ip6_multicast_query(struct net_bridge *br,
 		max_delay = max(msecs_to_jiffies(mldv2_mrc(mld2q)), 1UL);
 	}
 
+	is_general_query = group && ipv6_addr_any(group);
+
+	/* RFC2710+RFC3810 (MLDv1+MLDv2) require the multicast link layer
+	 * all-nodes destination address (ff02::1) for general queries
+	 */
+	if (is_general_query && !ipv6_addr_is_ll_all_nodes(&ip6h->daddr)) {
+		err = -EINVAL;
+		goto out;
+	}
+
 	br_multicast_query_received(br, port, &br->ip6_querier,
 				    !ipv6_addr_any(&ip6h->saddr), max_delay);
 
-- 
1.7.10.4

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

* [PATCHv2 2/2] bridge: multicast: enable snooping on general queries only
  2014-03-10 21:25 [PATCHv2 1/2] bridge: multicast: add sanity check for general query destination Linus Lüssing
@ 2014-03-10 21:25 ` Linus Lüssing
  2014-03-10 22:56   ` Hannes Frederic Sowa
  2014-03-12  3:23   ` David Miller
  2014-03-12  3:23 ` [PATCHv2 1/2] bridge: multicast: add sanity check for general query destination David Miller
  2014-03-12 18:34 ` Ben Hutchings
  2 siblings, 2 replies; 7+ messages in thread
From: Linus Lüssing @ 2014-03-10 21:25 UTC (permalink / raw)
  To: netdev
  Cc: bridge, Stephen Hemminger, David S. Miller, linux-kernel,
	Jan Stancek, Florian Westphal, Linus Lüssing

Without this check someone could easily create a denial of service
by injecting multicast-specific queries to enable the bridge
snooping part if no real querier issuing periodic general queries
is present on the link which would result in the bridge wrongly
shutting down ports for multicast traffic as the bridge did not learn
about these listeners.

With this patch the snooping code is enabled upon receiving valid,
general queries only.

Signed-off-by: Linus Lüssing <linus.luessing@web.de>
---
v2: unchanged

 net/bridge/br_multicast.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index e56bae4..93067ec 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -1127,9 +1127,10 @@ static void br_multicast_query_received(struct net_bridge *br,
 					struct net_bridge_port *port,
 					struct bridge_mcast_querier *querier,
 					int saddr,
+					bool is_general_query,
 					unsigned long max_delay)
 {
-	if (saddr)
+	if (saddr && is_general_query)
 		br_multicast_update_querier_timer(br, querier, max_delay);
 	else if (timer_pending(&querier->timer))
 		return;
@@ -1190,7 +1191,7 @@ static int br_ip4_multicast_query(struct net_bridge *br,
 	}
 
 	br_multicast_query_received(br, port, &br->ip4_querier, !!iph->saddr,
-				    max_delay);
+				    !group, max_delay);
 
 	if (!group)
 		goto out;
@@ -1282,7 +1283,8 @@ static int br_ip6_multicast_query(struct net_bridge *br,
 	}
 
 	br_multicast_query_received(br, port, &br->ip6_querier,
-				    !ipv6_addr_any(&ip6h->saddr), max_delay);
+				    !ipv6_addr_any(&ip6h->saddr),
+				    is_general_query, max_delay);
 
 	if (!group)
 		goto out;
-- 
1.7.10.4

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

* Re: [PATCHv2 2/2] bridge: multicast: enable snooping on general queries only
  2014-03-10 21:25 ` [PATCHv2 2/2] bridge: multicast: enable snooping on general queries only Linus Lüssing
@ 2014-03-10 22:56   ` Hannes Frederic Sowa
  2014-03-11  1:48     ` Linus Lüssing
  2014-03-12  3:23   ` David Miller
  1 sibling, 1 reply; 7+ messages in thread
From: Hannes Frederic Sowa @ 2014-03-10 22:56 UTC (permalink / raw)
  To: Linus Lüssing
  Cc: netdev, Florian Westphal, bridge, linux-kernel, David S. Miller,
	Stephen Hemminger, Jan Stancek

On Mon, Mar 10, 2014 at 10:25:25PM +0100, Linus Lüssing wrote:
>  	br_multicast_query_received(br, port, &br->ip6_querier,
> -				    !ipv6_addr_any(&ip6h->saddr), max_delay);
> +				    !ipv6_addr_any(&ip6h->saddr),
> +				    is_general_query, max_delay);

Just a small nit, maybe for a later patch:

After your change 6565b9eeef194a ("bridge: multicast: add sanity check
for query source addresses"), which is still in -net only, we could
replace !ipv6_addr_any(&ip6h->saddr) with '1'?

Greetings,

  Hannes

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

* Re: [PATCHv2 2/2] bridge: multicast: enable snooping on general queries only
  2014-03-10 22:56   ` Hannes Frederic Sowa
@ 2014-03-11  1:48     ` Linus Lüssing
  0 siblings, 0 replies; 7+ messages in thread
From: Linus Lüssing @ 2014-03-11  1:48 UTC (permalink / raw)
  To: Hannes Frederic Sowa
  Cc: netdev, Florian Westphal, bridge, linux-kernel, David S. Miller,
	Stephen Hemminger, Jan Stancek

[-- Attachment #1: Type: text/plain, Size: 858 bytes --]

On Mon, Mar 10, 2014 at 11:56:00PM +0100, Hannes Frederic Sowa wrote:
> On Mon, Mar 10, 2014 at 10:25:25PM +0100, Linus Lüssing wrote:
> >  	br_multicast_query_received(br, port, &br->ip6_querier,
> > -				    !ipv6_addr_any(&ip6h->saddr), max_delay);
> > +				    !ipv6_addr_any(&ip6h->saddr),
> > +				    is_general_query, max_delay);
> 
> Just a small nit, maybe for a later patch:
> 
> After your change 6565b9eeef194a ("bridge: multicast: add sanity check
> for query source addresses"), which is still in -net only, we could
> replace !ipv6_addr_any(&ip6h->saddr) with '1'?

Aiy, good point, that part is obsolete now and
br_multicast_query_received() could be simplified, right. Going
to do that once we are out of deep-RC territory again and/or
the according commit is available in net-next. Thanks for the
hint!

Cheers, Linus

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCHv2 1/2] bridge: multicast: add sanity check for general query destination
  2014-03-10 21:25 [PATCHv2 1/2] bridge: multicast: add sanity check for general query destination Linus Lüssing
  2014-03-10 21:25 ` [PATCHv2 2/2] bridge: multicast: enable snooping on general queries only Linus Lüssing
@ 2014-03-12  3:23 ` David Miller
  2014-03-12 18:34 ` Ben Hutchings
  2 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2014-03-12  3:23 UTC (permalink / raw)
  To: linus.luessing; +Cc: netdev, fwestpha, bridge, linux-kernel, stephen, jstancek

From: Linus Lüssing <linus.luessing@web.de>
Date: Mon, 10 Mar 2014 22:25:24 +0100

> General IGMP and MLD queries are supposed to have the multicast
> link-local all-nodes address as their destination according to RFC2236
> section 9, RFC3376 section 4.1.12/9.1, RFC2710 section 8 and RFC3810
> section 5.1.15.
> 
> Without this check, such malformed IGMP/MLD queries can result in a
> denial of service: The queries are ignored by most IGMP/MLD listeners
> therefore they will not respond with an IGMP/MLD report. However,
> without this patch these malformed MLD queries would enable the
> snooping part in the bridge code, potentially shutting down the
> according ports towards these hosts for multicast traffic as the
> bridge did not learn about these listeners.
> 
> Reported-by: Jan Stancek <jstancek@redhat.com>
> Signed-off-by: Linus Lüssing <linus.luessing@web.de>

Applied.

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

* Re: [PATCHv2 2/2] bridge: multicast: enable snooping on general queries only
  2014-03-10 21:25 ` [PATCHv2 2/2] bridge: multicast: enable snooping on general queries only Linus Lüssing
  2014-03-10 22:56   ` Hannes Frederic Sowa
@ 2014-03-12  3:23   ` David Miller
  1 sibling, 0 replies; 7+ messages in thread
From: David Miller @ 2014-03-12  3:23 UTC (permalink / raw)
  To: linus.luessing; +Cc: netdev, fwestpha, bridge, linux-kernel, stephen, jstancek

From: Linus Lüssing <linus.luessing@web.de>
Date: Mon, 10 Mar 2014 22:25:25 +0100

> Without this check someone could easily create a denial of service
> by injecting multicast-specific queries to enable the bridge
> snooping part if no real querier issuing periodic general queries
> is present on the link which would result in the bridge wrongly
> shutting down ports for multicast traffic as the bridge did not learn
> about these listeners.
> 
> With this patch the snooping code is enabled upon receiving valid,
> general queries only.
> 
> Signed-off-by: Linus Lüssing <linus.luessing@web.de>

Applied.

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

* Re: [PATCHv2 1/2] bridge: multicast: add sanity check for general query destination
  2014-03-10 21:25 [PATCHv2 1/2] bridge: multicast: add sanity check for general query destination Linus Lüssing
  2014-03-10 21:25 ` [PATCHv2 2/2] bridge: multicast: enable snooping on general queries only Linus Lüssing
  2014-03-12  3:23 ` [PATCHv2 1/2] bridge: multicast: add sanity check for general query destination David Miller
@ 2014-03-12 18:34 ` Ben Hutchings
  2 siblings, 0 replies; 7+ messages in thread
From: Ben Hutchings @ 2014-03-12 18:34 UTC (permalink / raw)
  To: Linus Lüssing
  Cc: netdev, Florian Westphal, bridge, linux-kernel, David S. Miller,
	Stephen Hemminger, Jan Stancek

[-- Attachment #1: Type: text/plain, Size: 459 bytes --]

On Mon, 2014-03-10 at 22:25 +0100, Linus Lüssing wrote:
> General IGMP and MLD queries are supposed to have the multicast
> link-local all-nodes address as their destination according to RFC2236
> section 9, RFC3376 section 4.1.12/9.1, RFC2710 section 8 and RFC3810
> section 5.1.15.
[...]

That reminds me, shouldn't we also check this in igmp_rcv()?

Ben.

-- 
Ben Hutchings
Any sufficiently advanced bug is indistinguishable from a feature.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 811 bytes --]

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

end of thread, other threads:[~2014-03-12 18:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-10 21:25 [PATCHv2 1/2] bridge: multicast: add sanity check for general query destination Linus Lüssing
2014-03-10 21:25 ` [PATCHv2 2/2] bridge: multicast: enable snooping on general queries only Linus Lüssing
2014-03-10 22:56   ` Hannes Frederic Sowa
2014-03-11  1:48     ` Linus Lüssing
2014-03-12  3:23   ` David Miller
2014-03-12  3:23 ` [PATCHv2 1/2] bridge: multicast: add sanity check for general query destination David Miller
2014-03-12 18:34 ` Ben Hutchings

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).