]> git.feebdaed.xyz Git - 0xmirror/ovs.git/commitdiff
dpif-netlink: Fix memory leak when re-add vport channel.
authorYunjian Wang <wangyunjian@huawei.com>
Thu, 23 Oct 2025 01:35:24 +0000 (09:35 +0800)
committerIlya Maximets <i.maximets@ovn.org>
Fri, 24 Oct 2025 13:02:42 +0000 (15:02 +0200)
When vport_add_channel() is called duplicate, the resources for
previously specified sock was not freed. This issue only occurs
when per-cpu dispatch is disabled. This patch fixes this issue.

Reported by Address Sanitizer.

Direct leak of 60 byte(s) in 3 object(s) allocated from:
    0 0xffffb3658080 in malloc (/usr/lib64/libasan.so.6+0xa9080)
    1 0x922630 in xmalloc__ lib/util.c:141
    2 0x922718 in xmalloc lib/util.c:176
    3 0x9c67e4 in nl_sock_create lib/netlink-socket.c:147
    4 0x94cb6c in create_nl_sock lib/dpif-netlink.c:283
    5 0x950bec in dpif_netlink_port_add__ lib/dpif-netlink.c:978
    6 0x951a20 in dpif_netlink_port_add_compat lib/dpif-netlink.c:1101
    7 0x951cd0 in dpif_netlink_port_add lib/dpif-netlink.c:1147
    8 0x616354 in dpif_port_add lib/dpif.c:602
    9 0x49f424 in port_add ofproto/ofproto-dpif.c:4144
    10 0x44d51c in ofproto_port_add ofproto/ofproto.c:2204
    11 0x416914 in iface_do_create vswitchd/bridge.c:2203
    12 0x416dbc in iface_create vswitchd/bridge.c:2246
    13 0x40e1d0 in bridge_add_ports__ vswitchd/bridge.c:1225
    14 0x40e290 in bridge_add_ports vswitchd/bridge.c:1241
    15 0x40cc6c in bridge_reconfigure vswitchd/bridge.c:952
    16 0x420884 in bridge_run vswitchd/bridge.c:3440
    17 0x42f3d0 in main vswitchd/ovs-vswitchd.c:137

Reproduce steps:
    ovs-vsctl add-br br-ovs
    ovs-vsctl add-port br-ovs test -- set interface test type=internal
    ip netns add ns_test
    ip link set test netns ns_test
    ip netns del ns_test
    ifconfig br-ovs up
    sleep 1
    ifconfig br-ovs down
    sleep 1
    ovs-vsctl del-br br-ovs

Fixes: 1579cf677fcb ("dpif-linux: Implement the API functions to allow multiple handler threads read upcall.")
Acked-by: Mike Pattrick <mkp@redhat.com>
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
lib/dpif-netlink.c

index 7587c9c3e8e3013fd5fd37cc28c21eba46ebd984..2b33d0fa604f78b2bebb45a8e96d4c55ccffc56a 100644 (file)
@@ -274,6 +274,7 @@ static int dpif_netlink_vport_from_ofpbuf(struct dpif_netlink_vport *,
 static int dpif_netlink_port_query__(const struct dpif_netlink *dpif,
                                      odp_port_t port_no, const char *port_name,
                                      struct dpif_port *dpif_port);
+static void vport_del_channels(struct dpif_netlink *, odp_port_t);
 
 static int
 create_nl_sock(struct dpif_netlink *dpif OVS_UNUSED, struct nl_sock **sockp)
@@ -589,6 +590,8 @@ vport_add_channel(struct dpif_netlink *dpif, odp_port_t port_no,
         dpif->uc_array_size = new_size;
     }
 
+    vport_del_channels(dpif, port_no);
+
     memset(&event, 0, sizeof event);
     event.events = EPOLLIN | EPOLLEXCLUSIVE;
     event.data.u32 = port_idx;