Skip to content

Commit 805ddef

Browse files
author
Baoquan He
committed
coredump, vmcore: Set p_align to 4 for PT_NOTE
JIRA: https://issues.redhat.com/browse/RHEL-32199 Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git Conflict: There's fuzz in fs/binfmt_elf.c which need be handled manually. commit 60592fb Author: Fangrui Song <maskray@google.com> Date: Fri May 12 02:25:28 2023 +0000 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/D150022 Signed-off-by: Fangrui Song <maskray@google.com> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20230512022528.3430327-1-maskray@google.com Signed-off-by: Baoquan He <bhe@redhat.com>
1 parent 312df70 commit 805ddef

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

fs/binfmt_elf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ static void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, loff_t offset)
14821482
phdr->p_filesz = sz;
14831483
phdr->p_memsz = 0;
14841484
phdr->p_flags = 0;
1485-
phdr->p_align = 0;
1485+
phdr->p_align = 4;
14861486
}
14871487

14881488
static void fill_note(struct memelfnote *note, const char *name, int type,

fs/binfmt_elf_fdpic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ static inline void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, loff_t offs
12681268
phdr->p_filesz = sz;
12691269
phdr->p_memsz = 0;
12701270
phdr->p_flags = 0;
1271-
phdr->p_align = 0;
1271+
phdr->p_align = 4;
12721272
return;
12731273
}
12741274

fs/proc/vmcore.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ static int __init merge_note_headers_elf64(char *elfptr, size_t *elfsz,
879879
phdr.p_offset = roundup(note_off, PAGE_SIZE);
880880
phdr.p_vaddr = phdr.p_paddr = 0;
881881
phdr.p_filesz = phdr.p_memsz = phdr_sz;
882-
phdr.p_align = 0;
882+
phdr.p_align = 4;
883883

884884
/* Add merged PT_NOTE program header*/
885885
tmp = elfptr + sizeof(Elf64_Ehdr);
@@ -1070,7 +1070,7 @@ static int __init merge_note_headers_elf32(char *elfptr, size_t *elfsz,
10701070
phdr.p_offset = roundup(note_off, PAGE_SIZE);
10711071
phdr.p_vaddr = phdr.p_paddr = 0;
10721072
phdr.p_filesz = phdr.p_memsz = phdr_sz;
1073-
phdr.p_align = 0;
1073+
phdr.p_align = 4;
10741074

10751075
/* Add merged PT_NOTE program header*/
10761076
tmp = elfptr + sizeof(Elf32_Ehdr);

0 commit comments

Comments
 (0)