public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Quentin Monnet <quentin@isovalent.com>
To: Daniel Borkmann <daniel@iogearbox.net>,
	Alexei Starovoitov <ast@kernel.org>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
	Andrii Nakryiko <andriin@fb.com>,
	Michal Rostecki <mrostecki@opensuse.org>
Subject: Re: [PATCH bpf] libbpf: add null pointer check in bpf_object__init_user_btf_maps()
Date: Thu, 12 Mar 2020 16:50:59 +0000	[thread overview]
Message-ID: <cb65f021-35e6-a5b2-cacb-06be89aebccf@isovalent.com> (raw)
In-Reply-To: <1fff03e7-e52b-edcc-d427-f912bf0a4af2@iogearbox.net>

2020-03-12 16:37 UTC+0100 ~ Daniel Borkmann <daniel@iogearbox.net>
> On 3/12/20 3:03 PM, Quentin Monnet wrote:
>> When compiling bpftool with clang 7, after the addition of its recent
>> "bpftool prog profile" feature, Michal reported a segfault. This
>> occurred while the build process was attempting to generate the
>> skeleton needed for the profiling program, with the following command:
>>
>>      ./_bpftool gen skeleton skeleton/profiler.bpf.o > profiler.skel.h
>>
>> Tracing the error showed that bpf_object__init_user_btf_maps() does no
>> verification on obj->btf before passing it to btf__get_nr_types(), where
>> btf is dereferenced. Libbpf considers BTF information should be here
>> because of the presence of a ".maps" section in the object file (hence
>> the check on "obj->efile.btf_maps_shndx < 0" fails and we do not exit
>> from the function early), but it was unable to load BTF info as there is
>> no .BTF section.
>>
>> Add a null pointer check and error out if the pointer is null. The final
>> bpftool executable still fails to build, but at least we have a proper
>> error and no more segfault.
>>
>> Fixes: abd29c931459 ("libbpf: allow specifying map definitions using
>> BTF")
>> Cc: Andrii Nakryiko <andriin@fb.com>
>> Reported-by: Michal Rostecki <mrostecki@opensuse.org>
>> Signed-off-by: Quentin Monnet <quentin@isovalent.com>
> 
> Applied to bpf-next, thanks! Note ...
> 
>> ---
>>   tools/lib/bpf/libbpf.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>> index 223be01dc466..19c0c40e8a80 100644
>> --- a/tools/lib/bpf/libbpf.c
>> +++ b/tools/lib/bpf/libbpf.c
>> @@ -2140,6 +2140,10 @@ static int
>> bpf_object__init_user_btf_maps(struct bpf_object *obj, bool strict,
>>           return -EINVAL;
>>       }
>>   +    if (!obj->btf) {
>> +        pr_warn("failed to retrieve BTF for map");
> 
> I've added a '\n' here

Sorry about that, thank you Daniel!
Quentin

  reply	other threads:[~2020-03-12 16:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-12 14:03 [PATCH bpf] libbpf: add null pointer check in bpf_object__init_user_btf_maps() Quentin Monnet
2020-03-12 14:22 ` Michal Rostecki
2020-03-12 15:37 ` Daniel Borkmann
2020-03-12 16:50   ` Quentin Monnet [this message]
2020-03-12 17:54   ` Andrii Nakryiko
2020-03-12 18:21     ` Daniel Borkmann
2020-03-12 18:34       ` Quentin Monnet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cb65f021-35e6-a5b2-cacb-06be89aebccf@isovalent.com \
    --to=quentin@isovalent.com \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=mrostecki@opensuse.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox