Skip to contentSkip to conversation

ll_map: Fix descriptor leak in ll_link_get()

PATCH In review Maks Mishin 3 participants 3 messages Feb 7, 2024 – Feb 8, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ll_map: Fix descriptor leak in ll_link_get()

Found by RASU JSC

---
 lib/ll_map.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/ll_map.c +3 -1
index 8970c20f..711708a5 100644
@@ -278,8 +278,10 @@ static int ll_link_get(const char *name, int index)
 	struct nlmsghdr *answer;
 	int rc = 0;
 
-	if (rtnl_open(&rth, 0) < 0)
+	if (rtnl_open(&rth, 0) < 0) {
+		rtnl_close(&rth);
 		return 0;
+	}
 
 	addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask);
 	if (name)
Signature · 1 line
2.30.2
#1 lore raw
Quoted 12 lines · Maks Mishin

Found by RASU JSC

---
 lib/ll_map.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/ll_map.c +0 -0
index 8970c20f..711708a5 100644

lib/ll_map.c static int ll_link_get(const char *name, int index) · line 282

Quoted 6 lines
lib/ll_map.c +2 -1
@@ -278,8 +278,10 @@ static int ll_link_get(const char *name, int index)
 	struct nlmsghdr *answer;
 	int rc = 0;
 
-	if (rtnl_open(&rth, 0) < 0)
+	if (rtnl_open(&rth, 0) < 0) {
+		rtnl_close(&rth);

There's no need to call rtnl_close() if the call to rtnl_open() just failed.

Quoted 5 lines
lib/ll_map.c +1 -0
 		return 0;
+	}
 
 	addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask);
 	if (name)
#2 lore raw
In reply to Maks Mishin
Quoted 13 lines · On Wed, 7 Feb 2024 23:32:39 +0300 Maks Mishin <[email protected]> wrote:

Found by RASU JSC

---
 lib/ll_map.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/ll_map.c +0 -0
index 8970c20f..711708a5 100644
@@ -278,8 +278,10 @@ static int ll_link_get(const char *name, int index)
 	struct nlmsghdr *answer;

lib/ll_map.c static int ll_link_get(const char *name, int index) · line 287

Quoted 10 lines
lib/ll_map.c +3 -1
 	int rc = 0;
 
-	if (rtnl_open(&rth, 0) < 0)
+	if (rtnl_open(&rth, 0) < 0) {
+		rtnl_close(&rth);
 		return 0;
+	}
 
 	addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask);
 	if (name)

Same as previous patch.

This doesn't make sense, the error path in rtnl_open cleans up itself. Do you have a reproducer or is this just some static analyzer?