git: bcd7b196c83b - stable/14 - ELF note parser: provide more info on failure
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 14 Feb 2024 03:53:48 UTC
The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=bcd7b196c83b9a1ed5f2e2215c15542088d88aef commit bcd7b196c83b9a1ed5f2e2215c15542088d88aef Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2024-02-10 01:36:58 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2024-02-14 03:42:40 +0000 ELF note parser: provide more info on failure (cherry picked from commit 29d4f8bfc642f0196c27eb469ea7eb326ff529d1) --- sys/kern/imgact_elf.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index f22f9addb45c..85f0602fe584 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -2704,6 +2704,7 @@ __elfN(note_procstat_auxv)(void *arg, struct sbuf *sb, size_t *sizep) } } +#define MAX_NOTES_LOOP 4096 static bool __elfN(parse_notes)(struct image_params *imgp, Elf_Note *checknote, const char *note_vendor, const Elf_Phdr *pnote, @@ -2743,9 +2744,15 @@ __elfN(parse_notes)(struct image_params *imgp, Elf_Note *checknote, pnote->p_offset + pnote->p_filesz); buf = NULL; } - for (i = 0; i < 100 && note >= note0 && note < note_end; i++) { - if (!aligned(note, Elf32_Addr) || (const char *)note_end - - (const char *)note < sizeof(Elf_Note)) { + for (i = 0; i < MAX_NOTES_LOOP && note >= note0 && note < note_end; + i++) { + if (!aligned(note, Elf32_Addr)) { + uprintf("Unaligned ELF note\n"); + goto retf; + } + if ((const char *)note_end - (const char *)note < + sizeof(Elf_Note)) { + uprintf("ELF note to short\n"); goto retf; } if (note->n_namesz != checknote->n_namesz || @@ -2765,6 +2772,8 @@ nextnote: roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE) + roundup2(note->n_descsz, ELF_NOTE_ROUNDSIZE)); } + if (i >= MAX_NOTES_LOOP) + uprintf("ELF note parser reached %d notes\n", i); retf: res = false; ret: