From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (wildebeest.demon.nl [212.238.236.112]) by sourceware.org (Postfix) with ESMTPS id 47E933870849 for ; Thu, 3 Sep 2020 09:58:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 47E933870849 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mark@klomp.org Received: from tarox.wildebeest.org (tarox.wildebeest.org [172.31.17.39]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 67B2530016BF; Thu, 3 Sep 2020 11:58:18 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id 88BCF41B987F; Thu, 3 Sep 2020 11:58:18 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH] libebl: Handle aarch64 bti, pac bits in gnu property note Date: Thu, 3 Sep 2020 11:56:15 +0200 Message-Id: <20200903095615.5710-1-mark@klomp.org> X-Mailer: git-send-email 2.18.4 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Sep 2020 09:58:23 -0000 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 --- libebl/ChangeLog | 5 ++ libebl/eblobjnote.c | 67 +++++++++++++++++++ tests/ChangeLog | 5 ++ tests/run-readelf-n.sh | 31 +++++++++ tests/testfile-gnu-property-note-aarch64.bz2 | Bin 0 -> 1952 bytes 5 files changed, 108 insertions(+) create mode 100755 tests/testfile-gnu-property-note-aarch64.bz2 diff --git a/libebl/ChangeLog b/libebl/ChangeLog index e54aa2c9..aa43b31f 100644 --- a/libebl/ChangeLog +++ b/libebl/ChangeLog @@ -1,3 +1,8 @@ +2020-09-03 Mark Wielaard + + * eblobjnote.c (ebl_object_note): For EM_AARCH64 handle BTI and PAC + in GNU_PROPERTY_AARCH64_FEATURE_1_AND. + 2020-07-19 Mark Wielaard * libebl.h: Only typedef Ebl if _LIBASM_H is undefined. diff --git a/libebl/eblobjnote.c b/libebl/eblobjnote.c index f7ac915c..37cbc499 100644 --- a/libebl/eblobjnote.c +++ b/libebl/eblobjnote.c @@ -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 ("", + 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 diff --git a/tests/ChangeLog b/tests/ChangeLog index 047100b0..cb2e9956 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,8 @@ +2020-09-03 Mark Wielaard + + * testfile-gnu-property-note-aarch64.bz2: New file. + * run-readelf-n.sh: Handle testfile-gnu-property-note-aarch64. + 2020-07-19 Mark Wielaard * asm-tst1.c: Include libebl.h after libasm.h. diff --git a/tests/run-readelf-n.sh b/tests/run-readelf-n.sh index cc7d7f66..4c98fd82 100755 --- a/tests/run-readelf-n.sh +++ b/tests/run-readelf-n.sh @@ -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 index 0000000000000000000000000000000000000000..2fe37b1957065c4ebeb5ffae4c933fe7da1310b6 GIT binary patch literal 1952 zcmV;R2VeL?T4*^jL0KkKSqDBAMgRyv|NsC0|Ns2||Nj5ye$M~r-+c6lZ^QU^#;x?+ zU;F>fU+>@sJhOes+G-$|TXH)Tr-p<LvGxcW7~ z@(nZ~5&(EWl8^|qIRTI$fLM|YtYpa=^n%@A+rOYtyX5jmp+0EnumLc=Mui!Ak~ zBZCi3naaqv7?w@f6#Zx$Tgdaz;5AUv->tW^3W#$)m6=F%ofvXfs)eS2mI?E<6*<(X zC6px~Q1g(5&{m~iD#dBiWDANUs+ACm2Gn@>oR0y-+22o*7q zl0<|_6*IGTl`oT=pa4a=V&U_Ff_Ul@0T|!2qrI%1Y=cy1)le;=kRT`ip0yMB13>W? zD5XM@V!x1sLvV~Xfx0WD1yZpO6FtsqLm38VO-}mlvFT8GQi5!+ZNZ5NDZdOQG=NNG zY(SvFAXRMvuV$r)sbZST7-b^1VS!h>-baMh%lcSYKR5ovpBh3*SLrU?NDs-WntF(m z1Vq6X;}S?W%toQ0KcX7p49qjgVL`KTHW_XVjyFYVpKIi<7JFR_t~7IWar7P7n+EAf zzD;U^3e(Jk6}ZT-*Bg3-EngrGm=@y2Hye9Mgi8l`$r=0JW5L$;4%DzGU}`N%5ymT} zgSr4@78-H@W@d0e$r@u56;(71e?0p#&@$;v#DPI>jEB%!MNz2odk z5We;pwu`tBLNZgIKBM>Mr4S;D8)az+AUQhJ!a9Y6nzn{aSPyrfL9u`=#U&w00tyG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