binutils-gdb/libctf
Naveed Khan e375c6e25f libctf: bounds-check forward ctt_type before indexing pop[]
init_static_types_internal() walks the CTF type section that comes
directly from an object file's .ctf section.  During the first counting
pass it treats a CTF_K_FORWARD record's ctt_type as the CTF_K_* kind of
the forwarded tag and bumps the corresponding population count:

	if (kind == CTF_K_FORWARD)
	  pop[tp->ctt_type]++;

pop[] is a fixed-size stack array with CTF_K_MAX + 1 (64) entries, but
ctt_type is a 32-bit value read straight from the file and is never
validated.  A crafted dict whose forward record carries a ctt_type
greater than CTF_K_MAX therefore causes an out-of-bounds write to the
stack at an attacker-controlled index.

The type walk is reachable from ctf_bufopen()/ctf_open(), i.e. whenever
libctf opens a dict: ld while linking CTF, and objdump/nm --ctf.  The
second pass already tolerates an out-of-range ctt_type (ctf_name_table()
has a default case), so only this first-pass index was unguarded.

Reject a ctt_type outside the valid kind range as ECTF_CORRUPT, matching
the existing corruption handling in the same loop.

Reproduced with a 65-byte in-memory dict (one CTF_K_FORWARD record whose
ctt_type is 64) passed to ctf_bufopen().  Before the fix, AddressSanitizer
reports a stack-buffer-overflow at ctf-open.c:759 overflowing pop[64];
after the fix ctf_bufopen() returns ECTF_CORRUPT.  Valid forwards
(ctt_type of CTF_K_STRUCT/UNION/ENUM) and the boundary value CTF_K_MAX
still open successfully.

Signed-off-by: Naveed Khan <naveed@digiscrypt.com>
2026-07-16 09:47:42 +09:30
..
doc Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
testsuite libctf: remove CTF_F_ARRNELEMS flag 2026-02-27 15:06:41 +00:00
.gitignore libctf: restructure error handling to reduce relocations 2020-07-22 17:57:20 +01:00
aclocal.m4 Binutils: Add clang LTO support to AR and RANLIB 2025-09-25 12:30:13 +08:00
ChangeLog Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ChangeLog-2020 libctf: fix old ChangeLog typo 2021-01-05 14:53:40 +00:00
config.h.in libctf: suppress spurious failure of malloc-counting tests under valgrind 2024-06-18 13:20:32 +01:00
configure tidy m4 plugin config support 2025-11-03 10:59:50 +10:30
configure.ac Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-archive.c libctf: allow ctf_arc_bufpreamble to fail 2026-02-27 15:06:39 +00:00
ctf-create.c Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-decl.c libctf: remove CTF_F_ARRNELEMS flag 2026-02-27 15:06:41 +00:00
ctf-decls.h Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-dedup.c Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-dump.c libctf: remove CTF_F_ARRNELEMS flag 2026-02-27 15:06:41 +00:00
ctf-endian.h Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-error.c Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-hash.c Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-impl.h Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-inlines.h Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-intl.h Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-labels.c Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-link.c PR 34275 double free in ctf_link_deduplicating_per_cu 2026-07-04 09:23:00 +09:30
ctf-lookup.c Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-open-bfd.c libctf: allow ctf_arc_bufpreamble to fail 2026-02-27 15:06:39 +00:00
ctf-open.c libctf: bounds-check forward ctt_type before indexing pop[] 2026-07-16 09:47:42 +09:30
ctf-qsort_r.c Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-serialize.c Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-sha1.c Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-sha1.h Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-string.c Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-subr.c Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-types.c Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
ctf-util.c Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
elf.h Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
libctf.ver Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
Makefile.am Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
Makefile.in Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
NEWS include, libctf, ld: extend variable section to contain functions too 2022-03-23 13:48:32 +00:00
swap.h Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30