From: Anne Macedo <annemacedo@linux.microsoft.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
Isabella Basso <isabbasso@riseup.net>,
Paul Moore <paul@paul-moore.com>,
Anne Macedo <annemacedo@linux.microsoft.com>
Subject: [PATCH] libbpf: add validation to BTF's variable type ID
Date: Thu, 29 Sep 2022 13:05:58 -0300 [thread overview]
Message-ID: <20220929160558.5034-1-annemacedo@linux.microsoft.com> (raw)
If BTF is corrupted, a SEGV may occur due to a null pointer dereference on
bpf_object__init_user_btf_map.
This patch adds a validation that checks whether the DATASEC's variable
type ID is null. If so, it raises a warning.
Reported by oss-fuzz project [1].
A similar patch for the same issue exists on [2]. However, the code is
unreachable when using oss-fuzz data.
[1] https://github.com/libbpf/libbpf/issues/484
[2] https://patchwork.kernel.org/project/netdevbpf/patch/20211103173213.1376990-3-andrii@kernel.org/
Reviewed-by: Isabella Basso <isabbasso@riseup.net>
Signed-off-by: Anne Macedo <annemacedo@linux.microsoft.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 184ce1684dcd..0c88612ab7c4 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -2464,6 +2464,10 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
vi = btf_var_secinfos(sec) + var_idx;
var = btf__type_by_id(obj->btf, vi->type);
+ if (!var || !btf_is_var(var)) {
+ pr_warn("map #%d: non-VAR type seen", var_idx);
+ return -EINVAL;
+ }
var_extra = btf_var(var);
map_name = btf__name_by_offset(obj->btf, var->name_off);
--
2.30.2
next reply other threads:[~2022-09-29 16:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-29 16:05 Anne Macedo [this message]
2022-09-30 2:32 ` [PATCH] libbpf: add validation to BTF's variable type ID John Fastabend
2022-09-30 13:00 ` Anne Macedo
2022-09-30 22:38 ` Andrii Nakryiko
2022-10-03 21:26 ` Paul Moore
2022-10-05 22:42 ` Andrii Nakryiko
2022-10-06 17:01 ` Anne Macedo
2022-10-06 17:07 ` Andrii Nakryiko
2022-10-06 17:54 ` Anne Macedo
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=20220929160558.5034-1-annemacedo@linux.microsoft.com \
--to=annemacedo@linux.microsoft.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=isabbasso@riseup.net \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=paul@paul-moore.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=yhs@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