]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwfl: Make sure note data is properly aligned.
authorMark Wielaard <mark@klomp.org>
Sat, 18 Dec 2021 01:01:37 +0000 (02:01 +0100)
committerMark Wielaard <mark@klomp.org>
Sat, 18 Dec 2021 01:23:44 +0000 (02:23 +0100)
In dwfl_segment_report_module the note data might not be properly
aligned. Check that it is before accessing the data directly.
Otherwise convert data so it is properly aligned.

Also fix NOTE_ALIGN4 and NOTE_ALIGN8 to work correctly with long
types.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdwfl/ChangeLog
libdwfl/dwfl_segment_report_module.c
libelf/ChangeLog
libelf/libelfP.h

index 8760b1ef883c54064311652af062accedcc4c60e..f18a0c45701af6572ffeb85c55d7787d2b599518 100644 (file)
@@ -1,3 +1,8 @@
+2021-12-16  Mark Wielaard  <mark@klomp.org>
+
+       * dwfl_segment_report_module.c (dwfl_segment_report_module): Check
+       note data is properly aligned.
+
 2021-12-16  Mark Wielaard  <mark@klomp.org>
 
        * link_map.c (dwfl_link_map_report): Make sure phnum is non-zero.
index f323929e8564c640fce590490fcd09f1e3844485..2263e3cc1b1907cff254493318b338e33c4cdeab 100644 (file)
@@ -517,7 +517,10 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
               assert (sizeof (Elf32_Nhdr) == sizeof (Elf64_Nhdr));
 
               void *notes;
-              if (ei_data == MY_ELFDATA)
+              if (ei_data == MY_ELFDATA
+                 && (uintptr_t) data == (align == 8
+                                         ? NOTE_ALIGN8 ((uintptr_t) data)
+                                         : NOTE_ALIGN4 ((uintptr_t) data)))
                 notes = data;
               else
                 {
index 96059eff302b1c14fca87e84b18d879cd29bbf18..617d97a5aab19eff0c1083ce40791b66b14139f9 100644 (file)
@@ -1,3 +1,8 @@
+2021-12-16  Mark Wielaard  <mark@klomp.org>
+
+       * libelfP.h (NOTE_ALIGN4): And with negative unsigned long.
+       (NOTE_ALIGN8): Likewise.
+
 2021-12-15  Mark Wielaard  <mark@klomp.org>
 
        * elf_begin.c (get_shnum): Use offsetof to get field of unaligned
index fc1aebec8cc44563b099c2f54bf293b31e6d38bd..2c6995bbebf60dc6584ae756962c251cd667a3bc 100644 (file)
@@ -603,10 +603,10 @@ extern void __libelf_reset_rawdata (Elf_Scn *scn, void *buf, size_t size,
 /* Align offset to 4 bytes as needed for note name and descriptor data.
    This is almost always used, except for GNU Property notes, which use
    8 byte padding...  */
-#define NOTE_ALIGN4(n) (((n) + 3) & -4U)
+#define NOTE_ALIGN4(n) (((n) + 3) & -4UL)
 
 /* Special note padding rule for GNU Property notes.  */
-#define NOTE_ALIGN8(n) (((n) + 7) & -8U)
+#define NOTE_ALIGN8(n) (((n) + 7) & -8UL)
 
 /* Convenience macro.  */
 #define INVALID_NDX(ndx, type, data) \