[PATCH] D66692: hwasan: Align n_namesz and n_descsz to 4 when reading notes.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 23 16:24:54 PDT 2019


pcc created this revision.
pcc added a reviewer: eugenis.
Herald added projects: Sanitizers, LLVM.
Herald added a subscriber: Sanitizers.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66692

Files:
  compiler-rt/lib/hwasan/hwasan.cpp


Index: compiler-rt/lib/hwasan/hwasan.cpp
===================================================================
--- compiler-rt/lib/hwasan/hwasan.cpp
+++ compiler-rt/lib/hwasan/hwasan.cpp
@@ -276,10 +276,10 @@
     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;
       }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66692.216979.patch
Type: text/x-patch
Size: 687 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190823/aeb38557/attachment.bin>


More information about the llvm-commits mailing list