Skip to content

Commit 961a285

Browse files
Alexey Dobriyanakpm00
authored andcommitted
build-id: require program headers to be right after ELF header
Neither ELF spec not ELF loader require program header to be placed right after ELF header, but build-id code very much assumes such placement: See find_get_page(vma->vm_file->f_mapping, 0); line and checks against PAGE_SIZE. Returns errors for now until someone rewrites build-id parser to be more inline with load_elf_binary(). Link: https://lkml.kernel.org/r/d58bc281-6ca7-467a-9a64-40fa214bd63e@p183 Signed-off-by: Alexey Dobriyan <[email protected]> Reviewed-by: Jiri Olsa <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 6073496 commit 961a285

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/buildid.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ static int get_build_id_32(const void *page_addr, unsigned char *build_id,
7373
Elf32_Phdr *phdr;
7474
int i;
7575

76+
/*
77+
* FIXME
78+
* Neither ELF spec nor ELF loader require that program headers
79+
* start immediately after ELF header.
80+
*/
81+
if (ehdr->e_phoff != sizeof(Elf32_Ehdr))
82+
return -EINVAL;
7683
/* only supports phdr that fits in one page */
7784
if (ehdr->e_phnum >
7885
(PAGE_SIZE - sizeof(Elf32_Ehdr)) / sizeof(Elf32_Phdr))
@@ -98,6 +105,13 @@ static int get_build_id_64(const void *page_addr, unsigned char *build_id,
98105
Elf64_Phdr *phdr;
99106
int i;
100107

108+
/*
109+
* FIXME
110+
* Neither ELF spec nor ELF loader require that program headers
111+
* start immediately after ELF header.
112+
*/
113+
if (ehdr->e_phoff != sizeof(Elf64_Ehdr))
114+
return -EINVAL;
101115
/* only supports phdr that fits in one page */
102116
if (ehdr->e_phnum >
103117
(PAGE_SIZE - sizeof(Elf64_Ehdr)) / sizeof(Elf64_Phdr))

0 commit comments

Comments
 (0)