Skip to contentSkip to conversation

libbpf: fix memleak in libbpf_netlink_recv()

PATCH Applied Andrii Nakryiko 3 participants 3 messages Feb 17, 2022

Subsystems (2)
lore
Share & tools
lore

Andrii Nakryiko

author maintainer
#0 lore raw

PATCH 1/1 libbpf: fix memleak in libbpf_netlink_recv()

Ensure that libbpf_netlink_recv() frees dynamically allocated buffer in all code paths.

Cc Toke Høiland-Jørgensen <[email protected]>
Fixes 9c3de619e13e ("libbpf: Use dynamically allocated buffer when receiving netlink messages")
---
 tools/lib/bpf/netlink.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/lib/bpf/netlink.c +5 -3
index a598061f6fea..cbc8967d5402 100644
@@ -176,7 +176,8 @@ static int libbpf_netlink_recv(int sock, __u32 nl_pid, int seq,
 				libbpf_nla_dump_errormsg(nh);
 				goto done;
 			case NLMSG_DONE:
-				return 0;
+				ret = 0;
+				goto done;
 			default:
 				break;
 			}
@@ -188,9 +189,10 @@ static int libbpf_netlink_recv(int sock, __u32 nl_pid, int seq,
 				case NL_NEXT:
 					goto start;
 				case NL_DONE:
-					return 0;
+					ret = 0;
+					goto done;
 				default:
-					return ret;
+					goto done;
 				}
 			}
 		}
Signature · 1 line
2.30.2
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Andrii Nakryiko

Ensure that libbpf_netlink_recv() frees dynamically allocated buffer in all code paths.

Cc Toke Høiland-Jørgensen <[email protected]>
Fixes 9c3de619e13e ("libbpf: Use dynamically allocated buffer when receiving netlink messages")

Oops! I saw there were already 'goto done' labels in that block of code so assumed it was all fine and didn't look closer. Thank you for the fix!

-Toke

#2 lore raw
In reply to Andrii Nakryiko
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Quoted 8 lines · On Wed, 16 Feb 2022 23:39:58 -0800 you wrote:

Ensure that libbpf_netlink_recv() frees dynamically allocated buffer in all code paths.

Cc Toke Høiland-Jørgensen <[email protected]>
Fixes 9c3de619e13e ("libbpf: Use dynamically allocated buffer when receiving netlink messages")

[...]

Here is the summary with links:
- [bpf-next] libbpf: fix memleak in libbpf_netlink_recv()

    https://git.kernel.org/bpf/bpf-next/c/1b8c924a0593

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html