Patchwork [precise,sru,5/5] veth: fix NULL dereference in veth_dellink()

login
register
mail settings
Submitter Chris J Arges
Date March 25, 2014, 9:03 p.m.
Message ID <1395781387-10928-6-git-send-email-chris.j.arges@canonical.com>
Download mbox | patch
Permalink /patch/333712/
State New
Headers show

Comments

Chris J Arges - March 25, 2014, 9:03 p.m.
From: Eric Dumazet <edumazet@google.com>

BugLink: http://bugs.launchpad.net/bugs/1201869

commit d0e2c55e7c940 (veth: avoid a NULL deref in veth_stats_one)
added another NULL deref in veth_dellink().

We crash because veth_dellink() is called twice, so we must
take care of NULL peer.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit f45a5c267da35174e22cec955093a7513dc1623d)

Signed-off-by: Chris J Arges <chris.j.arges@canonical.com>
---
 drivers/net/veth.c |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Patch

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index e093646..3634032 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -423,12 +423,13 @@  static void veth_dellink(struct net_device *dev, struct list_head *head)
 	 * not being freed before one RCU grace period.
 	 */
 	RCU_INIT_POINTER(priv->peer, NULL);
-
-	priv = netdev_priv(peer);
-	RCU_INIT_POINTER(priv->peer, NULL);
-
 	unregister_netdevice_queue(dev, head);
-	unregister_netdevice_queue(peer, head);
+
+	if (peer) {
+		priv = netdev_priv(peer);
+		RCU_INIT_POINTER(priv->peer, NULL);
+		unregister_netdevice_queue(peer, head);
+	}
 }
 
 static const struct nla_policy veth_policy[VETH_INFO_MAX + 1] = {