From: David Faust Date: Thu, 7 Nov 2024 17:27:07 +0000 (-0800) Subject: bpf: avoid possible null deref in btf_ext_output [PR target/117447] X-Git-Tag: basepoints/gcc-16~4527 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e1382034246a594f1da8dbaee97c4a06743f31a;p=thirdparty%2Fgcc.git bpf: avoid possible null deref in btf_ext_output [PR target/117447] The BPF-specific .BTF.ext section is always generated for BPF programs if -gbtf is specified, and generating it requires BTF information and assumes that the BTF info has already been generated. Compiling non-C languages to BPF is not supported, nor is generating CTF/BTF for non-C. But, compiling another language like C++ to BPF with -gbtf specified meant that we would try to generate the .BTF.ext section anyway, and then ICE because no BTF information was available. Add a check to bail out of btf_ext_output if the TU CTFC does not exist, meaning no BTF info is available. gcc/ PR target/117447 * config/bpf/btfext-out.cc (btf_ext_output): Bail if TU CTFC is null. --- diff --git a/gcc/config/bpf/btfext-out.cc b/gcc/config/bpf/btfext-out.cc index ca6241aa52ee..760b2b59ff6a 100644 --- a/gcc/config/bpf/btfext-out.cc +++ b/gcc/config/bpf/btfext-out.cc @@ -611,6 +611,9 @@ btf_ext_init (void) void btf_ext_output (void) { + if (!ctf_get_tu_ctfc ()) + return; + output_btfext_header (); output_btfext_func_info (btf_ext); if (TARGET_BPF_CORE)