From b163653243e9419c3f74386375c95ad93b8980d2 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Wed, 12 Sep 2018 14:28:27 +0100 Subject: [PATCH] Bug fixes for recent update --- annocheck/hardened.c | 39 +++++++++++++++++++++++++-------------- plugin/x86_64.annobin.cc | 2 +- tests/Makefile.am | 2 +- tests/Makefile.in | 2 +- tests/property-note-test | 34 +++++++++++++++++++++++++++++----- tests/property-note.S | 8 ++++---- 6 files changed, 61 insertions(+), 26 deletions(-) diff --git a/annocheck/hardened.c b/annocheck/hardened.c index cb2252b..50a8284 100644 --- a/annocheck/hardened.c +++ b/annocheck/hardened.c @@ -792,19 +792,30 @@ walk_build_notes (annocheck_data * data, } else { - value = (value >> 9) & 3; - - if (value == 0 || value == 1) + if (value & (1 << 13)) { - report_i (INFO, "%s: fail: (%s): Insufficient optimization level: -O%d", - data, sec, note_data, prefer_func_name, value); - tests[TEST_OPTIMIZATION].num_fail ++; + /* Compiled with -Og rather than -O2. + Treat this as a flag to indicate that the package developer is + intentionally not compiling with -O2, so suppress warnings about it. */ + report_i (VERBOSE, "%s: skip: (%s): compiled with -Og, so ignoring test for -O2+", + data, sec, note_data, prefer_func_name, value); } - else /* value == 2 || value == 3 */ + else { - report_i (VERBOSE2, "%s: pass: (%s): Sufficient optimization level: -O%d", - data, sec, note_data, prefer_func_name, value); - tests[TEST_OPTIMIZATION].num_pass ++; + value = (value >> 9) & 3; + + if (value == 0 || value == 1) + { + report_i (INFO, "%s: fail: (%s): Insufficient optimization level: -O%d", + data, sec, note_data, prefer_func_name, value); + tests[TEST_OPTIMIZATION].num_fail ++; + } + else /* value == 2 || value == 3 */ + { + report_i (VERBOSE2, "%s: pass: (%s): Sufficient optimization level: -O%d", + data, sec, note_data, prefer_func_name, value); + tests[TEST_OPTIMIZATION].num_pass ++; + } } } break; @@ -934,8 +945,8 @@ check_note_section (annocheck_data * data, { if (sec->shdr.sh_addralign != 4 && sec->shdr.sh_addralign != 8) { - einfo (ERROR, "%s: note section %s not properly aligned", - data->filename, sec->secname); + einfo (ERROR, "%s: note section %s not properly aligned (alignment: %ld)", + data->filename, sec->secname, (long) sec->shdr.sh_addralign); } if (const_strneq (sec->secname, GNU_BUILD_ATTRS_SECTION_NAME)) @@ -1139,8 +1150,8 @@ check_seg (annocheck_data * data, { if (seg->phdr->p_align != 4) { - einfo (VERBOSE, "%s: Note segment not 4 or 8 byte aligned", - data->filename); + einfo (VERBOSE, "%s: Note segment not 4 or 8 byte aligned (alignment: %ld)", + data->filename, (long) seg->phdr->p_align); tests[TEST_PROPERTY_NOTE].num_fail ++; } diff --git a/plugin/x86_64.annobin.cc b/plugin/x86_64.annobin.cc index a8687e1..389611b 100644 --- a/plugin/x86_64.annobin.cc +++ b/plugin/x86_64.annobin.cc @@ -125,7 +125,7 @@ annobin_target_specific_function_notes (const char * aname, const char * aname_e || (unsigned long) ix86_isa_flags != global_x86_isa) { annobin_inform (1, "record ISA value of %lx for %s", - ix86_isa_flags, func_name); + (long) ix86_isa_flags, func_name); annobin_output_numeric_note (GNU_BUILD_ATTRIBUTE_ABI, ix86_isa_flags, "numeric: ABI", aname, aname_end, FUNC, sec_name); diff --git a/tests/Makefile.am b/tests/Makefile.am index 1c46543..a4fad11 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -15,10 +15,10 @@ TESTS=compile-test \ assembler-gap-test \ dynamic-notes-test \ section-size-test \ - property-note-test XFAIL_TESTS=hardening-fail-test \ missing-notes-test \ + property-note-test # FIXME: Add a test for merging notes... diff --git a/tests/Makefile.in b/tests/Makefile.in index 5a63b9c..6cb0c7b 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -223,7 +223,7 @@ TESTS = compile-test \ section-size-test XFAIL_TESTS = hardening-fail-test \ - missing-notes-test + missing-notes-test property-note-test all: all-am .SUFFIXES: diff --git a/tests/property-note-test b/tests/property-note-test index 87e045c..e64ce19 100755 --- a/tests/property-note-test +++ b/tests/property-note-test @@ -22,15 +22,39 @@ GCC=gcc ANNOCHECK=../annocheck/annocheck PLUGIN=../plugin/.libs/annobin.so -OPTS="-O2 -fpie -fstack-protector-strong -D_GLIBCXX_ASSERTIONS -D_FORTIFY_SOURCE=2" +OPTS="-c -O2 -D_FORTIFY_SOURCE=2 -fPIE -Wall -fstack-protector-strong -D_GLIBCXX_ASSERTIONS -fstack-clash-protection" +EXTRA_OPTS="-fcf-protection -mstackrealign" + +$GCC -fplugin=$PLUGIN -g $OPTS $EXTRA_OPTS $srcdir/hello_hard.c +if [ $? != 0 ]; +then + echo "Compiler might not support -fcf-protection, retrying without it" + EXTRA_OPTS="-mstackrealign" + $GCC -fplugin=$PLUGIN -g $OPTS $EXTRA_OPTS $srcdir/hello_hard.c + if [ $? != 0 ]; + then + echo "Compiler might not support -mstackrealign, retrying without it" + EXTRA_OPTS="-fcf-protection" + $GCC -fplugin=$PLUGIN -g $OPTS $EXTRA_OPTS $srcdir/hello_hard.c + if [ $? != 0 ]; + then + echo "Compiler might not support either -fcf-protection or -mstackrealign, retrying without both" + EXTRA_OPTS="" + $GCC -fplugin=$PLUGIN -g $OPTS $EXTRA_OPTS $srcdir/hello_hard.c + if [ $? != 0 ]; + then + echo "Failed :-(" + exit 1 + fi + fi + fi +fi $GAS $srcdir/property-note.S -o property-note.o -$GCC -fplugin=$PLUGIN $OPTS -c $srcdir/hello.c +$GCC -fplugin=$PLUGIN $OPTS $EXTRA_OPTS -c $srcdir/hello.c $srcdir/hello3.c -$GCC -fplugin=$PLUGIN $OPTS -c $srcdir/hello3.c - -$GCC -nostartfiles -e 0 hello.o property-note.o hello3.o -o property-note-test.exe -Wl,--defsym,big_stack=0 -Wl,-z,now +$GCC -fPIE hello.o property-note.o hello3.o -o property-note-test.exe -Wl,--defsym,big_stack=0 -Wl,-z,now $ANNOCHECK property-note-test.exe > property-note-test.out diff --git a/tests/property-note.S b/tests/property-note.S index 4ec0863..45eb391 100644 --- a/tests/property-note.S +++ b/tests/property-note.S @@ -10,20 +10,20 @@ text_end: .section .note.gnu.property, "a", %note .balign 4 .dc.l 4 # size of name - .dc.l 24 # size of description + .dc.l 16 # size of description .dc.l 0x5 # type = PROPERTY_TYPE_0 .asciz "GNU" # name (GNU Property Note) .dc.l 0xc0000002 # GNU_PROPERTY_X86_UINT32_AND_LO - .dc.l 8 # data size + .dc.l 4 # data size .dc.l 1 # property bits .dc.l 0 # padding .dc.l 4 # size of name - .dc.l 24 # size of description + .dc.l 16 # size of description .dc.l 0x5 # type = PROPERTY_TYPE_0 .asciz "GNU" # name (GNU Property Note) .dc.l 0xc0080000 # GNU_PROPERTY_X86_UINT32_OR_HI - .dc.l 8 # data size + .dc.l 4 # data size .dc.l 1 # isa bits .dc.l 0 # padding -- 2.43.5