This series fixes two independent out-of-bounds read bugs in
ebl_object_note (libebl/eblobjnote.c) when parsing malformed ELF notes:
1. In NT_STAPSDT parsing, the second memchr for the argument string
scanned from args while passing the remaining length from pname
(desc + descsz - pname), reading past desc + descsz when the
argument string is unterminated. It also incremented and read args
unsequenced in the same call.
2. In GNU build attribute note parsing, reads into the note name were
not bounded by namesz: the header guard checked namesz < 2 instead of
requiring two bytes after the "GA" prefix, named attribute printing
used unbounded "%s"/strlen, numeric length calculation could wrap in
size_t when value passed name + namesz, and string attribute printing
used unbounded "%s".
Both were found by source audit and confirmed with valgrind on crafted
big-endian ELF inputs: an unterminated NT_STAPSDT argument string reads
past an 84-byte note allocation at eblobjnote.c:107, and an
unterminated build attribute name reads past a 20-byte one at :266.
The second also prints the bytes it reads, so readelf -n emits two
bytes of unrelated heap content on stdout. Both inputs are clean after
the series.
Patch 3 adds those two inputs as a test. Only the build attribute one
works as a regression test: it fails without patch 2 because the bytes
past the note name are printed. The stapsdt input cannot fail a
testrun_compare, since an over-long memchr length does not change which
byte is found first and the descriptor is rejected either way, so it is
there for coverage and to exercise that read under --enable-valgrind.
make check is 270 tests, 255 pass, 15 skip, 0 fail, with the new test
included.
Minseok Kim (3):
libebl: bound second stapsdt memchr by remaining length from args
libebl: bound GNU build attribute note reads by namesz
tests: add regression tests for unterminated stapsdt and build
attribute notes
libebl/eblobjnote.c | 47 ++++++++++++++++-----
tests/Makefile.am | 3 ++
tests/run-readelf-badnote.sh | 75 +++++++++++++++++++++++++++++++++
tests/testfile-badnote-ga.bz2 | Bin 0 -> 158 bytes
tests/testfile-badnote-sdt.bz2 | Bin 0 -> 159 bytes
5 files changed, 114 insertions(+), 11 deletions(-)
create mode 100755 tests/run-readelf-badnote.sh
create mode 100644 tests/testfile-badnote-ga.bz2
create mode 100644 tests/testfile-badnote-sdt.bz2
--
2.34.1