Re: [PATCH 5.4 326/367] libbpf: Free btf_vmlinux when closing bpf_object

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Hi Greg,

On 23/09/23 1:55 pm, Greg Kroah-Hartman wrote:
On Wed, Sep 20, 2023 at 06:58:45PM +0530, Harshit Mogalapalli wrote:
Hi Greg,

On 20/09/23 5:01 pm, Greg Kroah-Hartman wrote:
5.4-stable review patch.  If anyone has any objections, please let me know.


From: Hao Luo <haoluo@xxxxxxxxxx>

[ Upstream commit 29d67fdebc42af6466d1909c60fdd1ef4f3e5240 ]

I hit a memory leak when testing bpf_program__set_attach_target().
Basically, set_attach_target() may allocate btf_vmlinux, for example,
when setting attach target for bpf_iter programs. But btf_vmlinux
is freed only in bpf_object_load(), which means if we only open
bpf object but not load it, setting attach target may leak

So let's free btf_vmlinux in bpf_object__close() anyway.

Signed-off-by: Hao Luo <haoluo@xxxxxxxxxx>
Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
   tools/lib/bpf/libbpf.c | 1 +
   1 file changed, 1 insertion(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index b8849812449c3..343018632d2d1 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -4202,6 +4202,7 @@ void bpf_object__close(struct bpf_object *obj)
+	btf__free(obj->btf_vmlinux);

This patch introduces a build failure.

libbpf.c: In function 'bpf_object__close':
libbpf.c:4205:22: error: 'struct bpf_object' has no member named
  4205 |         btf__free(obj->btf_vmlinux);
       |                      ^~

This struct member "btf_vmlinux" is added in commit a6ed02cac690 ("libbpf:
Load btf_vmlinux only once per object.") which is not in 5.4.y

So I think we should drop this patch.

Now dropped, thanks.

I have tested kernel(5.4.257 final release) where the offending patches are dropped. No regressions seen there.


greg k-h

[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux