netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] ip6tnl: fix use after free of fb_tnl_dev
       [not found] <20131113211430.1ad3bb7d@gandalf.local.home>
@ 2013-11-14 14:47 ` Nicolas Dichtel
  2013-11-14 15:40   ` Willem de Bruijn
  2013-11-14 22:05   ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Nicolas Dichtel @ 2013-11-14 14:47 UTC (permalink / raw)
  To: rostedt
  Cc: linux-kernel, stable, gregkh, williams, linux-rt-users, lclaudio,
	davem, netdev, Nicolas Dichtel, Willem de Bruijn

Bug has been introduced by commit bb8140947a24 ("ip6tnl: allow to use rtnl ops
on fb tunnel").

When ip6_tunnel.ko is unloaded, FB device is delete by rtnl_link_unregister()
and then we try to use the pointer in ip6_tnl_destroy_tunnels().

Let's add an handler for dellink, which will never remove the FB tunnel. With
this patch it will no more be possible to remove it via 'ip link del ip6tnl0',
but it's safer.

The same fix was already proposed by Willem de Bruijn <willemb@google.com> for
sit interfaces.

CC: Willem de Bruijn <willemb@google.com>
Reported-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 net/ipv6/ip6_tunnel.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 583b77e2f69b..c1e11b5d6ccc 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1635,6 +1635,15 @@ static int ip6_tnl_changelink(struct net_device *dev, struct nlattr *tb[],
 	return ip6_tnl_update(t, &p);
 }
 
+static void ip6_tnl_dellink(struct net_device *dev, struct list_head *head)
+{
+	struct net *net = dev_net(dev);
+	struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
+
+	if (dev != ip6n->fb_tnl_dev)
+		unregister_netdevice_queue(dev, head);
+}
+
 static size_t ip6_tnl_get_size(const struct net_device *dev)
 {
 	return
@@ -1699,6 +1708,7 @@ static struct rtnl_link_ops ip6_link_ops __read_mostly = {
 	.validate	= ip6_tnl_validate,
 	.newlink	= ip6_tnl_newlink,
 	.changelink	= ip6_tnl_changelink,
+	.dellink	= ip6_tnl_dellink,
 	.get_size	= ip6_tnl_get_size,
 	.fill_info	= ip6_tnl_fill_info,
 };
@@ -1715,9 +1725,9 @@ static struct xfrm6_tunnel ip6ip6_handler __read_mostly = {
 	.priority	=	1,
 };
 
-static void __net_exit ip6_tnl_destroy_tunnels(struct ip6_tnl_net *ip6n)
+static void __net_exit ip6_tnl_destroy_tunnels(struct net *net)
 {
-	struct net *net = dev_net(ip6n->fb_tnl_dev);
+	struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
 	struct net_device *dev, *aux;
 	int h;
 	struct ip6_tnl *t;
@@ -1785,10 +1795,8 @@ err_alloc_dev:
 
 static void __net_exit ip6_tnl_exit_net(struct net *net)
 {
-	struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
-
 	rtnl_lock();
-	ip6_tnl_destroy_tunnels(ip6n);
+	ip6_tnl_destroy_tunnels(net);
 	rtnl_unlock();
 }
 
-- 
1.8.4.1

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

* Re: [PATCH net] ip6tnl: fix use after free of fb_tnl_dev
  2013-11-14 14:47 ` [PATCH net] ip6tnl: fix use after free of fb_tnl_dev Nicolas Dichtel
@ 2013-11-14 15:40   ` Willem de Bruijn
  2013-11-14 22:05   ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: Willem de Bruijn @ 2013-11-14 15:40 UTC (permalink / raw)
  To: Nicolas Dichtel
  Cc: rostedt, linux-kernel, stable, gregkh, williams, linux-rt-users,
	lclaudio, David Miller, netdev

On Thu, Nov 14, 2013 at 9:47 AM, Nicolas Dichtel
<nicolas.dichtel@6wind.com> wrote:
> Bug has been introduced by commit bb8140947a24 ("ip6tnl: allow to use rtnl ops
> on fb tunnel").
>
> When ip6_tunnel.ko is unloaded, FB device is delete by rtnl_link_unregister()
> and then we try to use the pointer in ip6_tnl_destroy_tunnels().
>
> Let's add an handler for dellink, which will never remove the FB tunnel. With
> this patch it will no more be possible to remove it via 'ip link del ip6tnl0',
> but it's safer.
>
> The same fix was already proposed by Willem de Bruijn <willemb@google.com> for
> sit interfaces.
>
> CC: Willem de Bruijn <willemb@google.com>
> Reported-by: Steven Rostedt <rostedt@goodmis.org>
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

Acked-by: Willem de Bruijn <willemb@google.com>

Also ran a test similar to the one for sit: `modprobe ip6_tunnel;
rmmod ip6_tunnel` with CONFIG_DEBUG_SLAB=y. This exposed the bug at
HEAD, completes successfully with the patch applied.

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

* Re: [PATCH net] ip6tnl: fix use after free of fb_tnl_dev
  2013-11-14 14:47 ` [PATCH net] ip6tnl: fix use after free of fb_tnl_dev Nicolas Dichtel
  2013-11-14 15:40   ` Willem de Bruijn
@ 2013-11-14 22:05   ` David Miller
  2013-11-14 22:18     ` Steven Rostedt
  1 sibling, 1 reply; 4+ messages in thread
From: David Miller @ 2013-11-14 22:05 UTC (permalink / raw)
  To: nicolas.dichtel
  Cc: rostedt, linux-kernel, stable, gregkh, williams, linux-rt-users,
	lclaudio, netdev, willemb

From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date: Thu, 14 Nov 2013 15:47:03 +0100

> Bug has been introduced by commit bb8140947a24 ("ip6tnl: allow to use rtnl ops
> on fb tunnel").
> 
> When ip6_tunnel.ko is unloaded, FB device is delete by rtnl_link_unregister()
> and then we try to use the pointer in ip6_tnl_destroy_tunnels().
> 
> Let's add an handler for dellink, which will never remove the FB tunnel. With
> this patch it will no more be possible to remove it via 'ip link del ip6tnl0',
> but it's safer.
> 
> The same fix was already proposed by Willem de Bruijn <willemb@google.com> for
> sit interfaces.
> 
> CC: Willem de Bruijn <willemb@google.com>
> Reported-by: Steven Rostedt <rostedt@goodmis.org>
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

Applied and queued up for -stable, thanks for being so proactive about this
Nicolas.

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

* Re: [PATCH net] ip6tnl: fix use after free of fb_tnl_dev
  2013-11-14 22:05   ` David Miller
@ 2013-11-14 22:18     ` Steven Rostedt
  0 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2013-11-14 22:18 UTC (permalink / raw)
  To: David Miller
  Cc: nicolas.dichtel, linux-kernel, stable, gregkh, williams,
	linux-rt-users, lclaudio, netdev, willemb

On Thu, 14 Nov 2013 17:05:29 -0500 (EST)
David Miller <davem@davemloft.net> wrote:

 
> Applied and queued up for -stable, thanks for being so proactive about this
> Nicolas.

I should also note that I added this back to 3.10.18 and the bug goes
away.

If it's not too late:

Tested-by: Steven Rostedt <rostedt@goodmis.org>

-- Steve

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

end of thread, other threads:[~2013-11-14 22:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20131113211430.1ad3bb7d@gandalf.local.home>
2013-11-14 14:47 ` [PATCH net] ip6tnl: fix use after free of fb_tnl_dev Nicolas Dichtel
2013-11-14 15:40   ` Willem de Bruijn
2013-11-14 22:05   ` David Miller
2013-11-14 22:18     ` Steven Rostedt

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