Skip to content

Commit

Permalink
net: openvswitch: release vport resources on failure
Browse files Browse the repository at this point in the history
A recent commit introducing upcall packet accounting failed to properly
release the vport object when the per-cpu stats struct couldn't be
allocated.  This can cause dangling pointers to dp objects long after
they've been released.

Cc: wangchuanlei <[email protected]>
Fixes: 1933ea3 ("net: openvswitch: Add support to count upcall packets")
Reported-by: [email protected]
Signed-off-by: Aaron Conole <[email protected]>
Acked-by: Eelco Chaudron <[email protected]>
Reviewed-by: Michal Swiatkowski <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
apconole authored and kuba-moo committed Dec 22, 2022
1 parent f2575c8 commit 95637d9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions net/openvswitch/datapath.c
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
vport->upcall_stats = netdev_alloc_pcpu_stats(struct vport_upcall_stats_percpu);
if (!vport->upcall_stats) {
err = -ENOMEM;
goto err_destroy_portids;
goto err_destroy_vport;
}

err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
Expand All @@ -1876,6 +1876,8 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)
ovs_notify(&dp_datapath_genl_family, reply, info);
return 0;

err_destroy_vport:
ovs_dp_detach_port(vport);
err_destroy_portids:
kfree(rcu_dereference_raw(dp->upcall_portids));
err_unlock_and_destroy_meters:
Expand Down Expand Up @@ -2323,7 +2325,7 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
vport->upcall_stats = netdev_alloc_pcpu_stats(struct vport_upcall_stats_percpu);
if (!vport->upcall_stats) {
err = -ENOMEM;
goto exit_unlock_free;
goto exit_unlock_free_vport;
}

err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
Expand All @@ -2343,6 +2345,8 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct genl_info *info)
ovs_notify(&dp_vport_genl_family, reply, info);
return 0;

exit_unlock_free_vport:
ovs_dp_detach_port(vport);
exit_unlock_free:
ovs_unlock();
kfree_skb(reply);
Expand Down

0 comments on commit 95637d9

Please sign in to comment.