Both tls_info and ioperm_info check the note descriptor size only for alignment, not magnitude:
if (descsz % 16 != 0) /* backends/i386_corenote.c, NT_386_TLS */
if (descsz % 4 != 0) /* backends/x86_corenote.c, NT_386_IOPERM */
Because 0 % 16 == 0 and 0 % 4 == 0, a zero-length descriptor passes both
guards. Both functions also set *nregloc to 0, so handle_core_items()
receives the note's real n_descsz without downstream size re-checks. The
item tables (tls_items[] and ioperm_item) then dereference 16 bytes
(offsets 0x0, 0x4, 0x8, and 0xc) and 4 bytes (offset 0x0) respectively,
reading past the end of a zero-length descriptor.
Across the seven guards in this family, the five EXTRA_NOTES handlers in
backends/linux-core-note.c bound magnitude by exact size comparison, and
libebl/eblobjnote.c pairs both checks for a repeating descriptor:
if (descsz >= 8 && descsz % 4 == 0)
Because NT_386_TLS and NT_386_IOPERM hold repeating entries, the bound
must be a non-zero minimum (at least 16 and 4 bytes) rather than an
equality.
On an x86 core file containing an NT_386_TLS note with n_descsz 0
followed by a second note, readelf -n previously read into the adjacent
note header and printed its fields as TLS entry values:
CORE 0 386_TLS
index: 16, base: 0x00000000, limit: 0x00000003, flags: 0x44434241
Here, 16, 0x00000000, 0x00000003, and 0x44434241 are the following note's
n_namesz, n_descsz, n_type (NT_PRPSINFO), and the first four bytes of its
owner name "ABCD".
With the non-empty check in place, the zero-length note is listed with no
item line, while a well-formed 16-byte descriptor is unaffected.
ChangeLog:
* backends/i386_corenote.c (tls_info): Reject empty descriptors
by requiring descsz >= 16.
* backends/x86_corenote.c (ioperm_info): Reject empty descriptors
by requiring descsz >= 4.
Signed-off-by: Minseok Kim <[email protected]>
SEND-ME.patch
Description: Binary data
