BPF List
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <ast@kernel.org>, <daniel@iogearbox.net>
Cc: <andrii@kernel.org>, <kernel-team@fb.com>
Subject: [PATCH bpf-next 1/4] libbpf: fix potential NULL dereference when parsing ELF
Date: Mon, 15 Aug 2022 17:19:26 -0700	[thread overview]
Message-ID: <20220816001929.369487-2-andrii@kernel.org> (raw)
In-Reply-To: <20220816001929.369487-1-andrii@kernel.org>

Fix if condition filtering empty ELF sections to prevent NULL
dereference.

Fixes: 47ea7417b074 ("libbpf: Skip empty sections in bpf_object__init_global_data_maps")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index aa05a99b913d..5f0281e61437 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1646,7 +1646,7 @@ static int bpf_object__init_global_data_maps(struct bpf_object *obj)
 		sec_desc = &obj->efile.secs[sec_idx];
 
 		/* Skip recognized sections with size 0. */
-		if (sec_desc->data && sec_desc->data->d_size == 0)
+		if (!sec_desc->data || sec_desc->data->d_size == 0)
 			continue;
 
 		switch (sec_desc->sec_type) {
-- 
2.30.2


  reply	other threads:[~2022-08-16  3:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-16  0:19 [PATCH bpf-next 0/4] Preparatory libbpf fixes and clean ups Andrii Nakryiko
2022-08-16  0:19 ` Andrii Nakryiko [this message]
2022-08-16 21:31   ` [PATCH bpf-next 1/4] libbpf: fix potential NULL dereference when parsing ELF Hao Luo
2022-08-16  0:19 ` [PATCH bpf-next 2/4] libbpf: streamline bpf_attr and perf_event_attr initialization Andrii Nakryiko
2022-08-16 21:33   ` Hao Luo
2022-08-16 21:54     ` Andrii Nakryiko
2022-08-16  0:19 ` [PATCH bpf-next 3/4] libbpf: clean up deprecated and legacy aliases Andrii Nakryiko
2022-08-16 21:33   ` Hao Luo
2022-08-16 21:55     ` Andrii Nakryiko
2022-08-16  0:19 ` [PATCH bpf-next 4/4] selftests/bpf: few fixes for selftests/bpf built in release mode Andrii Nakryiko
2022-08-16 21:34   ` Hao Luo
2022-08-16 21:58     ` Andrii Nakryiko
2022-08-17 21:00 ` [PATCH bpf-next 0/4] Preparatory libbpf fixes and clean ups patchwork-bot+netdevbpf

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=20220816001929.369487-2-andrii@kernel.org \
    --to=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    /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