From 97bdc65f27dcd07f9f6eb967d31789436ff6ee01 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Wed, 2 Sep 2020 20:43:08 +0000 Subject: [PATCH] Don't assume objects in program sections have a size of a pointer. The size of the object at 'addr' is unknown and might be smaller than the size of a pointer (e.g. some x86 instructions are smaller than a pointer). Instead, just check that the address is in the bounds of the program header. Reported by: CHERI (indirectly) Reviewed by: kib, brooks Obtained from: CheriBSD MFC after: 1 week Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D26279 --- lib/libc/gen/elf_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libc/gen/elf_utils.c b/lib/libc/gen/elf_utils.c index 0d32c18ed34..fbf3bf17082 100644 --- a/lib/libc/gen/elf_utils.c +++ b/lib/libc/gen/elf_utils.c @@ -65,7 +65,7 @@ __elf_phdr_match_addr(struct dl_phdr_info *phdr_info, void *addr) #endif if (phdr_info->dlpi_addr + ph->p_vaddr <= (uintptr_t)addr && - (uintptr_t)addr + sizeof(addr) < phdr_info->dlpi_addr + + (uintptr_t)addr < phdr_info->dlpi_addr + ph->p_vaddr + ph->p_memsz) break; }