Commit 0a7c2a84 authored by Tony Ambardar's avatar Tony Ambardar Committed by Alexei Starovoitov
Browse files

libbpf: Fix accessing BTF.ext core_relo header



Update btf_ext_parse_info() to ensure the core_relo header is present
before reading its fields. This avoids a potential buffer read overflow
reported by the OSS Fuzz project.

Fixes: cf579164 ("libbpf: Support BTF.ext loading and output in either endianness")
Signed-off-by: default avatarTony Ambardar <tony.ambardar@gmail.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://issues.oss-fuzz.com/issues/388905046
Link: https://lore.kernel.org/bpf/20250125065236.2603346-1-itugrok@yahoo.com


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent a63a631c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -3015,8 +3015,6 @@ static int btf_ext_parse_info(struct btf_ext *btf_ext, bool is_native)
		.desc = "line_info",
	};
	struct btf_ext_sec_info_param core_relo = {
		.off = btf_ext->hdr->core_relo_off,
		.len = btf_ext->hdr->core_relo_len,
		.min_rec_size = sizeof(struct bpf_core_relo),
		.ext_info = &btf_ext->core_relo_info,
		.desc = "core_relo",
@@ -3034,6 +3032,8 @@ static int btf_ext_parse_info(struct btf_ext *btf_ext, bool is_native)
	if (btf_ext->hdr->hdr_len < offsetofend(struct btf_ext_header, core_relo_len))
		return 0; /* skip core relos parsing */

	core_relo.off = btf_ext->hdr->core_relo_off;
	core_relo.len = btf_ext->hdr->core_relo_len;
	err = btf_ext_parse_sec_info(btf_ext, &core_relo, is_native);
	if (err)
		return err;