Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1022933ybe; Wed, 4 Sep 2019 11:17:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHD/wAYqDsZ436pWbd40O2lXN0cqNL+kLYIlRh83VnxNYXAz3lLt4RHTMkLAEAlbe6S+Qn X-Received: by 2002:a17:90a:3d03:: with SMTP id h3mr6437471pjc.49.1567621037345; Wed, 04 Sep 2019 11:17:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567621037; cv=none; d=google.com; s=arc-20160816; b=tL2b5CGi4trCjhASd00ptMEfWNyVeDsxHvs3ntwz+yivPEo/R5sPNl2DMGTwdDsH73 2u0NUxn8j89hJqlFv9qM7eUjwfvhUcWYZmVh4ITxkM20TfgBHIhQucPE4ts5+I9gNRYl FUpwaUJ4ZOPjQ4r0ZXZtqZ8/9pJXxFv/1ocrtFy01qaliGV9MLZMJE46Dedptgi+PABy Jffk0+KSCmMEzCSXxBRzug7B2MRb2MzjuG3257xgnLMNX6MIRgvr742OfdZDXhmWHTup 4SxL0aZoGOxZQBX6LHgbEr+qNrMiYWI0XEsvrdUzg0gmR5CMQdAxhh4oQgGs/l8iUZP3 oJvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=N6/DmTLesB7Wit8jevo0KKDFoKMhQ6bm2TIuZvNvMVQ=; b=gB00iY/XYLDmHnT+PYgtDfgUI7KI2J2yfGm3tfekHn3/doyqB8mXG+nta1Ex6w+cph Tjh4jS7naKxFZ/K9b1B4+WfLCfDwfSHqPyJQ/9Hq5dqeBjQSJp5rLmvituktl/rGCHVa k134XdWsgBv/ybGUNgdR7A1ZcF+ead0292xqhnqGijj68E9caNxIXPTXothGdZVT/Mfm maVvao9tf4i2CN8a0CMI0E9XXGNzWsWhAhFigjWZoQIarTx7sUUbyD+YalYbXgQtS8IO qDi9PAzOy/U3Wep5BPUXBY1omQKZANT6iMykoFJyk5JUf/LjvD3lcIYoquVLvXYtLiZq LwVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BaLi7Aq8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b12si17947739pls.134.2019.09.04.11.17.01; Wed, 04 Sep 2019 11:17:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BaLi7Aq8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390999AbfIDSPh (ORCPT + 99 others); Wed, 4 Sep 2019 14:15:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:32952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390990AbfIDSPf (ORCPT ); Wed, 4 Sep 2019 14:15:35 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E560B206BA; Wed, 4 Sep 2019 18:15:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620934; bh=GVhog9IIZmIBP587bxenKiB18fEW1PN/f7l5RLrKjIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BaLi7Aq8B0QfOaS41vV7GigNX4QA/qm/goYF/dX8q7v0M2HLlggdHm4P0wIPVBCdE 8wYnLrYi0TNS0atduzhY1/D2jCPrn3eAAGH+Tqs53ka/ryP92cHcgV+ln/OBflGOd5 gsozUun8HymYBXC0BU9SmXmbu13gGN9yD9CpMl7c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+c6167ec3de7def23d1e8@syzkaller.appspotmail.com, Arvid Brodin , Cong Wang , "David S. Miller" Subject: [PATCH 5.2 143/143] hsr: implement dellink to clean up resources Date: Wed, 4 Sep 2019 19:54:46 +0200 Message-Id: <20190904175320.090038891@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Cong Wang commit b9a1e627405d68d475a3c1f35e685ccfb5bbe668 upstream. hsr_link_ops implements ->newlink() but not ->dellink(), which leads that resources not released after removing the device, particularly the entries in self_node_db and node_db. So add ->dellink() implementation to replace the priv_destructor. This also makes the code slightly easier to understand. Reported-by: syzbot+c6167ec3de7def23d1e8@syzkaller.appspotmail.com Cc: Arvid Brodin Signed-off-by: Cong Wang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/hsr/hsr_device.c | 13 +++++-------- net/hsr/hsr_device.h | 1 + net/hsr/hsr_framereg.c | 11 ++++++++++- net/hsr/hsr_framereg.h | 3 ++- net/hsr/hsr_netlink.c | 7 +++++++ 5 files changed, 25 insertions(+), 10 deletions(-) --- a/net/hsr/hsr_device.c +++ b/net/hsr/hsr_device.c @@ -344,10 +344,7 @@ static void hsr_announce(struct timer_li rcu_read_unlock(); } -/* According to comments in the declaration of struct net_device, this function - * is "Called from unregister, can be used to call free_netdev". Ok then... - */ -static void hsr_dev_destroy(struct net_device *hsr_dev) +void hsr_dev_destroy(struct net_device *hsr_dev) { struct hsr_priv *hsr; struct hsr_port *port; @@ -356,15 +353,16 @@ static void hsr_dev_destroy(struct net_d hsr_debugfs_term(hsr); - rtnl_lock(); hsr_for_each_port(hsr, port) hsr_del_port(port); - rtnl_unlock(); del_timer_sync(&hsr->prune_timer); del_timer_sync(&hsr->announce_timer); synchronize_rcu(); + + hsr_del_self_node(&hsr->self_node_db); + hsr_del_nodes(&hsr->node_db); } static const struct net_device_ops hsr_device_ops = { @@ -391,7 +389,6 @@ void hsr_dev_setup(struct net_device *de dev->priv_flags |= IFF_NO_QUEUE; dev->needs_free_netdev = true; - dev->priv_destructor = hsr_dev_destroy; dev->hw_features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HIGHDMA | NETIF_F_GSO_MASK | NETIF_F_HW_CSUM | @@ -495,7 +492,7 @@ fail: hsr_for_each_port(hsr, port) hsr_del_port(port); err_add_port: - hsr_del_node(&hsr->self_node_db); + hsr_del_self_node(&hsr->self_node_db); return res; } --- a/net/hsr/hsr_device.h +++ b/net/hsr/hsr_device.h @@ -14,6 +14,7 @@ void hsr_dev_setup(struct net_device *dev); int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], unsigned char multicast_spec, u8 protocol_version); +void hsr_dev_destroy(struct net_device *hsr_dev); void hsr_check_carrier_and_operstate(struct hsr_priv *hsr); bool is_hsr_master(struct net_device *dev); int hsr_get_max_mtu(struct hsr_priv *hsr); --- a/net/hsr/hsr_framereg.c +++ b/net/hsr/hsr_framereg.c @@ -104,7 +104,7 @@ int hsr_create_self_node(struct list_hea return 0; } -void hsr_del_node(struct list_head *self_node_db) +void hsr_del_self_node(struct list_head *self_node_db) { struct hsr_node *node; @@ -117,6 +117,15 @@ void hsr_del_node(struct list_head *self } } +void hsr_del_nodes(struct list_head *node_db) +{ + struct hsr_node *node; + struct hsr_node *tmp; + + list_for_each_entry_safe(node, tmp, node_db, mac_list) + kfree(node); +} + /* Allocate an hsr_node and add it to node_db. 'addr' is the node's address_A; * seq_out is used to initialize filtering of outgoing duplicate frames * originating from the newly added node. --- a/net/hsr/hsr_framereg.h +++ b/net/hsr/hsr_framereg.h @@ -12,7 +12,8 @@ struct hsr_node; -void hsr_del_node(struct list_head *self_node_db); +void hsr_del_self_node(struct list_head *self_node_db); +void hsr_del_nodes(struct list_head *node_db); struct hsr_node *hsr_add_node(struct list_head *node_db, unsigned char addr[], u16 seq_out); struct hsr_node *hsr_get_node(struct hsr_port *port, struct sk_buff *skb, --- a/net/hsr/hsr_netlink.c +++ b/net/hsr/hsr_netlink.c @@ -69,6 +69,12 @@ static int hsr_newlink(struct net *src_n return hsr_dev_finalize(dev, link, multicast_spec, hsr_version); } +static void hsr_dellink(struct net_device *hsr_dev, struct list_head *head) +{ + hsr_dev_destroy(hsr_dev); + unregister_netdevice_queue(hsr_dev, head); +} + static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev) { struct hsr_priv *hsr; @@ -113,6 +119,7 @@ static struct rtnl_link_ops hsr_link_ops .priv_size = sizeof(struct hsr_priv), .setup = hsr_dev_setup, .newlink = hsr_newlink, + .dellink = hsr_dellink, .fill_info = hsr_fill_info, };