Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 91f3fc9

Browse files
Pravin B Shelarsashalevin
Pravin B Shelar
authored andcommitted
openvswitch: Fix net exit.
[ Upstream commit 7b4577a ] Open vSwitch allows moving internal vport to different namespace while still connected to the bridge. But when namespace deleted OVS does not detach these vports, that results in dangling pointer to netdevice which causes kernel panic as follows. This issue is fixed by detaching all ovs ports from the deleted namespace at net-exit. BUG: unable to handle kernel NULL pointer dereference at 0000000000000028 IP: [<ffffffffa0aadaa5>] ovs_vport_locate+0x35/0x80 [openvswitch] Oops: 0000 [#1] SMP Call Trace: [<ffffffffa0aa6391>] lookup_vport+0x21/0xd0 [openvswitch] [<ffffffffa0aa65f9>] ovs_vport_cmd_get+0x59/0xf0 [openvswitch] [<ffffffff8167e07c>] genl_family_rcv_msg+0x1bc/0x3e0 [<ffffffff8167e319>] genl_rcv_msg+0x79/0xc0 [<ffffffff8167d919>] netlink_rcv_skb+0xb9/0xe0 [<ffffffff8167deac>] genl_rcv+0x2c/0x40 [<ffffffff8167cffd>] netlink_unicast+0x12d/0x1c0 [<ffffffff8167d3da>] netlink_sendmsg+0x34a/0x6b0 [<ffffffff8162e140>] sock_sendmsg+0xa0/0xe0 [<ffffffff8162e5e8>] ___sys_sendmsg+0x408/0x420 [<ffffffff8162f541>] __sys_sendmsg+0x51/0x90 [<ffffffff8162f592>] SyS_sendmsg+0x12/0x20 [<ffffffff81764ee9>] system_call_fastpath+0x12/0x17 Reported-by: Assaf Muller <[email protected]> Fixes: 46df7b8("openvswitch: Add support for network namespaces.") Signed-off-by: Pravin B Shelar <[email protected]> Reviewed-by: Thomas Graf <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent cbac74b commit 91f3fc9

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

Diff for: net/openvswitch/datapath.c

+43-2
Original file line numberDiff line numberDiff line change
@@ -2060,14 +2060,55 @@ static int __net_init ovs_init_net(struct net *net)
20602060
return 0;
20612061
}
20622062

2063-
static void __net_exit ovs_exit_net(struct net *net)
2063+
static void __net_exit list_vports_from_net(struct net *net, struct net *dnet,
2064+
struct list_head *head)
20642065
{
2065-
struct datapath *dp, *dp_next;
20662066
struct ovs_net *ovs_net = net_generic(net, ovs_net_id);
2067+
struct datapath *dp;
2068+
2069+
list_for_each_entry(dp, &ovs_net->dps, list_node) {
2070+
int i;
2071+
2072+
for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
2073+
struct vport *vport;
2074+
2075+
hlist_for_each_entry(vport, &dp->ports[i], dp_hash_node) {
2076+
struct netdev_vport *netdev_vport;
2077+
2078+
if (vport->ops->type != OVS_VPORT_TYPE_INTERNAL)
2079+
continue;
2080+
2081+
netdev_vport = netdev_vport_priv(vport);
2082+
if (dev_net(netdev_vport->dev) == dnet)
2083+
list_add(&vport->detach_list, head);
2084+
}
2085+
}
2086+
}
2087+
}
2088+
2089+
static void __net_exit ovs_exit_net(struct net *dnet)
2090+
{
2091+
struct datapath *dp, *dp_next;
2092+
struct ovs_net *ovs_net = net_generic(dnet, ovs_net_id);
2093+
struct vport *vport, *vport_next;
2094+
struct net *net;
2095+
LIST_HEAD(head);
20672096

20682097
ovs_lock();
20692098
list_for_each_entry_safe(dp, dp_next, &ovs_net->dps, list_node)
20702099
__dp_destroy(dp);
2100+
2101+
rtnl_lock();
2102+
for_each_net(net)
2103+
list_vports_from_net(net, dnet, &head);
2104+
rtnl_unlock();
2105+
2106+
/* Detach all vports from given namespace. */
2107+
list_for_each_entry_safe(vport, vport_next, &head, detach_list) {
2108+
list_del(&vport->detach_list);
2109+
ovs_dp_detach_port(vport);
2110+
}
2111+
20712112
ovs_unlock();
20722113

20732114
cancel_work_sync(&ovs_net->dp_notify_work);

Diff for: net/openvswitch/vport.h

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct vport_portids {
9393
* @ops: Class structure.
9494
* @percpu_stats: Points to per-CPU statistics used and maintained by vport
9595
* @err_stats: Points to error statistics used and maintained by vport
96+
* @detach_list: list used for detaching vport in net-exit call.
9697
*/
9798
struct vport {
9899
struct rcu_head rcu;
@@ -107,6 +108,7 @@ struct vport {
107108
struct pcpu_sw_netstats __percpu *percpu_stats;
108109

109110
struct vport_err_stats err_stats;
111+
struct list_head detach_list;
110112
};
111113

112114
/**

0 commit comments

Comments
 (0)