发件人: Mike Pattrick <[email protected]> 发送时间: 2025年10月2日 22:38 收件人: Wangyunjian <[email protected]> 抄送: [email protected]; Lilijun (Jerry) <[email protected]>; [email protected] 主题: Re: [ovs-dev] [PATCH] dpif-netlink: Fix memory leak when add vport channel.
On Fri, Sep 19, 2025 at 4:09 AM Yunjian Wang via dev <[email protected]<mailto:[email protected]>> wrote: When vport_add_channel() is called duplicate, the resources for previously specified sock was not freed. This patch fixes this issue. Hello Yunjian, Do you have a way to reproduce this issue? Following 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 ifconfig br-ovs down ovs-vsctl del-br br-ovs 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 Fixes: 69c51582ff78 ("dpif-netlink: don't allocate per thread netlink sockets") Signed-off-by: Yunjian Wang <[email protected]<mailto:[email protected]>> --- lib/dpif-netlink.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 7587c9c3e..d87a20af2 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -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 *dpif, odp_port_t port_no); static int create_nl_sock(struct dpif_netlink *dpif OVS_UNUSED, struct nl_sock **sockp) @@ -604,6 +605,11 @@ vport_add_channel(struct dpif_netlink *dpif, odp_port_t port_no, } #endif } + + if (dpif->channels[port_idx].sock != NULL) { Nit: I don't think this check is needed, vport_del_channels will already check for this. Agreed, I will remove it in the next version. Thanks, Yunjian Cheers, M + vport_del_channels(dpif, port_no); + } + dpif->channels[port_idx].sock = sock; dpif->channels[port_idx].last_poll = LLONG_MIN; -- 2.33.0 _______________________________________________ dev mailing list [email protected]<mailto:[email protected]> https://mail.openvswitch.org/mailman/listinfo/ovs-dev _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
