Commit 60592fb6 authored by Fangrui Song's avatar Fangrui Song Committed by Kees Cook

coredump, vmcore: Set p_align to 4 for PT_NOTE

Tools like readelf/llvm-readelf use p_align to parse a PT_NOTE program
header as an array of 4-byte entries or 8-byte entries. Currently, there
are workarounds[1] in place for Linux to treat p_align==0 as 4. However,
it would be more appropriate to set the correct alignment so that tools
do not have to rely on guesswork. FreeBSD coredumps set p_align to 4 as
well.

[1]: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=82ed9683ec099d8205dc499ac84febc975235af6
[2]: https://reviews.llvm.org/D150022Signed-off-by: default avatarFangrui Song <maskray@google.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20230512022528.3430327-1-maskray@google.com
parent f1fcbaa1
...@@ -1517,7 +1517,7 @@ static void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, loff_t offset) ...@@ -1517,7 +1517,7 @@ static void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, loff_t offset)
phdr->p_filesz = sz; phdr->p_filesz = sz;
phdr->p_memsz = 0; phdr->p_memsz = 0;
phdr->p_flags = 0; phdr->p_flags = 0;
phdr->p_align = 0; phdr->p_align = 4;
} }
static void fill_note(struct memelfnote *note, const char *name, int type, static void fill_note(struct memelfnote *note, const char *name, int type,
......
...@@ -1269,7 +1269,7 @@ static inline void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, loff_t offs ...@@ -1269,7 +1269,7 @@ static inline void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, loff_t offs
phdr->p_filesz = sz; phdr->p_filesz = sz;
phdr->p_memsz = 0; phdr->p_memsz = 0;
phdr->p_flags = 0; phdr->p_flags = 0;
phdr->p_align = 0; phdr->p_align = 4;
return; return;
} }
......
...@@ -877,7 +877,7 @@ static int __init merge_note_headers_elf64(char *elfptr, size_t *elfsz, ...@@ -877,7 +877,7 @@ static int __init merge_note_headers_elf64(char *elfptr, size_t *elfsz,
phdr.p_offset = roundup(note_off, PAGE_SIZE); phdr.p_offset = roundup(note_off, PAGE_SIZE);
phdr.p_vaddr = phdr.p_paddr = 0; phdr.p_vaddr = phdr.p_paddr = 0;
phdr.p_filesz = phdr.p_memsz = phdr_sz; phdr.p_filesz = phdr.p_memsz = phdr_sz;
phdr.p_align = 0; phdr.p_align = 4;
/* Add merged PT_NOTE program header*/ /* Add merged PT_NOTE program header*/
tmp = elfptr + sizeof(Elf64_Ehdr); tmp = elfptr + sizeof(Elf64_Ehdr);
...@@ -1068,7 +1068,7 @@ static int __init merge_note_headers_elf32(char *elfptr, size_t *elfsz, ...@@ -1068,7 +1068,7 @@ static int __init merge_note_headers_elf32(char *elfptr, size_t *elfsz,
phdr.p_offset = roundup(note_off, PAGE_SIZE); phdr.p_offset = roundup(note_off, PAGE_SIZE);
phdr.p_vaddr = phdr.p_paddr = 0; phdr.p_vaddr = phdr.p_paddr = 0;
phdr.p_filesz = phdr.p_memsz = phdr_sz; phdr.p_filesz = phdr.p_memsz = phdr_sz;
phdr.p_align = 0; phdr.p_align = 4;
/* Add merged PT_NOTE program header*/ /* Add merged PT_NOTE program header*/
tmp = elfptr + sizeof(Elf32_Ehdr); tmp = elfptr + sizeof(Elf32_Ehdr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment