From: David Faust <david.faust@oracle.com>
To: bpf@vger.kernel.org
Cc: david.faust@oracle.com
Subject: [PATCH bpf-next] libbpf: avoid mmap for size 0 sections
Date: Wed, 27 Jul 2022 13:48:08 -0700 [thread overview]
Message-ID: <20220727204808.13210-1-david.faust@oracle.com> (raw)
When populating maps in bpf_object__init_global_data_maps(), recognized
sections with no data (e.g. a .bss with size 0) lead to an mmap of 0
bytes which fails with EINVAL.
Add a check to skip mapping sections which are present, but empty.
Signed-off-by: David Faust <david.faust@oracle.com>
---
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 b01fe01b0761..4e7ceb4f5a27 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1642,6 +1642,10 @@ static int bpf_object__init_global_data_maps(struct bpf_object *obj)
for (sec_idx = 1; sec_idx < obj->efile.sec_cnt; sec_idx++) {
sec_desc = &obj->efile.secs[sec_idx];
+ /* Skip recognized sections with size 0. */
+ if (sec_desc->data && sec_desc->data->d_size == 0)
+ continue;
+
switch (sec_desc->sec_type) {
case SEC_DATA:
sec_name = elf_sec_name(obj, elf_sec_by_idx(obj, sec_idx));
--
2.36.1
next reply other threads:[~2022-07-27 20:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-27 20:48 David Faust [this message]
2022-07-28 14:15 ` [PATCH bpf-next] libbpf: avoid mmap for size 0 sections Jiri Olsa
2022-07-28 19:29 ` David Faust
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=20220727204808.13210-1-david.faust@oracle.com \
--to=david.faust@oracle.com \
--cc=bpf@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