Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3413268pxf; Mon, 29 Mar 2021 01:17:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsPHgRumXEk+ZysH9fYsaNjkCLJmHNjHBXAaHaXbxyBZj93DrXJSe2Ymq02aCMcrrKiXaD X-Received: by 2002:a17:906:add7:: with SMTP id lb23mr27100008ejb.273.1617005856834; Mon, 29 Mar 2021 01:17:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617005856; cv=none; d=google.com; s=arc-20160816; b=bbGTuIS91y6pw/Z9RZrpDfkB39wju6/wIjNKg6s8O2dU/99LjQIVy1SK5ki0mSmxf4 +uq0Gj1JWSA1FYcxOrS8nR7zwieTV1W6YtZ0zB97Dc6eqv2aNC46KsAFO8H1XgH+WDuS wWkeCpTmtOCOUd2OLBRUmIq6umj+7esJlAuMt1Coc5+tywkUT/Gjv+ELGoTyDA7ysvsK lllBMp+rYVZHTmZOAHPsJAzzLPMEUPC5DiejCoga1RZDTz1XNDPOTg3+hJyzE79y3RJ3 oQm0GH6IOi6lSS4UiTyJRdGN4Y86vgI09Y4mENsdeHBOB2Yo0z+0dppOhE4c0kkjta0V 3u1A== 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=UsVlWzsEupSaYrSNuQ5F4trXsDJeNsrX4QfnpjocdCY=; b=HP9yWDeudcmcL+ctWUY0bA4D+gDykQupGNsCHQrI5L8CI2xUdRCNjkntqrLzWWAxjw 7rJbmi/5OA1QI8Q54uIL5LrrpOEWtkN/V2Bo5rj2Kh4d4GrYU2jVFBQG5h1X5Je7nNQt 8/HyXxA2UL0KHU0GFx1/as1iH1DUREcKrCuv8iLGsgCRAaqr4TofvMsiQvddbtFjhHCv yDgUoZ7jPTC0CmuuEvLwMOMGIwQIlYh4/k6ztpRDoR4GYS5JYQOjq2T1LsiY1beikn+F 215mvvaxNeOeMFefHBMz0mfbFRjhmF/afyF4LZwTETMoVG/8KAfItUEqsNdvw7onAi2Z b/Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ifQLFVZk; 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 f8si12685162ejw.51.2021.03.29.01.17.14; Mon, 29 Mar 2021 01:17:36 -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=ifQLFVZk; 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 S232206AbhC2IQR (ORCPT + 99 others); Mon, 29 Mar 2021 04:16:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:53916 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232283AbhC2IKE (ORCPT ); Mon, 29 Mar 2021 04:10:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BD33A61494; Mon, 29 Mar 2021 08:10:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617005403; bh=MaAHh7af1WtedWFYydJEUtjtHLQ9CfEMuqj1NeMl2sM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ifQLFVZkwkW6TTESgL09tTOI8y9wjuyoae/SP6K+Wka17RNkm37p9POK+cVICupS+ Dqj8rpQsZcEFHjSORcOSPQxALek1AVBQj3/BHTLhSJB5mkU4h1ju/j5wfbhMkr4ljN sTlScg7zTI7PspHcDxQGSilNtHdN6warVKX0AciE= 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.19 67/72] can: dev: Move device back to init netns on owning netns delete Date: Mon, 29 Mar 2021 09:58:43 +0200 Message-Id: <20210329075612.481693343@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075610.300795746@linuxfoundation.org> References: <20210329075610.300795746@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 @@ -1235,6 +1235,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 @@ -9708,7 +9708,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 */