libelf: Improve ELF header validationAvoid integer overflow and reading past EOF.MFC of r276427, r276443, r277249 from contrib/elftoolchain.