Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp49038imu; Thu, 8 Nov 2018 14:33:33 -0800 (PST) X-Google-Smtp-Source: AJdET5freY/vp5RMCmyldCXWXEASMfmKUI/962h96JfKMHgY+xnEIuqHBf+JRQNB1Q0RpJiqMlvX X-Received: by 2002:a17:902:9698:: with SMTP id n24-v6mr6518620plp.9.1541716413132; Thu, 08 Nov 2018 14:33:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541716413; cv=none; d=google.com; s=arc-20160816; b=cjHOxLu5amdufaS4NxtGoq2lCJSd8Muu5LqY8CYfknfpFOjlzs3CHCTmE4h/luAjRX WIJ1cKDo0pnuFSWWuUooV+TNvyk4DAoZngAboqa1CqTqpODb555s10NB4wqgrJBbg1/A PYBj3rOADDxdAOCLEY6DvWNr7FcoFvNu05sypudp6wKr6cijkVokkmo1R2Y7ecYNQWpW PDo4j2NmvG2v3vDDxsaIoSEksc5Gqcy4/t+sywYpgkU/zuTAXprsHLAmWskB2oypxPYL vD1Z0Fggpd+0RDgEeT5Y4Q2Lx87b2QsWiZpLICM6Y84AFDV1n5yUCYI07wo5WfQloAjZ pcDg== 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=Io5ZsdTY4l7MfQ/ZO+5wyBtwWNc6NXF5l+qq2cQo09I=; b=McAdOCiulozRHODGR+6mU15yBWBr211q89x+qjve7yOE8wIhsyCjl7yA97cJIMHF59 z6Wl+wLvIJf+5a78oRYuDqCY9ZIcRI39uL5TeYyDIsEqJPVR+6GTiKpL+Dt0u9KMQG9W mo9Vumzu8SF+U83blgw5cByWTYkeg8PWkJQkEunEZMRu4IxQUS8VXGXzvdBDx2qktmzV k1Ppli25gqiWLPsJcAx3b1f4IR59J1I26klM2nLMU5BJFAksuzD9xCBl/HdRjQ+wYR5P c168drjFDUTnG7vVdEX701mv0lcJ/bVqovGpBCGmhybLvBvETWvpj0+OPn7MTPoHlF2X yX4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dHKUxFsX; 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 w32si5022273pga.337.2018.11.08.14.33.17; Thu, 08 Nov 2018 14:33:33 -0800 (PST) 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=dHKUxFsX; 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 S1730294AbeKIHha (ORCPT + 99 others); Fri, 9 Nov 2018 02:37:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:55750 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728100AbeKIHh2 (ORCPT ); Fri, 9 Nov 2018 02:37:28 -0500 Received: from localhost (unknown [208.72.13.198]) (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 F138220892; Thu, 8 Nov 2018 21:59:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714400; bh=wD6hG8fg5ofn4jNYV25c+VuTV3Dlxq1WJXD90xgfqbA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dHKUxFsXPGgjHMN2kg7wp0ckXaT+iresYYF5QQxOInMCz5CQMB7aXSfUnB/56fwH7 v/LElBffE0oTz2fB2Gd6daLkUihj1nefK11xe9NFVLT68KbqELe9oRUUA0Cr7pKJP/ xCoV56xknu7TBmNJuhKnQK/YEonLDfte+JNz7tFM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lance Richardson , Nicolas Dichtel , Steffen Klassert , Sasha Levin Subject: [PATCH 4.4 060/114] vti6: flush x-netns xfrm cache when vti interface is removed Date: Thu, 8 Nov 2018 13:51:15 -0800 Message-Id: <20181108215106.521100197@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215059.051093652@linuxfoundation.org> References: <20181108215059.051093652@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 7f92083eb58f85ea114d97f65fcbe22be5b0468d ] This is the same fix than commit a5d0dc810abf ("vti: flush x-netns xfrm cache when vti interface is removed") This patch fixes a refcnt problem when a x-netns vti6 interface is removed: unregister_netdevice: waiting for vti6_test to become free. Usage count = 1 Here is a script to reproduce the problem: ip link set dev ntfp2 up ip addr add dev ntfp2 2001::1/64 ip link add vti6_test type vti6 local 2001::1 remote 2001::2 key 1 ip netns add secure ip link set vti6_test netns secure ip netns exec secure ip link set vti6_test up ip netns exec secure ip link s lo up ip netns exec secure ip addr add dev vti6_test 2003::1/64 ip -6 xfrm policy add dir out tmpl src 2001::1 dst 2001::2 proto esp \ mode tunnel mark 1 ip -6 xfrm policy add dir in tmpl src 2001::2 dst 2001::1 proto esp \ mode tunnel mark 1 ip xfrm state add src 2001::1 dst 2001::2 proto esp spi 1 mode tunnel \ enc des3_ede 0x112233445566778811223344556677881122334455667788 mark 1 ip xfrm state add src 2001::2 dst 2001::1 proto esp spi 1 mode tunnel \ enc des3_ede 0x112233445566778811223344556677881122334455667788 mark 1 ip netns exec secure ping6 -c 4 2003::2 ip netns del secure CC: Lance Richardson Signed-off-by: Nicolas Dichtel Acked-by: Lance Richardson Signed-off-by: Steffen Klassert Signed-off-by: Sasha Levin --- net/ipv6/ip6_vti.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c index 60d4052d97a6..51da5987952c 100644 --- a/net/ipv6/ip6_vti.c +++ b/net/ipv6/ip6_vti.c @@ -1140,6 +1140,33 @@ static struct xfrm6_protocol vti_ipcomp6_protocol __read_mostly = { .priority = 100, }; +static bool is_vti6_tunnel(const struct net_device *dev) +{ + return dev->netdev_ops == &vti6_netdev_ops; +} + +static int vti6_device_event(struct notifier_block *unused, + unsigned long event, void *ptr) +{ + struct net_device *dev = netdev_notifier_info_to_dev(ptr); + struct ip6_tnl *t = netdev_priv(dev); + + if (!is_vti6_tunnel(dev)) + return NOTIFY_DONE; + + switch (event) { + case NETDEV_DOWN: + if (!net_eq(t->net, dev_net(dev))) + xfrm_garbage_collect(t->net); + break; + } + return NOTIFY_DONE; +} + +static struct notifier_block vti6_notifier_block __read_mostly = { + .notifier_call = vti6_device_event, +}; + /** * vti6_tunnel_init - register protocol and reserve needed resources * @@ -1150,6 +1177,8 @@ static int __init vti6_tunnel_init(void) const char *msg; int err; + register_netdevice_notifier(&vti6_notifier_block); + msg = "tunnel device"; err = register_pernet_device(&vti6_net_ops); if (err < 0) @@ -1182,6 +1211,7 @@ xfrm_proto_ah_failed: xfrm_proto_esp_failed: unregister_pernet_device(&vti6_net_ops); pernet_dev_failed: + unregister_netdevice_notifier(&vti6_notifier_block); pr_err("vti6 init: failed to register %s\n", msg); return err; } @@ -1196,6 +1226,7 @@ static void __exit vti6_tunnel_cleanup(void) xfrm6_protocol_deregister(&vti_ah6_protocol, IPPROTO_AH); xfrm6_protocol_deregister(&vti_esp6_protocol, IPPROTO_ESP); unregister_pernet_device(&vti6_net_ops); + unregister_netdevice_notifier(&vti6_notifier_block); } module_init(vti6_tunnel_init); -- 2.17.1