[LTP] [PATCH v8 2/2] coredump02: Verify ELF structure and notes
Andrea Cervesato
andrea.cervesato@suse.com
Wed Sep 9 11:15:59 CEST 2026
Hi Cyril,
> I would have expected that the elf headers are aligned properly and
> since we loaded the whole file into aligned buffer (malloc() aligns
> properly), it should be safe to just cast the desc pointer into the
> strcut elf_prpsinfo *info = desc; and acces info.pr_name directly from
> the buffer.
I made an analysis and I found out this is not valid.
It seems like we can't use the cast in x86_64 because it requires a
8 bytes aligned struct.
The kernel writes:
12 bytes: note header
5 bytes: "CORE" and its ending zero
3 bytes: padding
---
20 bytes total
Although malloc() aligns the buffer’s starting address, the descriptor
inside it is not 8-byte aligned. For example:
Buffer starts at address: 4096
Notes start at file offset: 624 (64 + 10 × 56)
First descriptor is another: 20 bytes later
Descriptor's memory address: 4740
So memory is not 8 bytes aligned and when we cast to a pointer we
might be misaligned when accessing pr_pid.
We still need memcpy(), so we make sure we are accessing the right
portion of the memory.
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com
More information about the ltp
mailing list