From patchwork Sat Feb 9 06:10:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 219368 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 81A892C007B for ; Sat, 9 Feb 2013 17:11:05 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751547Ab3BIGKy (ORCPT ); Sat, 9 Feb 2013 01:10:54 -0500 Received: from mail-pa0-f47.google.com ([209.85.220.47]:56574 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751213Ab3BIGKx (ORCPT ); Sat, 9 Feb 2013 01:10:53 -0500 Received: by mail-pa0-f47.google.com with SMTP id bj3so2387706pad.20 for ; Fri, 08 Feb 2013 22:10:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:subject:from:to:cc:date:content-type:x-mailer :content-transfer-encoding:mime-version; bh=zC/4J1SGIQTaIfzEnlNRtln98b9jDpBJ3Jov25cxySw=; b=XC41k894ZdNkMGy/f2ML+7uqefUir4rItIpkubhIjJbPA80OiE8PawXmLxbloajV6h 9abMFa1qnwpx2vIBouvoaJ/oSxXN3xUs7HF+AzfDZvSUWsUgfwJzxrL2GSd55R/Z/a+g sEZuATiH1crtOw8f8SlYKSPMeCc3PuI/UMIhaAZzX0hBqjUscv0YsBC/DWC2D/E/wjCO yjvXR2tNMfvVd5vZ/G5CLli3jHVH/SjDfgTnFhttmKotbJ+joDE6K3dJ4k1b+6F2zCG5 1UMpza+jJcFes4s72Ne+h2tQK9zWaFVmxJJcRXRV+mif+vkox31pHZl1udFdSpZ467Bp ZU4Q== X-Received: by 10.66.82.163 with SMTP id j3mr24910701pay.31.1360390253093; Fri, 08 Feb 2013 22:10:53 -0800 (PST) Received: from [172.19.248.245] ([172.19.248.245]) by mx.google.com with ESMTPS id mc1sm558801pbc.34.2013.02.08.22.10.50 (version=SSLv3 cipher=RC4-SHA bits=128/128); Fri, 08 Feb 2013 22:10:51 -0800 (PST) Message-ID: <1360390249.6696.22.camel@edumazet-glaptop> Subject: [PATCH net-next] veth: fix NULL dereference in veth_dellink() From: Eric Dumazet To: David Miller Cc: netdev Date: Fri, 08 Feb 2013 22:10:49 -0800 X-Mailer: Evolution 3.2.3-0ubuntu6 Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eric Dumazet commit d0e2c55e7c940 (veth: avoid a NULL deref in veth_stats_one) added another NULL deref in veth_dellink(). # ip link add name veth1 type veth peer name veth0 # rmmod veth We crash because veth_dellink() is called twice, so we must take care of NULL peer. Signed-off-by: Eric Dumazet --- drivers/net/veth.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/veth.c b/drivers/net/veth.c index e1da42a..07a4af0 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -426,12 +426,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] = {