Received: by 10.192.165.148 with SMTP id m20csp813433imm; Fri, 27 Apr 2018 07:57:12 -0700 (PDT) X-Google-Smtp-Source: AB8JxZotZN6oXlkI/AF1KbdjKN9VaGw9BZR2ap5cRLJpy7K81N8J33JkXITsAvMSKcvPWRYQGcQx X-Received: by 2002:a17:902:2702:: with SMTP id c2-v6mr2545316plb.297.1524841032245; Fri, 27 Apr 2018 07:57:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524841032; cv=none; d=google.com; s=arc-20160816; b=uNfl9QfpQ5UUdcHxaBrRwpdP/vMa3FVQXsEaoAxAu9SyE48B++iVBxgD9D9XJfeb0t TleT2IOG12xCVp0EfTs//RRJ4V3i/p4yvStouifE9WbqdLKGnz4zTvnbaCV4RLGhdBnD egbZeunkxLnexohLAWB58l5XaCIMQnVgZgNdo73RYZorm4KK092SG+ZDjbwHSWU5y8Me UouWaChYG8Yv2nT80eAjTVLblwgF1EKov01YCj0wDwObOXfcCLvgeS3wLaXOrdRh3kfu Mf4vc2HC5VH96c44CxI9xPH8arPxFDY74W9PFqA8/OvwJGLa5Titwc/L3dbonIYyExSo cXrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=flA2e6/uDDt66UYmq8oGdXiRjkTlMGbylBQiGzQnf0k=; b=YWbRe0W1pEfxk/SB1F9g/LMbosaMLdb5iLq3k9rD+KVh6aN49UPQzY9nC9CNxhAkKf EWl3Ob+sWCRGSw4wcBSz5Jfww0Kp8qyK/lMr5cX8bq4/QgP41+lPLxeAUXVKXDL5gFgQ y1g+TisryFQ2rH8w66QIU0SZi3b1pJ4nttQ/HDmGZi2vbvWXcszIo9qIWSlPBGZDvZTh idO55o3qzBoGQZ3L9YL1G3GlqnHKKadM0qWRfcXxgkD0iVZl6sphoThX0t4Bm7rMuaGh c86gvtG6X1JW7zPxYepjUeBYpGtj3RqrykiFN1+3gJCxohuNXsrLBZQB9/9gDsFW2dqy j7mQ== ARC-Authentication-Results: i=1; mx.google.com; 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 k18si1427346pfe.13.2018.04.27.07.56.58; Fri, 27 Apr 2018 07:57:12 -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; 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 S934193AbeD0Oz4 (ORCPT + 99 others); Fri, 27 Apr 2018 10:55:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:52452 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934110AbeD0OGY (ORCPT ); Fri, 27 Apr 2018 10:06:24 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 C6AF421890; Fri, 27 Apr 2018 14:06:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C6AF421890 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wolfgang Bumiller , "David S. Miller" Subject: [PATCH 4.14 18/80] net: fix deadlock while clearing neighbor proxy table Date: Fri, 27 Apr 2018 15:58:11 +0200 Message-Id: <20180427135733.827936085@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427135732.928644313@linuxfoundation.org> References: <20180427135732.928644313@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wolfgang Bumiller [ Upstream commit 53b76cdf7e8fecec1d09e38aad2f8579882591a8 ] When coming from ndisc_netdev_event() in net/ipv6/ndisc.c, neigh_ifdown() is called with &nd_tbl, locking this while clearing the proxy neighbor entries when eg. deleting an interface. Calling the table's pndisc_destructor() with the lock still held, however, can cause a deadlock: When a multicast listener is available an IGMP packet of type ICMPV6_MGM_REDUCTION may be sent out. When reaching ip6_finish_output2(), if no neighbor entry for the target address is found, __neigh_create() is called with &nd_tbl, which it'll want to lock. Move the elements into their own list, then unlock the table and perform the destruction. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=199289 Fixes: 6fd6ce2056de ("ipv6: Do not depend on rt->n in ip6_finish_output2().") Signed-off-by: Wolfgang Bumiller Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/neighbour.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -55,7 +55,8 @@ static void neigh_timer_handler(unsigned static void __neigh_notify(struct neighbour *n, int type, int flags, u32 pid); static void neigh_update_notify(struct neighbour *neigh, u32 nlmsg_pid); -static int pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev); +static int pneigh_ifdown_and_unlock(struct neigh_table *tbl, + struct net_device *dev); #ifdef CONFIG_PROC_FS static const struct file_operations neigh_stat_seq_fops; @@ -291,8 +292,7 @@ int neigh_ifdown(struct neigh_table *tbl { write_lock_bh(&tbl->lock); neigh_flush_dev(tbl, dev); - pneigh_ifdown(tbl, dev); - write_unlock_bh(&tbl->lock); + pneigh_ifdown_and_unlock(tbl, dev); del_timer_sync(&tbl->proxy_timer); pneigh_queue_purge(&tbl->proxy_queue); @@ -681,9 +681,10 @@ int pneigh_delete(struct neigh_table *tb return -ENOENT; } -static int pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev) +static int pneigh_ifdown_and_unlock(struct neigh_table *tbl, + struct net_device *dev) { - struct pneigh_entry *n, **np; + struct pneigh_entry *n, **np, *freelist = NULL; u32 h; for (h = 0; h <= PNEIGH_HASHMASK; h++) { @@ -691,16 +692,23 @@ static int pneigh_ifdown(struct neigh_ta while ((n = *np) != NULL) { if (!dev || n->dev == dev) { *np = n->next; - if (tbl->pdestructor) - tbl->pdestructor(n); - if (n->dev) - dev_put(n->dev); - kfree(n); + n->next = freelist; + freelist = n; continue; } np = &n->next; } } + write_unlock_bh(&tbl->lock); + while ((n = freelist)) { + freelist = n->next; + n->next = NULL; + if (tbl->pdestructor) + tbl->pdestructor(n); + if (n->dev) + dev_put(n->dev); + kfree(n); + } return -ENOENT; }