From: Greg Kroah-Hartman Date: Mon, 29 Mar 2021 06:13:25 +0000 (+0200) Subject: 4.9-stable patches X-Git-Tag: v5.11.11~31 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b367dd5df1cf402ffb4f74c32b0ab8cdb56a005;p=thirdparty%2Fkernel%2Fstable-queue.git 4.9-stable patches added patches: can-dev-move-device-back-to-init-netns-on-owning-netns-delete.patch --- diff --git a/queue-4.9/can-dev-move-device-back-to-init-netns-on-owning-netns-delete.patch b/queue-4.9/can-dev-move-device-back-to-init-netns-on-owning-netns-delete.patch new file mode 100644 index 00000000000..a21d82912dd --- /dev/null +++ b/queue-4.9/can-dev-move-device-back-to-init-netns-on-owning-netns-delete.patch @@ -0,0 +1,96 @@ +From 3a5ca857079ea022e0b1b17fc154f7ad7dbc150f Mon Sep 17 00:00:00 2001 +From: Martin Willi +Date: Tue, 2 Mar 2021 13:24:23 +0100 +Subject: can: dev: Move device back to init netns on owning netns delete + +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 */ diff --git a/queue-4.9/series b/queue-4.9/series index 240edd61d6e..0101b9bedf0 100644 --- a/queue-4.9/series +++ b/queue-4.9/series @@ -47,3 +47,4 @@ arm64-futex-bound-number-of-ldxr-stxr-loops-in-futex_wake_op.patch futex-prevent-robust-futex-exit-race.patch futex-fix-incorrect-should_fail_futex-handling.patch futex-handle-transient-ownerless-rtmutex-state-correctly.patch +can-dev-move-device-back-to-init-netns-on-owning-netns-delete.patch