* [PATCH v3 bpf]: libbpf: fixing leak when kernel does not support btf
@ 2019-03-08 5:18 Nikita V. Shirokov
2019-03-08 5:32 ` Yonghong Song
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Nikita V. Shirokov @ 2019-03-08 5:18 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Yonghong Song
Cc: netdev, Nikita V . Shirokov
we could end up in situation when we have object file w/ all btf
info but kernel does not support btf yet. in this situation currently
libbpf just set obj->btf to NULL w/o freeing it first.
this patch if fixing it by making sure to run btf__free first
v2->v3:
- adding "Fixes" tag
v1->v2:
- adding netdev to cc
Fixes: 8a138aed4a80 ("bpf: btf: Add BTF support to libbpf")
Signed-off-by: Nikita V. Shirokov <tehnerd@tehnerd.com>
---
tools/lib/bpf/libbpf.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index f5eb60379c8d..d5b830d60601 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -838,6 +838,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)
if (IS_ERR(obj->btf) || btf__load(obj->btf)) {
pr_warning("Error loading ELF section %s: %ld. Ignored and continue.\n",
BTF_ELF_SEC, PTR_ERR(obj->btf));
+ if (!IS_ERR(obj->btf))
+ btf__free(obj->btf);
obj->btf = NULL;
}
} else if (strcmp(name, BTF_EXT_ELF_SEC) == 0) {
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3 bpf]: libbpf: fixing leak when kernel does not support btf
2019-03-08 5:18 [PATCH v3 bpf]: libbpf: fixing leak when kernel does not support btf Nikita V. Shirokov
@ 2019-03-08 5:32 ` Yonghong Song
2019-03-08 13:20 ` Daniel Borkmann
2019-03-08 16:45 ` Martin Lau
2 siblings, 0 replies; 5+ messages in thread
From: Yonghong Song @ 2019-03-08 5:32 UTC (permalink / raw)
To: Nikita V. Shirokov, Alexei Starovoitov, Daniel Borkmann; +Cc: netdev
On 3/7/19 9:18 PM, Nikita V. Shirokov wrote:
> we could end up in situation when we have object file w/ all btf
> info but kernel does not support btf yet. in this situation currently
> libbpf just set obj->btf to NULL w/o freeing it first.
> this patch if fixing it by making sure to run btf__free first
>
> v2->v3:
> - adding "Fixes" tag
>
> v1->v2:
> - adding netdev to cc
>
> Fixes: 8a138aed4a80 ("bpf: btf: Add BTF support to libbpf")
> Signed-off-by: Nikita V. Shirokov <tehnerd@tehnerd.com>
Acked-by: Yonghong Song <yhs@fb.com>
> ---
> tools/lib/bpf/libbpf.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index f5eb60379c8d..d5b830d60601 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -838,6 +838,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)
> if (IS_ERR(obj->btf) || btf__load(obj->btf)) {
> pr_warning("Error loading ELF section %s: %ld. Ignored and continue.\n",
> BTF_ELF_SEC, PTR_ERR(obj->btf));
> + if (!IS_ERR(obj->btf))
> + btf__free(obj->btf);
> obj->btf = NULL;
> }
> } else if (strcmp(name, BTF_EXT_ELF_SEC) == 0) {
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 bpf]: libbpf: fixing leak when kernel does not support btf
2019-03-08 5:18 [PATCH v3 bpf]: libbpf: fixing leak when kernel does not support btf Nikita V. Shirokov
2019-03-08 5:32 ` Yonghong Song
@ 2019-03-08 13:20 ` Daniel Borkmann
2019-03-08 16:45 ` Martin Lau
2 siblings, 0 replies; 5+ messages in thread
From: Daniel Borkmann @ 2019-03-08 13:20 UTC (permalink / raw)
To: Nikita V. Shirokov, Alexei Starovoitov, Yonghong Song; +Cc: netdev
On 03/08/2019 06:18 AM, Nikita V. Shirokov wrote:
> we could end up in situation when we have object file w/ all btf
> info but kernel does not support btf yet. in this situation currently
> libbpf just set obj->btf to NULL w/o freeing it first.
> this patch if fixing it by making sure to run btf__free first
>
> v2->v3:
> - adding "Fixes" tag
>
> v1->v2:
> - adding netdev to cc
>
> Fixes: 8a138aed4a80 ("bpf: btf: Add BTF support to libbpf")
> Signed-off-by: Nikita V. Shirokov <tehnerd@tehnerd.com>
Applied, thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 bpf]: libbpf: fixing leak when kernel does not support btf
2019-03-08 5:18 [PATCH v3 bpf]: libbpf: fixing leak when kernel does not support btf Nikita V. Shirokov
2019-03-08 5:32 ` Yonghong Song
2019-03-08 13:20 ` Daniel Borkmann
@ 2019-03-08 16:45 ` Martin Lau
2019-03-08 20:23 ` Daniel Borkmann
2 siblings, 1 reply; 5+ messages in thread
From: Martin Lau @ 2019-03-08 16:45 UTC (permalink / raw)
To: Nikita V. Shirokov
Cc: Alexei Starovoitov, Daniel Borkmann, Yonghong Song, netdev
On Fri, Mar 08, 2019 at 05:18:14AM +0000, Nikita V. Shirokov wrote:
> we could end up in situation when we have object file w/ all btf
> info but kernel does not support btf yet. in this situation currently
> libbpf just set obj->btf to NULL w/o freeing it first.
> this patch if fixing it by making sure to run btf__free first
>
> v2->v3:
> - adding "Fixes" tag
>
> v1->v2:
> - adding netdev to cc
>
> Fixes: 8a138aed4a80 ("bpf: btf: Add BTF support to libbpf")
I think the Fixes tag should belong to a later patch, just in
case there will be an issue when pulling into stable:
Fixes: d29d87f7e612 ("btf: separate btf creation and loading")
> Signed-off-by: Nikita V. Shirokov <tehnerd@tehnerd.com>
> ---
> tools/lib/bpf/libbpf.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index f5eb60379c8d..d5b830d60601 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -838,6 +838,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)
> if (IS_ERR(obj->btf) || btf__load(obj->btf)) {
> pr_warning("Error loading ELF section %s: %ld. Ignored and continue.\n",
> BTF_ELF_SEC, PTR_ERR(obj->btf));
Printing this PTR_ERR(obj->btf) seems not very correct also if btf__load()
was the one failing.
> + if (!IS_ERR(obj->btf))
> + btf__free(obj->btf);
> obj->btf = NULL;
> }
> } else if (strcmp(name, BTF_EXT_ELF_SEC) == 0) {
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3 bpf]: libbpf: fixing leak when kernel does not support btf
2019-03-08 16:45 ` Martin Lau
@ 2019-03-08 20:23 ` Daniel Borkmann
0 siblings, 0 replies; 5+ messages in thread
From: Daniel Borkmann @ 2019-03-08 20:23 UTC (permalink / raw)
To: Martin Lau, Nikita V. Shirokov; +Cc: Alexei Starovoitov, Yonghong Song, netdev
On 03/08/2019 05:45 PM, Martin Lau wrote:
> On Fri, Mar 08, 2019 at 05:18:14AM +0000, Nikita V. Shirokov wrote:
>> we could end up in situation when we have object file w/ all btf
>> info but kernel does not support btf yet. in this situation currently
>> libbpf just set obj->btf to NULL w/o freeing it first.
>> this patch if fixing it by making sure to run btf__free first
>>
>> v2->v3:
>> - adding "Fixes" tag
>>
>> v1->v2:
>> - adding netdev to cc
>>
>> Fixes: 8a138aed4a80 ("bpf: btf: Add BTF support to libbpf")
> I think the Fixes tag should belong to a later patch, just in
> case there will be an issue when pulling into stable:
>
> Fixes: d29d87f7e612 ("btf: separate btf creation and loading")
Agree, I just fixed up the tags, thanks!
>> Signed-off-by: Nikita V. Shirokov <tehnerd@tehnerd.com>
>> ---
>> tools/lib/bpf/libbpf.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>> index f5eb60379c8d..d5b830d60601 100644
>> --- a/tools/lib/bpf/libbpf.c
>> +++ b/tools/lib/bpf/libbpf.c
>> @@ -838,6 +838,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)
>> if (IS_ERR(obj->btf) || btf__load(obj->btf)) {
>> pr_warning("Error loading ELF section %s: %ld. Ignored and continue.\n",
>> BTF_ELF_SEC, PTR_ERR(obj->btf));
> Printing this PTR_ERR(obj->btf) seems not very correct also if btf__load()
> was the one failing.
Makes sense as well. Given this is logically independent from addressing
this leak, please send a follow-up fix for the pr_warning().
>> + if (!IS_ERR(obj->btf))
>> + btf__free(obj->btf);
>> obj->btf = NULL;
>> }
>> } else if (strcmp(name, BTF_EXT_ELF_SEC) == 0) {
>> --
>> 2.17.1
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-03-08 20:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-08 5:18 [PATCH v3 bpf]: libbpf: fixing leak when kernel does not support btf Nikita V. Shirokov
2019-03-08 5:32 ` Yonghong Song
2019-03-08 13:20 ` Daniel Borkmann
2019-03-08 16:45 ` Martin Lau
2019-03-08 20:23 ` Daniel Borkmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.