Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3427957pxf; Mon, 29 Mar 2021 01:49:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+AO6UvZx26Qx0S1xE+RrcR8Jqq7tqeuBPAfZKD0l/VvdnVriwEv28zln+nhSKS3XVi49d X-Received: by 2002:a17:906:8a61:: with SMTP id hy1mr14162714ejc.59.1617007751350; Mon, 29 Mar 2021 01:49:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617007751; cv=none; d=google.com; s=arc-20160816; b=WYSdPkowjm/NOtMIti4oJ5yQ+d0EvKrV9cpqguvq1/8OvsBenhyCd3Ma1dSZbhLZfE zNWCcL8//FAjOPyStHbX35KkG2werStS7HcXGwIOm3yl4Z0jt4y9dNJuBtYPrwWSYD1M PBBcc4+HlYXp33djZ2Vrmx1ZOrY/t5+wSgi93uCbps9s+MsQ8qrrdf9+qbDm10CdrLcd +31U8fJQ2waxPAllwNDvP2GpIRKVQdptO19ceDQLDtid5M5eZN42HrX1ApBdlQk++LkJ ZApTKWf1c/2QxbdzXscYt25xjoL5sbnNOb5GFyCDF77tM0+IXqL8RZLWOcIwvMHMysHd 3wDQ== 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=JBzX8nJJGAcK2RP8HGDCnf1eMdiD5hFdbWjSH8BcHCc=; b=qhcauV7BORiV6dnVZ9obRh5k1084RyFA1ItsT4kL/X1P10gbx18x+s2T6iy0FvtNEy caPm4HF1PwXQsUL91CFeWSBZVWDS+a3CAGgwvTvIWNDx1kexrGdmWmpo8AUolkMzPZUE Ki578ItGblTEasosCs3v19xYVGxm/55Hrf8s0NtiW0sPrYS2gUOklyAuJnkXgTyV5+3Y 7S3EyGhzDPTv+l0V01/wWctZ0k4DaoALjEa24YmanJ41bHr0bsZ62gb2cldhKG5yO9Ut UFJN4wThdNCTU3AVYAezUyQIPqxgi2+lB7XHP6y5F5nNWFV01lqVX86oVk2TtEK0E+Ml rF4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tTZo+dG7; 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 j2si12572825ejx.646.2021.03.29.01.48.49; Mon, 29 Mar 2021 01:49:11 -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=tTZo+dG7; 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 S235753AbhC2Irh (ORCPT + 99 others); Mon, 29 Mar 2021 04:47:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:40836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233865AbhC2I10 (ORCPT ); Mon, 29 Mar 2021 04:27:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0ACB761581; Mon, 29 Mar 2021 08:26:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617006361; bh=KvXms17jIybmqnJ11SALUWgKPvlHfwn+uX60/seO6EI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tTZo+dG7kO4GAc7J2kgnnz2YHnSjKzfkPwpASyEHUYMDTER48UNIhXv4xqyrrzJEt /HtLIlM+W1UlRkUWDgLdwK9cq9GKVwCwO+IvpmdlZU5eyBIKhgFsx/yP/ZVWBBrkBn iv23UXRC4jlTjtZXyvSbAukGG82J8rK8ErHSA1Jg= 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 5.10 212/221] can: dev: Move device back to init netns on owning netns delete Date: Mon, 29 Mar 2021 09:59:03 +0200 Message-Id: <20210329075636.193635638@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075629.172032742@linuxfoundation.org> References: <20210329075629.172032742@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 @@ -1255,6 +1255,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 @@ -33,6 +33,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 @@ -64,6 +65,7 @@ struct rtnl_link_ops { size_t priv_size; void (*setup)(struct net_device *dev); + bool netns_refund; unsigned int maxtype; const struct nla_policy *policy; int (*validate)(struct nlattr *tb[], --- a/net/core/dev.c +++ b/net/core/dev.c @@ -11106,7 +11106,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 */