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

Commit 7b4577a

Browse files
Pravin B Shelardavem330
Pravin B Shelar
authored andcommitted
openvswitch: Fix net exit.
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]>
1 parent 34eea79 commit 7b4577a

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
@@ -2194,14 +2194,55 @@ static int __net_init ovs_init_net(struct net *net)
21942194
return 0;
21952195
}
21962196

2197-
static void __net_exit ovs_exit_net(struct net *net)
2197+
static void __net_exit list_vports_from_net(struct net *net, struct net *dnet,
2198+
struct list_head *head)
21982199
{
2199-
struct datapath *dp, *dp_next;
22002200
struct ovs_net *ovs_net = net_generic(net, ovs_net_id);
2201+
struct datapath *dp;
2202+
2203+
list_for_each_entry(dp, &ovs_net->dps, list_node) {
2204+
int i;
2205+
2206+
for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
2207+
struct vport *vport;
2208+
2209+
hlist_for_each_entry(vport, &dp->ports[i], dp_hash_node) {
2210+
struct netdev_vport *netdev_vport;
2211+
2212+
if (vport->ops->type != OVS_VPORT_TYPE_INTERNAL)
2213+
continue;
2214+
2215+
netdev_vport = netdev_vport_priv(vport);
2216+
if (dev_net(netdev_vport->dev) == dnet)
2217+
list_add(&vport->detach_list, head);
2218+
}
2219+
}
2220+
}
2221+
}
2222+
2223+
static void __net_exit ovs_exit_net(struct net *dnet)
2224+
{
2225+
struct datapath *dp, *dp_next;
2226+
struct ovs_net *ovs_net = net_generic(dnet, ovs_net_id);
2227+
struct vport *vport, *vport_next;
2228+
struct net *net;
2229+
LIST_HEAD(head);
22012230

22022231
ovs_lock();
22032232
list_for_each_entry_safe(dp, dp_next, &ovs_net->dps, list_node)
22042233
__dp_destroy(dp);
2234+
2235+
rtnl_lock();
2236+
for_each_net(net)
2237+
list_vports_from_net(net, dnet, &head);
2238+
rtnl_unlock();
2239+
2240+
/* Detach all vports from given namespace. */
2241+
list_for_each_entry_safe(vport, vport_next, &head, detach_list) {
2242+
list_del(&vport->detach_list);
2243+
ovs_dp_detach_port(vport);
2244+
}
2245+
22052246
ovs_unlock();
22062247

22072248
cancel_work_sync(&ovs_net->dp_notify_work);

Diff for: net/openvswitch/vport.h

+2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct vport_portids {
103103
* @ops: Class structure.
104104
* @percpu_stats: Points to per-CPU statistics used and maintained by vport
105105
* @err_stats: Points to error statistics used and maintained by vport
106+
* @detach_list: list used for detaching vport in net-exit call.
106107
*/
107108
struct vport {
108109
struct rcu_head rcu;
@@ -117,6 +118,7 @@ struct vport {
117118
struct pcpu_sw_netstats __percpu *percpu_stats;
118119

119120
struct vport_err_stats err_stats;
121+
struct list_head detach_list;
120122
};
121123

122124
/**

0 commit comments

Comments
 (0)