hwasan: Align n_namesz and n_descsz to 4 when reading notes.

There is no requirement for the producer of a note to include the note
alignment in these fields. As a result we can end up missing the HWASAN note
if one of the other notes in the binary has the alignment missing.

Differential Revision: https://reviews.llvm.org/D66692

llvm-svn: 369826
This commit is contained in:
Peter Collingbourne 2019-08-23 23:33:26 +00:00
parent 27d69b2f4f
commit b2e7b85468
1 changed files with 2 additions and 2 deletions

View File

@ -276,10 +276,10 @@ static void InitGlobalsFromPhdrs(ElfW(Addr) base, const ElfW(Phdr) * phdr,
while (note < nend) {
auto *nhdr = reinterpret_cast<const ElfW(Nhdr) *>(note);
const char *name = note + sizeof(ElfW(Nhdr));
const char *desc = name + nhdr->n_namesz;
const char *desc = name + RoundUpTo(nhdr->n_namesz, 4);
if (nhdr->n_type != NT_LLVM_HWASAN_GLOBALS ||
internal_strcmp(name, "LLVM") != 0) {
note = desc + nhdr->n_descsz;
note = desc + RoundUpTo(nhdr->n_descsz, 4);
continue;
}