netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ipmr/ip6mr: prevent out-of-bounds vif_table access
@ 2010-03-26  9:45 Nicolas Dichtel
  2010-03-26 16:51 ` David Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Dichtel @ 2010-03-26  9:45 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

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

Hi,

please consider the attached patch about IPv4 and IPv6 multicast.


Regards,
Nicolas

[-- Attachment #2: 0001-net-ipmr-ip6mr-prevent-out-of-bounds-vif_table-acc.patch --]
[-- Type: text/x-diff, Size: 2922 bytes --]

>From fb0b874d55bfe2b81499d4c17598b94ac6c58594 Mon Sep 17 00:00:00 2001
From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date: Fri, 26 Mar 2010 10:12:34 +0100
Subject: [PATCH] net: ipmr/ip6mr: prevent out-of-bounds vif_table access

When cache is unresolved, c->mf[6]c_parent is set to 65535 and
minvif, maxvif are not initialized, hence we must avoid to
parse IIF and OIF.
A second problem can happen when the user dumps a cache entry
where a VIF, that was referenced at creation time, has been
removed.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 net/ipv4/ipmr.c  |   11 +++++++----
 net/ipv6/ip6mr.c |   11 +++++++----
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 0b9d03c..d0a6092 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -1616,17 +1616,20 @@ ipmr_fill_mroute(struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm)
 	int ct;
 	struct rtnexthop *nhp;
 	struct net *net = mfc_net(c);
-	struct net_device *dev = net->ipv4.vif_table[c->mfc_parent].dev;
 	u8 *b = skb_tail_pointer(skb);
 	struct rtattr *mp_head;
 
-	if (dev)
-		RTA_PUT(skb, RTA_IIF, 4, &dev->ifindex);
+	/* If cache is unresolved, don't try to parse IIF and OIF */
+	if (c->mfc_parent > MAXVIFS)
+		return -ENOENT;
+
+	if (VIF_EXISTS(net, c->mfc_parent))
+		RTA_PUT(skb, RTA_IIF, 4, &net->ipv4.vif_table[c->mfc_parent].dev->ifindex);
 
 	mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0));
 
 	for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) {
-		if (c->mfc_un.res.ttls[ct] < 255) {
+		if (VIF_EXISTS(net, ct) && c->mfc_un.res.ttls[ct] < 255) {
 			if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4))
 				goto rtattr_failure;
 			nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp)));
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 23e4ac0..27acfb5 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -1695,17 +1695,20 @@ ip6mr_fill_mroute(struct sk_buff *skb, struct mfc6_cache *c, struct rtmsg *rtm)
 	int ct;
 	struct rtnexthop *nhp;
 	struct net *net = mfc6_net(c);
-	struct net_device *dev = net->ipv6.vif6_table[c->mf6c_parent].dev;
 	u8 *b = skb_tail_pointer(skb);
 	struct rtattr *mp_head;
 
-	if (dev)
-		RTA_PUT(skb, RTA_IIF, 4, &dev->ifindex);
+	/* If cache is unresolved, don't try to parse IIF and OIF */
+	if (c->mf6c_parent > MAXMIFS)
+		return -ENOENT;
+
+	if (MIF_EXISTS(net, c->mf6c_parent))
+		RTA_PUT(skb, RTA_IIF, 4, &net->ipv6.vif6_table[c->mf6c_parent].dev->ifindex);
 
 	mp_head = (struct rtattr *)skb_put(skb, RTA_LENGTH(0));
 
 	for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) {
-		if (c->mfc_un.res.ttls[ct] < 255) {
+		if (MIF_EXISTS(net, ct) && c->mfc_un.res.ttls[ct] < 255) {
 			if (skb_tailroom(skb) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp)) + 4))
 				goto rtattr_failure;
 			nhp = (struct rtnexthop *)skb_put(skb, RTA_ALIGN(sizeof(*nhp)));
-- 
1.5.4.5


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

* Re: [PATCH] net: ipmr/ip6mr: prevent out-of-bounds vif_table access
  2010-03-26  9:45 [PATCH] net: ipmr/ip6mr: prevent out-of-bounds vif_table access Nicolas Dichtel
@ 2010-03-26 16:51 ` David Miller
  2010-03-26 17:19   ` Nicolas Dichtel
  0 siblings, 1 reply; 5+ messages in thread
From: David Miller @ 2010-03-26 16:51 UTC (permalink / raw)
  To: nicolas.dichtel; +Cc: netdev

From: Nicolas Dichtel <nicolas.dichtel@dev.6wind.com>
Date: Fri, 26 Mar 2010 10:45:35 +0100

> please consider the attached patch about IPv4 and IPv6 multicast.

Already fixed by Patrick McHardy recently:

commit a50436f2cd6e85794f7e1aad795ca8302177b896
Author: Patrick McHardy <kaber@trash.net>
Date:   Wed Mar 17 06:04:14 2010 +0000

    net: ipmr/ip6mr: fix potential out-of-bounds vif_table access
    
    mfc_parent of cache entries is used to index into the vif_table and is
    initialised from mfcctl->mfcc_parent. This can take values of to 2^16-1,
    while the vif_table has only MAXVIFS (32) entries. The same problem
    affects ip6mr.
    
    Refuse invalid values to fix a potential out-of-bounds access. Unlike
    the other validity checks, this is checked in ipmr_mfc_add() instead of
    the setsockopt handler since its unused in the delete path and might be
    uninitialized.
    
    Signed-off-by: Patrick McHardy <kaber@trash.net>
    Signed-off-by: David S. Miller <davem@davemloft.net>

diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 8582e12..0b9d03c 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -802,6 +802,9 @@ static int ipmr_mfc_add(struct net *net, struct mfcctl *mfc, int mrtsock)
 	int line;
 	struct mfc_cache *uc, *c, **cp;
 
+	if (mfc->mfcc_parent >= MAXVIFS)
+		return -ENFILE;
+
 	line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr);
 
 	for (cp = &net->ipv4.mfc_cache_array[line];
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 52e0f74..23e4ac0 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -1113,6 +1113,9 @@ static int ip6mr_mfc_add(struct net *net, struct mf6cctl *mfc, int mrtsock)
 	unsigned char ttls[MAXMIFS];
 	int i;
 
+	if (mfc->mf6cc_parent >= MAXMIFS)
+		return -ENFILE;
+
 	memset(ttls, 255, MAXMIFS);
 	for (i = 0; i < MAXMIFS; i++) {
 		if (IF_ISSET(i, &mfc->mf6cc_ifset))

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

* Re: [PATCH] net: ipmr/ip6mr: prevent out-of-bounds vif_table access
  2010-03-26 16:51 ` David Miller
@ 2010-03-26 17:19   ` Nicolas Dichtel
  2010-03-26 18:11     ` David Miller
  2010-03-27 15:34     ` David Miller
  0 siblings, 2 replies; 5+ messages in thread
From: Nicolas Dichtel @ 2010-03-26 17:19 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

yes, but I think that it is not enough, ip[6]mr_mfc_add() is only called via 
setsockopt().

When a multicast packet arrived in ip6_mr_input(), if there is no cache 
ip6mr_cache_unresolved() will be called and this function will add an entry with 
parent == 65535.

And the second problem is that when a vif is removed, no cleanup is made in 
cache entry. Hence, we can have a cache entry which points to an invalid vif 
(dev is set ot NULL).


Regards,
Nicolas

Le 26.03.2010 17:51, David Miller a écrit :
> From: Nicolas Dichtel <nicolas.dichtel@dev.6wind.com>
> Date: Fri, 26 Mar 2010 10:45:35 +0100
> 
>> please consider the attached patch about IPv4 and IPv6 multicast.
> 
> Already fixed by Patrick McHardy recently:
> 
> commit a50436f2cd6e85794f7e1aad795ca8302177b896
> Author: Patrick McHardy <kaber@trash.net>
> Date:   Wed Mar 17 06:04:14 2010 +0000
> 
>     net: ipmr/ip6mr: fix potential out-of-bounds vif_table access
>     
>     mfc_parent of cache entries is used to index into the vif_table and is
>     initialised from mfcctl->mfcc_parent. This can take values of to 2^16-1,
>     while the vif_table has only MAXVIFS (32) entries. The same problem
>     affects ip6mr.
>     
>     Refuse invalid values to fix a potential out-of-bounds access. Unlike
>     the other validity checks, this is checked in ipmr_mfc_add() instead of
>     the setsockopt handler since its unused in the delete path and might be
>     uninitialized.
>     
>     Signed-off-by: Patrick McHardy <kaber@trash.net>
>     Signed-off-by: David S. Miller <davem@davemloft.net>
> 
> diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
> index 8582e12..0b9d03c 100644
> --- a/net/ipv4/ipmr.c
> +++ b/net/ipv4/ipmr.c
> @@ -802,6 +802,9 @@ static int ipmr_mfc_add(struct net *net, struct mfcctl *mfc, int mrtsock)
>  	int line;
>  	struct mfc_cache *uc, *c, **cp;
>  
> +	if (mfc->mfcc_parent >= MAXVIFS)
> +		return -ENFILE;
> +
>  	line = MFC_HASH(mfc->mfcc_mcastgrp.s_addr, mfc->mfcc_origin.s_addr);
>  
>  	for (cp = &net->ipv4.mfc_cache_array[line];
> diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
> index 52e0f74..23e4ac0 100644
> --- a/net/ipv6/ip6mr.c
> +++ b/net/ipv6/ip6mr.c
> @@ -1113,6 +1113,9 @@ static int ip6mr_mfc_add(struct net *net, struct mf6cctl *mfc, int mrtsock)
>  	unsigned char ttls[MAXMIFS];
>  	int i;
>  
> +	if (mfc->mf6cc_parent >= MAXMIFS)
> +		return -ENFILE;
> +
>  	memset(ttls, 255, MAXMIFS);
>  	for (i = 0; i < MAXMIFS; i++) {
>  		if (IF_ISSET(i, &mfc->mf6cc_ifset))

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

* Re: [PATCH] net: ipmr/ip6mr: prevent out-of-bounds vif_table access
  2010-03-26 17:19   ` Nicolas Dichtel
@ 2010-03-26 18:11     ` David Miller
  2010-03-27 15:34     ` David Miller
  1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2010-03-26 18:11 UTC (permalink / raw)
  To: nicolas.dichtel; +Cc: netdev

From: Nicolas Dichtel <nicolas.dichtel@dev.6wind.com>
Date: Fri, 26 Mar 2010 18:19:34 +0100

> yes, but I think that it is not enough, ip[6]mr_mfc_add() is only
> called via setsockopt().
> 
> When a multicast packet arrived in ip6_mr_input(), if there is no
> cache ip6mr_cache_unresolved() will be called and this function will
> add an entry with parent == 65535.
> 
> And the second problem is that when a vif is removed, no cleanup is
> made in cache entry. Hence, we can have a cache entry which points to
> an invalid vif (dev is set ot NULL).

Ok, I'll take another look at your patch, thanks for
explaining.

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

* Re: [PATCH] net: ipmr/ip6mr: prevent out-of-bounds vif_table access
  2010-03-26 17:19   ` Nicolas Dichtel
  2010-03-26 18:11     ` David Miller
@ 2010-03-27 15:34     ` David Miller
  1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2010-03-27 15:34 UTC (permalink / raw)
  To: nicolas.dichtel; +Cc: netdev

From: Nicolas Dichtel <nicolas.dichtel@dev.6wind.com>
Date: Fri, 26 Mar 2010 18:19:34 +0100

> When a multicast packet arrived in ip6_mr_input(), if there is no
> cache ip6mr_cache_unresolved() will be called and this function will
> add an entry with parent == 65535.
> 
> And the second problem is that when a vif is removed, no cleanup is
> made in cache entry. Hence, we can have a cache entry which points to
> an invalid vif (dev is set ot NULL).

I've applied your fix, thanks Nicolas.

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

end of thread, other threads:[~2010-03-27 15:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-26  9:45 [PATCH] net: ipmr/ip6mr: prevent out-of-bounds vif_table access Nicolas Dichtel
2010-03-26 16:51 ` David Miller
2010-03-26 17:19   ` Nicolas Dichtel
2010-03-26 18:11     ` David Miller
2010-03-27 15:34     ` David Miller

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).