ibnetdisc: Fix leak in add_to_portlid_hash
This commit is contained in:
parent
fd96c16d08
commit
25b9222c5b
48
0082-ibnetdisc-Fix-leak-in-add_to_portlid_hash.patch
Normal file
48
0082-ibnetdisc-Fix-leak-in-add_to_portlid_hash.patch
Normal file
@ -0,0 +1,48 @@
|
||||
From 5814d7842b85451cc29186844c022785835c3565 Mon Sep 17 00:00:00 2001
|
||||
From: Anton Kuchin <antonkuchin@nebius.com>
|
||||
Date: Thu, 23 Nov 2023 16:55:41 +0100
|
||||
Subject: [PATCH] ibnetdisc: Fix leak in add_to_portlid_hash
|
||||
|
||||
When the duplicate port is added to the map cl_qmap_insert() returns pointer
|
||||
to existing value and the new entry is left unused that results in leak:
|
||||
|
||||
==1606814== 2,624 bytes in 41 blocks are definitely lost in loss record 1 of 1
|
||||
==1606814== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
|
||||
==1606814== by 0x5174B59: add_to_portlid_hash (ibnetdisc.c:704)
|
||||
==1606814== by 0x517638E: recv_port_info (ibnetdisc.c:379)
|
||||
==1606814== by 0x51789B0: process_one_recv (query_smp.c:200)
|
||||
==1606814== by 0x5178EF7: process_mads (query_smp.c:276)
|
||||
==1606814== by 0x51755E7: ibnd_discover_fabric (ibnetdisc.c:817)
|
||||
==1606814== by 0x109229: main (in /vagrant/go/gpu/ib-ict-manager/a.out)
|
||||
|
||||
The solution is to free new item if it was not added to the map.
|
||||
|
||||
Fixes: 16168163317b ("ibdiags: Use cl_qmap instead of glib hashtable")
|
||||
|
||||
Signed-off-by: Anton Kuchin <antonkuchin@nebius.com>
|
||||
|
||||
---
|
||||
libibnetdisc/ibnetdisc.c | 7 +++++--
|
||||
1 file changed, 5 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/libibnetdisc/ibnetdisc.c b/libibnetdisc/ibnetdisc.c
|
||||
index 970818c..6061b8c 100644
|
||||
--- a/libibnetdisc/ibnetdisc.c
|
||||
+++ b/libibnetdisc/ibnetdisc.c
|
||||
@@ -711,8 +711,11 @@ void add_to_portlid_hash(ibnd_port_t * port, f_internal_t *f_int)
|
||||
item = malloc(sizeof(*item));
|
||||
if (item) {
|
||||
item->port = port;
|
||||
- cl_qmap_insert(&f_int->lid2guid, lid,
|
||||
- &item->cl_map);
|
||||
+ if (cl_qmap_insert(&f_int->lid2guid, lid,
|
||||
+ &item->cl_map) != &item->cl_map) {
|
||||
+ /* Port is already in map, release item */
|
||||
+ free(item);
|
||||
+ }
|
||||
}
|
||||
}
|
||||
}
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
Name: rdma-core
|
||||
Version: 41.0
|
||||
Release: 25
|
||||
Release: 26
|
||||
Summary: RDMA core userspace libraries and daemons
|
||||
License: GPLv2 or BSD
|
||||
Url: https://github.com/linux-rdma/rdma-core
|
||||
@ -87,6 +87,7 @@ patch78: 0078-libhns-Add-pthread_spin_destroy-pthread_mutex_destro.patch
|
||||
patch79: 0079-libhns-Removes-a-repeated-initialization-of-a-spinlo.patch
|
||||
patch80: 0080-libhns-Fix-owner-bit-when-SQ-wraps-around-in-new-IO.patch
|
||||
patch81: 0081-libhns-Fix-missing-DB-when-compiler-does-not-support.patch
|
||||
patch82: 0082-ibnetdisc-Fix-leak-in-add_to_portlid_hash.patch
|
||||
|
||||
BuildRequires: binutils cmake >= 2.8.11 gcc libudev-devel pkgconfig pkgconfig(libnl-3.0)
|
||||
BuildRequires: pkgconfig(libnl-route-3.0) valgrind-devel systemd systemd-devel
|
||||
@ -334,6 +335,12 @@ fi
|
||||
%{_mandir}/*
|
||||
|
||||
%changelog
|
||||
* Thu Aug 8 2024 yanshuai <yanshuai01@kylinos.cn> - 41.0-26
|
||||
- Type: bugfix
|
||||
- ID: NA
|
||||
- SUG: NA
|
||||
- DESC: ibnetdisc: Fix leak in add_to_portlid_hash
|
||||
|
||||
* Tue Dec 12 2023 Ran Zhou <zhouran10@h-partners.com> - 41.0-25
|
||||
- Type: bugfix
|
||||
- ID: NA
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user