]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libebl: Handle aarch64 bti, pac bits in gnu property note
authorMark Wielaard <mark@klomp.org>
Thu, 3 Sep 2020 13:42:32 +0000 (09:42 -0400)
committerMark Wielaard <mark@klomp.org>
Mon, 7 Sep 2020 09:23:54 +0000 (11:23 +0200)
When building with gcc -mbranch-protection= we might get a gnu property
note indicating BTI (Branch Target Identification) and/or PAC (Pointer
Authentication Code) is being used.

Add a small testcase to show eu-readelf -n now properly lists those
bits in the gnu property note.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libebl/ChangeLog
libebl/eblobjnote.c
tests/ChangeLog
tests/Makefile.am
tests/run-readelf-n.sh
tests/testfile-gnu-property-note-aarch64.bz2 [new file with mode: 0755]

index e54aa2c90e4636c8216a7fb9eec71373720bf097..aa43b31f32fa3c77c9f2fb42bbad4f599caf14eb 100644 (file)
@@ -1,3 +1,8 @@
+2020-09-03  Mark Wielaard  <mark@klomp.org>
+
+       * eblobjnote.c (ebl_object_note): For EM_AARCH64 handle BTI and PAC
+       in GNU_PROPERTY_AARCH64_FEATURE_1_AND.
+
 2020-07-19  Mark Wielaard  <mark@klomp.org>
 
        * libebl.h: Only typedef Ebl if _LIBASM_H is undefined.
index f7ac915c59b2841edc24f6316fb70dc01b7bfd85..37cbc4998f49f054a71f2305a84f9865a0ed34bd 100644 (file)
@@ -476,6 +476,73 @@ ebl_object_note (Ebl *ebl, uint32_t namesz, const char *name, uint32_t type,
                            }
                        }
                    }
+                 else if (prop.pr_type >= GNU_PROPERTY_LOPROC
+                          && prop.pr_type <= GNU_PROPERTY_HIPROC
+                          && ehdr.e_machine == EM_AARCH64)
+                   {
+                     printf ("AARCH64 ");
+                     if (prop.pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND)
+                       {
+                         printf ("FEATURE_1_AND: ");
+
+                         if (prop.pr_datasz == 4)
+                           {
+                             GElf_Word data;
+                             in.d_type = ELF_T_WORD;
+                             out.d_type = ELF_T_WORD;
+                             in.d_size = 4;
+                             out.d_size = 4;
+                             in.d_buf = (void *) desc;
+                             out.d_buf = (void *) &data;
+
+                             if (gelf_xlatetom (ebl->elf, &out, &in,
+                                                elfident[EI_DATA]) == NULL)
+                               {
+                                 printf ("%s\n", elf_errmsg (-1));
+                                 return;
+                               }
+                             printf ("%08" PRIx32 " ", data);
+
+                             if ((data & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
+                                 != 0)
+                               {
+                                 printf ("BTI");
+                                 data &= ~GNU_PROPERTY_AARCH64_FEATURE_1_BTI;
+                                 if (data != 0)
+                                   printf (" ");
+                               }
+
+                             if ((data & GNU_PROPERTY_AARCH64_FEATURE_1_PAC)
+                                 != 0)
+                               {
+                                 printf ("PAC");
+                                 data &= ~GNU_PROPERTY_AARCH64_FEATURE_1_PAC;
+                                 if (data != 0)
+                                   printf (" ");
+                               }
+
+                             if (data != 0)
+                               printf ("UNKNOWN");
+                           }
+                         else
+                           printf ("<bad datasz: %" PRId32 ">",
+                                   prop.pr_datasz);
+
+                         printf ("\n");
+                       }
+                     else
+                       {
+                         printf ("%#" PRIx32, prop.pr_type);
+                         if (prop.pr_datasz > 0)
+                           {
+                             printf (" data: ");
+                             size_t i;
+                             for (i = 0; i < prop.pr_datasz - 1; i++)
+                               printf ("%02" PRIx8 " ", (uint8_t) desc[i]);
+                             printf ("%02" PRIx8 "\n", (uint8_t) desc[i]);
+                           }
+                       }
+                   }
                  else
                    {
                      if (prop.pr_type >= GNU_PROPERTY_LOPROC
index 047100b09740baa60ee631810a5a4cc491ff2883..61c6cb7c3db9fdde69a9a2db7714db5c253b09b7 100644 (file)
@@ -1,3 +1,10 @@
+2020-09-03  Mark Wielaard  <mark@klomp.org>
+
+       * testfile-gnu-property-note-aarch64.bz2: New file.
+       * run-readelf-n.sh: Handle testfile-gnu-property-note-aarch64.
+       * Makefile.am (EXTRA_DIST): Add
+       testfile-gnu-property-note-aarch64.bz2.
+
 2020-07-19  Mark Wielaard  <mark@klomp.org>
 
        * asm-tst1.c: Include libebl.h after libasm.h.
index d30b8218ebc2f73ec6a407c701fcdbae8f95ac07..939bbb6a502ef4ce0d9e82cf49649bd7d9c96a83 100644 (file)
@@ -319,6 +319,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
             testfile_gnu_props.64le.o.bz2 \
             testfile_gnu_props.32be.o.bz2 \
             testfile_gnu_props.64be.o.bz2 \
+            testfile-gnu-property-note-aarch64.bz2 \
             run-allfcts-multi.sh \
             test-offset-loop.bz2 test-offset-loop.alt.bz2 \
             run-prelink-addr-test.sh \
index cc7d7f66affb57fd87f29323efc4301188cf6307..4c98fd8242facda8c927aeb0a469f42955d5079b 100755 (executable)
@@ -226,3 +226,34 @@ Note section [ 4] '.note.gnu.property' of 56 bytes at offset 0x40:
   GNU                    8  GNU_PROPERTY_TYPE_0
     NO_COPY_ON_PROTECTION
 EOF
+
+# - testfile-gnu-property-note.c
+# int
+# main ()
+# {
+#   return 0;
+# }
+#
+# gcc -mbranch-protection=standard -c testfile-gnu-property-note.c
+# gcc -o testfile-gnu-property-note-aarch64 testfile-gnu-property-note.o
+# eu-strip --remove-section=.gnu.build.attributes \
+#         testfile-gnu-property-note-aarch64
+
+testfiles testfile-gnu-property-note-aarch64
+testrun_compare ${abs_top_builddir}/src/readelf -n testfile-gnu-property-note-aarch64 << EOF
+
+Note section [ 2] '.note.gnu.property' of 32 bytes at offset 0x2c8:
+  Owner          Data size  Type
+  GNU                   16  GNU_PROPERTY_TYPE_0
+    AARCH64 FEATURE_1_AND: 00000003 BTI PAC
+
+Note section [ 3] '.note.gnu.build-id' of 36 bytes at offset 0x2e8:
+  Owner          Data size  Type
+  GNU                   20  GNU_BUILD_ID
+    Build ID: af82d6df6f3b396487e3e27a826ca9cbbbecbe5f
+
+Note section [ 4] '.note.ABI-tag' of 32 bytes at offset 0x30c:
+  Owner          Data size  Type
+  GNU                   16  GNU_ABI_TAG
+    OS: Linux, ABI: 3.7.0
+EOF
diff --git a/tests/testfile-gnu-property-note-aarch64.bz2 b/tests/testfile-gnu-property-note-aarch64.bz2
new file mode 100755 (executable)
index 0000000..2fe37b1
Binary files /dev/null and b/tests/testfile-gnu-property-note-aarch64.bz2 differ