binutils-gdb/libctf
Nick Alcock 84f5c557a4 libctf, ld: diagnose corrupted CTF header cth_strlen
The last section in a CTF dict is the string table, at an offset
represented by the cth_stroff header field.  Its length is recorded in
the next field, cth_strlen, and the two added together are taken as the
size of the CTF dict.  Upon opening a dict, we check that none of the
header offsets exceed this size, and we check when uncompressing a
compressed dict that the result of the uncompression is the same length:
but CTF dicts need not be compressed, and short ones are not.
Uncompressed dicts just use the ctf_size without checking it.  This
field is thankfully almost unused: it is mostly used when reserializing
a dict, which can't be done to dicts read off disk since they're
read-only.

However, when opening an uncompressed foreign-endian dict we have to
copy it out of the mmaped region it is stored in so we can endian-
swap it, and we use ctf_size when doing that.  When the cth_strlen is
corrupt, this can overrun.

Fix this by checking the ctf_size in all uncompressed cases, just as we
already do in the compressed case.  Add a new test.

This came to light because various corrupted-CTF raw-asm tests had an
incorrect cth_strlen: fix all of them so they produce the expected
error again.

libctf/
	PR libctf/28933
	* ctf-open.c (ctf_bufopen_internal): Always check uncompressed
	CTF dict sizes against the section size in case the cth_strlen is
	corrupt.

ld/
	PR libctf/28933
	* testsuite/ld-ctf/diag-strlen-invalid.*: New test,
	derived from diag-cttname-invalid.s.
	* testsuite/ld-ctf/diag-cttname-invalid.s: Fix incorrect cth_strlen.
	* testsuite/ld-ctf/diag-cttname-null.s: Likewise.
	* testsuite/ld-ctf/diag-cuname.s: Likewise.
	* testsuite/ld-ctf/diag-parlabel.s: Likewise.
	* testsuite/ld-ctf/diag-parname.s: Likewise.
2022-03-23 13:48:32 +00:00
..
doc libctf: delete unused libctf_TEXINFOS 2022-02-11 04:20:49 -05:00
testsuite Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
.gitignore libctf: restructure error handling to reduce relocations 2020-07-22 17:57:20 +01:00
aclocal.m4 Implement a workaround for GNU mak jobserver 2021-01-12 05:45:44 -08:00
ChangeLog Add markers for 2.38 branch 2022-01-22 12:08:55 +00:00
ChangeLog-2020 libctf: fix old ChangeLog typo 2021-01-05 14:53:40 +00:00
config.h.in libctf, dedup: add deduplicator 2020-07-22 18:02:19 +01:00
configure libctf: re-generate configure 2021-12-02 07:51:57 -05:00
configure.ac Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-archive.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-create.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-decl.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-decls.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-dedup.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-dump.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-endian.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-error.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-hash.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-impl.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-inlines.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-intl.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-labels.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-link.c include, libctf, ld: extend variable section to contain functions too 2022-03-23 13:48:32 +00:00
ctf-lookup.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-open-bfd.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-open.c libctf, ld: diagnose corrupted CTF header cth_strlen 2022-03-23 13:48:32 +00:00
ctf-qsort_r.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-serialize.c include, libctf, ld: extend variable section to contain functions too 2022-03-23 13:48:32 +00:00
ctf-sha1.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-sha1.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-string.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-subr.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-types.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
ctf-util.c Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
elf.h Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
libctf.ver Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
Makefile.am Update year range in copyright notice of binutils files 2022-01-02 12:04:28 +10:30
Makefile.in libctf: delete unused libctf_TEXINFOS 2022-02-11 04:20:49 -05:00
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 2022-01-02 12:04:28 +10:30