Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3408507pxf; Mon, 29 Mar 2021 01:08:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYt/dYzIWgnUFVFwhLz2JmkrncvJQbAfo1zQUUDR+RemWNxTqjpZuFeudbqQ/v5cg0BJrK X-Received: by 2002:a17:906:144d:: with SMTP id q13mr28821601ejc.458.1617005293907; Mon, 29 Mar 2021 01:08:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617005293; cv=none; d=google.com; s=arc-20160816; b=QcoBpmqwNOpOhrDoZoQ1tGmzK5ooj+3SJap8XZqhe4FYsBtuZ+VhUnrBjuzYutsS8c 41tipkUVz9OKRbrF0f+m9maq3r4Ie8ezRSiozNcP0mHlqcAtx/4sU4SBcOOqTC2Ou3GJ BNejZ1yJUrO0tYN6fkX0KxwnYGI2np93iVemQ/bbD5a/a/7xCKnwUwEiVhljhP/HGadN e+7NUBmszEgtGBBV6sJnICmf64BSR8XdZ6TGGugfgn5DISVITFoTSZLRgO+V4Y/6xMjl DurtHYQuC1KfH42vf1J+oupRNWJ5SXnA6OBBI1TIKKF1A9l3MntpIWWIxkc63V1S6ReC 55aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=f2PztRO95mlxyyHEZkYOEmOZF6iR3YWQoR0Nbbhfi2s=; b=kSEv5o+0plPjY+mG/2NSp1HvVmS82efHoXLebNRzhCRk4BSTi/ydfWiVhJZcxB22cq ocF1pa6r0Xv6v4KN1ja96gq1diXmf4n3/sqs8vUgsfURXX5VzaVcCDKq6/ub+aV6+Ls7 dc3YE14d7IdZuoLA6URv1UFAVvsmr4WY4stUf96a0FFA45I+ljvulaj1Kx84upuuER8n qyEJQcMZYS6hMvQybSlFF1Y2XkjTono6iS1VYG6HLhWZC2uMW2LOe1UgFZqX7+H5Aq06 nK30bGtPeidtWKXNb3pBH7swCIEpg3hP0TIPbsrVL8srQUmtW9Fra0Jz20jdF3h7ouM5 KzHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dZEXgWD7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t22si11636788ejj.746.2021.03.29.01.07.51; Mon, 29 Mar 2021 01:08:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dZEXgWD7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231978AbhC2IGJ (ORCPT + 99 others); Mon, 29 Mar 2021 04:06:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:46566 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231601AbhC2IDl (ORCPT ); Mon, 29 Mar 2021 04:03:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8B99661974; Mon, 29 Mar 2021 08:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617005021; bh=rDzvt0X6sttH1YCUBD00Fw/jKkHsLU6e0wiS7skrXM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dZEXgWD7NYuV2ZMJLnvF/Ww4+osVrzulCVcE7zM89UcAMduhdA48sRl/OfoKXHLC5 Slwg+XGdAC5O44NVjbEBrip11DZHWcA/MlDLeGoX39tcwNiSEGJQ1AbbtChd5vENe0 P2vdCPbhpQnOUeKndpSF7w1lXpyo3N4qu8MYJ+Vs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Martin Willi , Marc Kleine-Budde Subject: [PATCH 4.9 50/53] can: dev: Move device back to init netns on owning netns delete Date: Mon, 29 Mar 2021 09:58:25 +0200 Message-Id: <20210329075609.161133746@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075607.561619583@linuxfoundation.org> References: <20210329075607.561619583@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Martin Willi commit 3a5ca857079ea022e0b1b17fc154f7ad7dbc150f upstream. When a non-initial netns is destroyed, the usual policy is to delete all virtual network interfaces contained, but move physical interfaces back to the initial netns. This keeps the physical interface visible on the system. CAN devices are somewhat special, as they define rtnl_link_ops even if they are physical devices. If a CAN interface is moved into a non-initial netns, destroying that netns lets the interface vanish instead of moving it back to the initial netns. default_device_exit() skips CAN interfaces due to having rtnl_link_ops set. Reproducer: ip netns add foo ip link set can0 netns foo ip netns delete foo WARNING: CPU: 1 PID: 84 at net/core/dev.c:11030 ops_exit_list+0x38/0x60 CPU: 1 PID: 84 Comm: kworker/u4:2 Not tainted 5.10.19 #1 Workqueue: netns cleanup_net [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [] (show_stack) from [] (dump_stack+0x94/0xa8) [] (dump_stack) from [] (__warn+0xb8/0x114) [] (__warn) from [] (warn_slowpath_fmt+0x7c/0xac) [] (warn_slowpath_fmt) from [] (ops_exit_list+0x38/0x60) [] (ops_exit_list) from [] (cleanup_net+0x230/0x380) [] (cleanup_net) from [] (process_one_work+0x1d8/0x438) [] (process_one_work) from [] (worker_thread+0x64/0x5a8) [] (worker_thread) from [] (kthread+0x148/0x14c) [] (kthread) from [] (ret_from_fork+0x14/0x2c) To properly restore physical CAN devices to the initial netns on owning netns exit, introduce a flag on rtnl_link_ops that can be set by drivers. For CAN devices setting this flag, default_device_exit() considers them non-virtual, applying the usual namespace move. The issue was introduced in the commit mentioned below, as at that time CAN devices did not have a dellink() operation. Fixes: e008b5fc8dc7 ("net: Simplfy default_device_exit and improve batching.") Link: https://lore.kernel.org/r/20210302122423.872326-1-martin@strongswan.org Signed-off-by: Martin Willi Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- drivers/net/can/dev.c | 1 + include/net/rtnetlink.h | 2 ++ net/core/dev.c | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) --- a/drivers/net/can/dev.c +++ b/drivers/net/can/dev.c @@ -1084,6 +1084,7 @@ static void can_dellink(struct net_devic static struct rtnl_link_ops can_link_ops __read_mostly = { .kind = "can", + .netns_refund = true, .maxtype = IFLA_CAN_MAX, .policy = can_policy, .setup = can_setup, --- a/include/net/rtnetlink.h +++ b/include/net/rtnetlink.h @@ -28,6 +28,7 @@ static inline int rtnl_msg_family(const * * @list: Used internally * @kind: Identifier + * @netns_refund: Physical device, move to init_net on netns exit * @maxtype: Highest device specific netlink attribute number * @policy: Netlink policy for device specific attribute validation * @validate: Optional validation function for netlink/changelink parameters @@ -84,6 +85,7 @@ struct rtnl_link_ops { unsigned int (*get_num_tx_queues)(void); unsigned int (*get_num_rx_queues)(void); + bool netns_refund; int slave_maxtype; const struct nla_policy *slave_policy; int (*slave_validate)(struct nlattr *tb[], --- a/net/core/dev.c +++ b/net/core/dev.c @@ -8300,7 +8300,7 @@ static void __net_exit default_device_ex continue; /* Leave virtual devices for the generic cleanup */ - if (dev->rtnl_link_ops) + if (dev->rtnl_link_ops && !dev->rtnl_link_ops->netns_refund) continue; /* Push remaining network devices to init_net */