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
This commit is contained in:
John Baldwin 2020-09-02 20:43:08 +00:00
parent 1a4531bc98
commit 97bdc65f27
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=365278

View file

@ -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;
}