From patchwork Thu Oct 9 10:32:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunjian Wang X-Patchwork-Id: 2147567 X-Patchwork-Delegate: i.maximets@samsung.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=PLsWNMHd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4cj5m46vH5z1yGq for ; Thu, 9 Oct 2025 21:32:20 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 26E8D40D1A; Thu, 9 Oct 2025 10:32:19 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id yJJGMSzxEOPQ; Thu, 9 Oct 2025 10:32:18 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 3A07D40471 Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key, unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=PLsWNMHd Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 3A07D40471; Thu, 9 Oct 2025 10:32:18 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2023FC060E; Thu, 9 Oct 2025 10:32:18 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 75C9EC060D for ; Thu, 9 Oct 2025 10:32:16 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 61583611F8 for ; Thu, 9 Oct 2025 10:32:16 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id JZJjo6blrwC5 for ; Thu, 9 Oct 2025 10:32:15 +0000 (UTC) X-Greylist: delayed 24731 seconds by postgrey-1.37 at util1.osuosl.org; Thu, 09 Oct 2025 10:32:13 UTC DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 5B8D4611F4 Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 5B8D4611F4 Authentication-Results: smtp3.osuosl.org; dkim=pass (1024-bit key, unprotected) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=PLsWNMHd Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=113.46.200.222; helo=canpmsgout07.his.huawei.com; envelope-from=wangyunjian@huawei.com; receiver= Received: from canpmsgout07.his.huawei.com (canpmsgout07.his.huawei.com [113.46.200.222]) by smtp3.osuosl.org (Postfix) with ESMTPS id 5B8D4611F4 for ; Thu, 9 Oct 2025 10:32:13 +0000 (UTC) dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=1jsiKbTmhtlq2AJu9Qrgywnu7PuzBeUdaUpZhhRQFhI=; b=PLsWNMHd38v9bmTSojoCv19/jApb32Ingk3W8Q9hWW5l7Qbuz9wiBi5/UuSYkNpafbmFBeRcU EvTnAVj4DfF/0DLPOCvOeUES8O8VwzmbsHCgfQl08rR0agUqF0LENGCvVhWgZMA5qd4x8NUDa2P U8ZdP2HN7y6J0eFIKduknMU= Received: from mail.maildlp.com (unknown [172.19.88.214]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4cj5lW0y1qzLlYL; Thu, 9 Oct 2025 18:31:51 +0800 (CST) Received: from dggemv706-chm.china.huawei.com (unknown [10.3.19.33]) by mail.maildlp.com (Postfix) with ESMTPS id C7CA91A016C; Thu, 9 Oct 2025 18:32:07 +0800 (CST) Received: from kwepemq100013.china.huawei.com (7.202.195.192) by dggemv706-chm.china.huawei.com (10.3.19.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 9 Oct 2025 18:32:07 +0800 Received: from localhost (10.174.243.191) by kwepemq100013.china.huawei.com (7.202.195.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 9 Oct 2025 18:32:07 +0800 To: Date: Thu, 9 Oct 2025 18:32:05 +0800 Message-ID: <1760005925-3756-1-git-send-email-wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 MIME-Version: 1.0 X-Originating-IP: [10.174.243.191] X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemq100013.china.huawei.com (7.202.195.192) Subject: [ovs-dev] [PATCH v2] dpif-netlink: Fix memory leak when add vport channel. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Yunjian Wang via dev From: Yunjian Wang Reply-To: Yunjian Wang Cc: jerry.lilijun@huawei.com, i.maximets@ovn.org, mcroce@redhat.com Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" When vport_add_channel() is called duplicate, the resources for previously specified sock was not freed. 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: 69c51582ff78 ("dpif-netlink: don't allocate per thread netlink sockets") Signed-off-by: Yunjian Wang Acked-by: Mike Pattrick --- v2: remove unnecessary check suggested by Mike Pattrick --- lib/dpif-netlink.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 7587c9c3e..e49ca298f 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,9 @@ vport_add_channel(struct dpif_netlink *dpif, odp_port_t port_no, } #endif } + + vport_del_channels(dpif, port_no); + dpif->channels[port_idx].sock = sock; dpif->channels[port_idx].last_poll = LLONG_MIN;