mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	net: openvswitch: release vport resources on failure
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 <wangchuanlei@inspur.com>
Fixes: 1933ea365a ("net: openvswitch: Add support to count upcall packets")
Reported-by: syzbot+8f4e2dcfcb3209ac35f9@syzkaller.appspotmail.com
Signed-off-by: Aaron Conole <aconole@redhat.com>
Acked-by: Eelco Chaudron <echaudro@redhat.com>
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Link: https://lore.kernel.org/r/20221220212717.526780-1-aconole@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
			
			
This commit is contained in:
		
							parent
							
								
									f2575c8f40
								
							
						
					
					
						commit
						95637d91fe
					
				
					 1 changed files with 6 additions and 2 deletions
				
			
		| 
						 | 
					@ -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);
 | 
						vport->upcall_stats = netdev_alloc_pcpu_stats(struct vport_upcall_stats_percpu);
 | 
				
			||||||
	if (!vport->upcall_stats) {
 | 
						if (!vport->upcall_stats) {
 | 
				
			||||||
		err = -ENOMEM;
 | 
							err = -ENOMEM;
 | 
				
			||||||
		goto err_destroy_portids;
 | 
							goto err_destroy_vport;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
 | 
						err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
 | 
				
			||||||
| 
						 | 
					@ -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);
 | 
						ovs_notify(&dp_datapath_genl_family, reply, info);
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					err_destroy_vport:
 | 
				
			||||||
 | 
						ovs_dp_detach_port(vport);
 | 
				
			||||||
err_destroy_portids:
 | 
					err_destroy_portids:
 | 
				
			||||||
	kfree(rcu_dereference_raw(dp->upcall_portids));
 | 
						kfree(rcu_dereference_raw(dp->upcall_portids));
 | 
				
			||||||
err_unlock_and_destroy_meters:
 | 
					err_unlock_and_destroy_meters:
 | 
				
			||||||
| 
						 | 
					@ -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);
 | 
						vport->upcall_stats = netdev_alloc_pcpu_stats(struct vport_upcall_stats_percpu);
 | 
				
			||||||
	if (!vport->upcall_stats) {
 | 
						if (!vport->upcall_stats) {
 | 
				
			||||||
		err = -ENOMEM;
 | 
							err = -ENOMEM;
 | 
				
			||||||
		goto exit_unlock_free;
 | 
							goto exit_unlock_free_vport;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
 | 
						err = ovs_vport_cmd_fill_info(vport, reply, genl_info_net(info),
 | 
				
			||||||
| 
						 | 
					@ -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);
 | 
						ovs_notify(&dp_vport_genl_family, reply, info);
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					exit_unlock_free_vport:
 | 
				
			||||||
 | 
						ovs_dp_detach_port(vport);
 | 
				
			||||||
exit_unlock_free:
 | 
					exit_unlock_free:
 | 
				
			||||||
	ovs_unlock();
 | 
						ovs_unlock();
 | 
				
			||||||
	kfree_skb(reply);
 | 
						kfree_skb(reply);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue