Blame SOURCES/annobin.unicode.patch

81f3b3
--- /dev/null	2021-10-25 08:23:06.499675237 +0100
81f3b3
+++ annobin-9.85/tests/unicode-test	2021-10-26 17:50:14.620383879 +0100
81f3b3
@@ -0,0 +1,45 @@
81f3b3
+#!/bin/bash
81f3b3
+
81f3b3
+# Copyright (c) 2021 Red Hat.
81f3b3
+#
81f3b3
+# This is free software; you can redistribute it and/or modify it
81f3b3
+# under the terms of the GNU General Public License as published
81f3b3
+# by the Free Software Foundation; either version 3, or (at your
81f3b3
+# option) any later version.
81f3b3
+#
81f3b3
+# It is distributed in the hope that it will be useful, but
81f3b3
+# WITHOUT ANY WARRANTY; without even the implied warranty of
81f3b3
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
81f3b3
+# GNU General Public License for more details.
81f3b3
+
81f3b3
+TEST_NAME=unicode
81f3b3
+. $srcdir/common.sh
81f3b3
+
81f3b3
+OPTS="-O2 -g -Wl,-z,now -pie -fpie"
81f3b3
+
81f3b3
+start_test
81f3b3
+
81f3b3
+$GCC $OPTS $srcdir/trick-hello.s -o trick-hello.exe
81f3b3
+if [ $? != 0 ];
81f3b3
+then
81f3b3
+    echo "unicode-test: FAIL: Could not compile test source file"
81f3b3
+    end_test
81f3b3
+    exit 1
81f3b3
+fi
81f3b3
+
81f3b3
+# Run annocheck
81f3b3
+
81f3b3
+OPTS="--ignore-gaps --skip-all --test-unicode"
81f3b3
+
81f3b3
+$ANNOCHECK trick-hello.exe $OPTS > unicode.out
81f3b3
+grep -e "FAIL: unicode" unicode.out
81f3b3
+if [ $? != 0 ];
81f3b3
+then
81f3b3
+    echo "unicode-test: FAIL: annocheck did not detect suspicious symbol names"
81f3b3
+    $ANNOCHECK trick-hello.exe $OPTS --verbose
81f3b3
+    end_test
81f3b3
+    exit 1
81f3b3
+fi
81f3b3
+
81f3b3
+end_test
81f3b3
+
81f3b3
--- /dev/null	2021-10-25 08:23:06.499675237 +0100
81f3b3
+++ annobin-9.85/tests/trick-hello.s	2021-10-26 17:15:25.803197562 +0100
81f3b3
@@ -0,0 +1,33 @@
81f3b3
+	.file	"trick-hello.c"
81f3b3
+	.text
81f3b3
+	.section	.rodata
81f3b3
+.LC0:
81f3b3
+	.string	"hah, gotcha!"
81f3b3
+	.text
81f3b3
+	.globl	he‮oll‬
81f3b3
+	.type	he‮oll‬, @function
81f3b3
+he‮oll‬:
81f3b3
+.LFB0:
81f3b3
+	nop
81f3b3
+.LFE0:
81f3b3
+	.size	he‮oll‬, .-he‮oll‬
81f3b3
+	.section	.rodata
81f3b3
+.LC1:
81f3b3
+	.string	"Hello world"
81f3b3
+	.text
81f3b3
+	.globl	hello
81f3b3
+	.type	hello, @function
81f3b3
+hello:
81f3b3
+.LFB1:
81f3b3
+	nop
81f3b3
+.LFE1:
81f3b3
+	.size	hello, .-hello
81f3b3
+	.globl	main
81f3b3
+	.type	main, @function
81f3b3
+main:
81f3b3
+.LFB2:
81f3b3
+	nop
81f3b3
+.LFE2:
81f3b3
+	.size	main, .-main
81f3b3
+	.ident	"GCC: (GNU) 11.2.1 20210728 (Red Hat 11.2.1-1)"
81f3b3
+	.section	.note.GNU-stack,"",@progbits
81f3b3
diff -rup annobin.orig/Makefile.in annobin-9.72/Makefile.in
81f3b3
--- annobin.orig/Makefile.in	2021-10-27 17:34:09.438721166 +0100
81f3b3
+++ annobin-9.72/Makefile.in	2021-10-27 17:34:19.226658425 +0100
81f3b3
@@ -323,6 +323,7 @@ plugindir = @plugindir@
81f3b3
 prefix = @prefix@
81f3b3
 program_transform_name = @program_transform_name@
81f3b3
 psdir = @psdir@
81f3b3
+runstatedir = @runstatedir@
81f3b3
 sbindir = @sbindir@
81f3b3
 sharedstatedir = @sharedstatedir@
81f3b3
 srcdir = @srcdir@
81f3b3
diff -rup annobin.orig/annocheck/Makefile.in annobin-9.72/annocheck/Makefile.in
81f3b3
--- annobin.orig/annocheck/Makefile.in	2021-10-27 17:34:09.443721134 +0100
81f3b3
+++ annobin-9.72/annocheck/Makefile.in	2021-10-27 17:34:19.227658419 +0100
81f3b3
@@ -314,6 +314,7 @@ plugindir = @plugindir@
81f3b3
 prefix = @prefix@
81f3b3
 program_transform_name = @program_transform_name@
81f3b3
 psdir = @psdir@
81f3b3
+runstatedir = @runstatedir@
81f3b3
 sbindir = @sbindir@
81f3b3
 sharedstatedir = @sharedstatedir@
81f3b3
 srcdir = @srcdir@
81f3b3
diff -rup annobin.orig/annocheck/hardened.c annobin-9.72/annocheck/hardened.c
81f3b3
--- annobin.orig/annocheck/hardened.c	2021-10-27 17:34:09.443721134 +0100
81f3b3
+++ annobin-9.72/annocheck/hardened.c	2021-10-27 17:35:14.200306024 +0100
81f3b3
@@ -37,7 +37,8 @@
81f3b3
 #define SOURCE_SEGMENT_CONTENTS "segment contents"
81f3b3
 #define SOURCE_SEGMENT_HEADERS  "segment headers"
81f3b3
 #define SOURCE_STRING_SECTION   "string section"
81f3b3
-#define SOURCE_COMMENT_SECTION   "comment section"
81f3b3
+#define SOURCE_COMMENT_SECTION  "comment section"
81f3b3
+#define SOURCE_SYMBOL_SECTION   "symbol section"
81f3b3
 
81f3b3
 #define GOLD_COLOUR     "\e[33;40m"
81f3b3
 #define RED_COLOUR      "\x1B[31;47m"
81f3b3
@@ -199,6 +200,7 @@ enum test_index
81f3b3
   TEST_STACK_REALIGN,
81f3b3
   TEST_TEXTREL,
81f3b3
   TEST_THREADS,
81f3b3
+  TEST_UNICODE,
81f3b3
   TEST_WARNINGS,
81f3b3
   TEST_WRITEABLE_GOT,
81f3b3
 
81f3b3
@@ -243,6 +245,7 @@ static test tests [TEST_MAX] =
81f3b3
   TEST (stack-realign,      STACK_REALIGN,      "Compiled with -mstackrealign (i686 only)"),
81f3b3
   TEST (textrel,            TEXTREL,            "There are no text relocations in the binary"),
81f3b3
   TEST (threads,            THREADS,            "Compiled with -fexceptions"),
81f3b3
+  TEST (unicode,            UNICODE,            "No unicode symbol names"),
81f3b3
   TEST (warnings,           WARNINGS,           "Compiled with -Wall"),
81f3b3
   TEST (writeable-got,      WRITEABLE_GOT,      "The .got section is not writeable"),
81f3b3
 };
81f3b3
@@ -1099,6 +1102,11 @@ interesting_sec (annocheck_data *     da
81f3b3
   if (streq (sec->secname, ".gdb_index"))
81f3b3
     per_file.debuginfo_file = true;
81f3b3
 
81f3b3
+  if (tests[TEST_UNICODE].enabled
81f3b3
+      && (sec->shdr.sh_type == SHT_SYMTAB
81f3b3
+	  || sec->shdr.sh_type == SHT_DYNSYM))	  
81f3b3
+    return true;
81f3b3
+
81f3b3
   if (streq (sec->secname, ".text"))
81f3b3
     {
81f3b3
       /* Separate debuginfo files have a .text section with a non-zero
81f3b3
@@ -2829,6 +2837,64 @@ check_code_section (annocheck_data *
81f3b3
 }
81f3b3
 
81f3b3
 static bool
81f3b3
+contains_suspicious_characters (const unsigned char * name)
81f3b3
+{
81f3b3
+  uint i;
81f3b3
+  uint len = strlen ((const char *) name);
81f3b3
+
81f3b3
+  /* FIXME: Test that locale is UTF-8.  */
81f3b3
+
81f3b3
+  for (i = 0; i < len; i++)
81f3b3
+    {
81f3b3
+      unsigned char c = name[i];
81f3b3
+
81f3b3
+      if (isgraph (c))
81f3b3
+	continue;
81f3b3
+
81f3b3
+      /* Control characters are always suspect.  So are spaces and DEL  */
81f3b3
+      if (iscntrl (c) || c == ' ' || c == 0x7f)
81f3b3
+	return true;
81f3b3
+
81f3b3
+      if (c < 0x7f) /* This test is probably redundant.  */
81f3b3
+	continue;
81f3b3
+
81f3b3
+      return true;
81f3b3
+    }
81f3b3
+
81f3b3
+  return false;
81f3b3
+}
81f3b3
+
81f3b3
+static bool
81f3b3
+check_symbol_section (annocheck_data * data, annocheck_section * sec)
81f3b3
+{
81f3b3
+  if (! tests[TEST_UNICODE].enabled)
81f3b3
+    return true;
81f3b3
+
81f3b3
+  /* Scan the symbols looking for non-ASCII characters in their names
81f3b3
+     that might cause problems.  Note - we do not examine the string
81f3b3
+     tables directly as there are perfectly legitimate reasons why these
81f3b3
+     characters might appear in strings.  But when they are used for
81f3b3
+     identifier names, their use is ... problematic.  */
81f3b3
+  GElf_Sym  sym;
81f3b3
+  uint      symndx;
81f3b3
+
81f3b3
+  for (symndx = 1; gelf_getsym (sec->data, symndx, & sym) != NULL; symndx++)
81f3b3
+    {
81f3b3
+      const char * symname = elf_strptr (data->elf, sec->shdr.sh_link, sym.st_name);
81f3b3
+
81f3b3
+      if (contains_suspicious_characters ((const unsigned char *) symname))
81f3b3
+	{
81f3b3
+	  fail (data, TEST_UNICODE, SOURCE_SYMBOL_SECTION, "suspicious characters were found in a symbol name");
81f3b3
+	  einfo (VERBOSE, "%s: info: symname: '%s', (%lu bytes long) in section: %s",
81f3b3
+		 get_filename (data), symname, (unsigned long) strlen (symname), sec->secname);
81f3b3
+	  if (!BE_VERBOSE)
81f3b3
+	    break;
81f3b3
+	}
81f3b3
+    }
81f3b3
+  return true;
81f3b3
+}
81f3b3
+
81f3b3
+static bool
81f3b3
 check_sec (annocheck_data *     data,
81f3b3
 	   annocheck_section *  sec)
81f3b3
 {
81f3b3
@@ -2839,6 +2905,8 @@ check_sec (annocheck_data *     data,
81f3b3
      selected in interesting_sec().  */
81f3b3
   switch (sec->shdr.sh_type)
81f3b3
     {
81f3b3
+    case SHT_SYMTAB:
81f3b3
+    case SHT_DYNSYM:   return check_symbol_section (data, sec);
81f3b3
     case SHT_NOTE:     return check_note_section (data, sec);
81f3b3
     case SHT_STRTAB:   return check_string_section (data, sec);
81f3b3
     case SHT_DYNAMIC:  return check_dynamic_section (data, sec);
81f3b3
@@ -3526,6 +3594,7 @@ finish (annocheck_data * data)
81f3b3
 	    case TEST_RWX_SEG:
81f3b3
 	    case TEST_TEXTREL:
81f3b3
 	    case TEST_THREADS:
81f3b3
+	    case TEST_UNICODE:
81f3b3
 	    case TEST_WRITEABLE_GOT:
81f3b3
 	      /* The absence of a result for these tests actually means that they have passed.  */
81f3b3
 	      pass (data, i, SOURCE_FINAL_SCAN, NULL);
81f3b3
Only in annobin-9.72/annocheck: hardened.c.orig
81f3b3
Only in annobin-9.72/annocheck: hardened.c.rej
81f3b3
diff -rup annobin.orig/configure annobin-9.72/configure
81f3b3
--- annobin.orig/configure	2021-10-27 17:34:09.438721166 +0100
81f3b3
+++ annobin-9.72/configure	2021-10-27 17:34:19.229658406 +0100
81f3b3
@@ -763,6 +763,7 @@ infodir
81f3b3
 docdir
81f3b3
 oldincludedir
81f3b3
 includedir
81f3b3
+runstatedir
81f3b3
 localstatedir
81f3b3
 sharedstatedir
81f3b3
 sysconfdir
81f3b3
@@ -860,6 +861,7 @@ datadir='${datarootdir}'
81f3b3
 sysconfdir='${prefix}/etc'
81f3b3
 sharedstatedir='${prefix}/com'
81f3b3
 localstatedir='${prefix}/var'
81f3b3
+runstatedir='${localstatedir}/run'
81f3b3
 includedir='${prefix}/include'
81f3b3
 oldincludedir='/usr/include'
81f3b3
 docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
81f3b3
@@ -1112,6 +1114,15 @@ do
81f3b3
   | -silent | --silent | --silen | --sile | --sil)
81f3b3
     silent=yes ;;
81f3b3
 
81f3b3
+  -runstatedir | --runstatedir | --runstatedi | --runstated \
81f3b3
+  | --runstate | --runstat | --runsta | --runst | --runs \
81f3b3
+  | --run | --ru | --r)
81f3b3
+    ac_prev=runstatedir ;;
81f3b3
+  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
81f3b3
+  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
81f3b3
+  | --run=* | --ru=* | --r=*)
81f3b3
+    runstatedir=$ac_optarg ;;
81f3b3
+
81f3b3
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
81f3b3
     ac_prev=sbindir ;;
81f3b3
   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
81f3b3
@@ -1249,7 +1260,7 @@ fi
81f3b3
 for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
81f3b3
 		datadir sysconfdir sharedstatedir localstatedir includedir \
81f3b3
 		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
81f3b3
-		libdir localedir mandir
81f3b3
+		libdir localedir mandir runstatedir
81f3b3
 do
81f3b3
   eval ac_val=\$$ac_var
81f3b3
   # Remove trailing slashes.
81f3b3
@@ -1402,6 +1413,7 @@ Fine tuning of the installation director
81f3b3
   --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
81f3b3
   --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
81f3b3
   --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
81f3b3
+  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
81f3b3
   --libdir=DIR            object code libraries [EPREFIX/lib]
81f3b3
   --includedir=DIR        C header files [PREFIX/include]
81f3b3
   --oldincludedir=DIR     C header files for non-gcc [/usr/include]
81f3b3
Only in annobin-9.72: configure.orig
81f3b3
diff -rup annobin.orig/doc/Makefile.in annobin-9.72/doc/Makefile.in
81f3b3
--- annobin.orig/doc/Makefile.in	2021-10-27 17:34:09.439721160 +0100
81f3b3
+++ annobin-9.72/doc/Makefile.in	2021-10-27 17:34:19.229658406 +0100
81f3b3
@@ -329,6 +329,7 @@ plugindir = @plugindir@
81f3b3
 prefix = @prefix@
81f3b3
 program_transform_name = @program_transform_name@
81f3b3
 psdir = @psdir@
81f3b3
+runstatedir = @runstatedir@
81f3b3
 sbindir = @sbindir@
81f3b3
 sharedstatedir = @sharedstatedir@
81f3b3
 srcdir = @srcdir@
81f3b3
diff -rup annobin.orig/doc/annobin.info annobin-9.72/doc/annobin.info
81f3b3
--- annobin.orig/doc/annobin.info	2021-10-27 17:34:09.440721153 +0100
81f3b3
+++ annobin-9.72/doc/annobin.info	2021-10-27 17:34:19.230658399 +0100
81f3b3
@@ -737,6 +737,7 @@ File: annobin.info,  Node: Hardened,  Ne
81f3b3
        [-skip-stack-realign]
81f3b3
        [-skip-textrel]
81f3b3
        [-skip-threads]
81f3b3
+       [-skip-unicode]
81f3b3
        [-skip-warnings]
81f3b3
        [-skip-writeable-got]
81f3b3
        [-test-NAME]
81f3b3
@@ -863,6 +864,10 @@ code to support the test.
81f3b3
      Check that the program was built by a production-ready compiler.
81f3b3
      Disabled by '--skip-production'.
81f3b3
 
81f3b3
+'Unicode'
81f3b3
+     This test checks for the presence of multibyte characters in symbol
81f3b3
+     names, which are unusual and potentially dangerous.
81f3b3
+
81f3b3
    The tool does support a couple of other command line options as well:
81f3b3
 
81f3b3
 '--skip-future'
81f3b3
Only in annobin-9.72/doc: annobin.info.orig
81f3b3
Only in annobin-9.72/doc: annobin.info.rej
81f3b3
diff -rup annobin.orig/doc/annobin.texi annobin-9.72/doc/annobin.texi
81f3b3
--- annobin.orig/doc/annobin.texi	2021-10-27 17:34:09.439721160 +0100
81f3b3
+++ annobin-9.72/doc/annobin.texi	2021-10-27 17:34:19.230658399 +0100
81f3b3
@@ -842,6 +842,7 @@ annocheck
81f3b3
   [@b{--skip-stack-realign}]
81f3b3
   [@b{--skip-textrel}]
81f3b3
   [@b{--skip-threads}]
81f3b3
+  [@b{--skip-unicode}]
81f3b3
   [@b{--skip-warnings}]
81f3b3
   [@b{--skip-writeable-got}]
81f3b3
   [@b{--test-@var{name}}]
81f3b3
@@ -983,6 +984,11 @@ Check that the program makes consistent
81f3b3
 @item Production Ready Compiler
81f3b3
 Check that the program was built by a production-ready compiler.
81f3b3
 Disabled by @option{--skip-production}.
81f3b3
+
81f3b3
+@item Unicode
81f3b3
+This test checks for the presence of multibyte characters in symbol
81f3b3
+names, which are unusual and potentially dangerous.
81f3b3
+
81f3b3
 @end table
81f3b3
 
81f3b3
 The tool does support a couple of other command line options as well:
81f3b3
Only in annobin-9.72/doc: annobin.texi.orig
81f3b3
diff -rup annobin.orig/gcc-plugin/Makefile.in annobin-9.72/gcc-plugin/Makefile.in
81f3b3
--- annobin.orig/gcc-plugin/Makefile.in	2021-10-27 17:34:09.443721134 +0100
81f3b3
+++ annobin-9.72/gcc-plugin/Makefile.in	2021-10-27 17:34:19.230658399 +0100
81f3b3
@@ -333,6 +333,7 @@ plugindir = @plugindir@
81f3b3
 prefix = @prefix@
81f3b3
 program_transform_name = @program_transform_name@
81f3b3
 psdir = @psdir@
81f3b3
+runstatedir = @runstatedir@
81f3b3
 sbindir = @sbindir@
81f3b3
 sharedstatedir = @sharedstatedir@
81f3b3
 srcdir = @srcdir@
81f3b3
diff -rup annobin.orig/scripts/Makefile.in annobin-9.72/scripts/Makefile.in
81f3b3
--- annobin.orig/scripts/Makefile.in	2021-10-27 17:34:09.441721146 +0100
81f3b3
+++ annobin-9.72/scripts/Makefile.in	2021-10-27 17:34:19.230658399 +0100
81f3b3
@@ -284,6 +284,7 @@ plugindir = @plugindir@
81f3b3
 prefix = @prefix@
81f3b3
 program_transform_name = @program_transform_name@
81f3b3
 psdir = @psdir@
81f3b3
+runstatedir = @runstatedir@
81f3b3
 sbindir = @sbindir@
81f3b3
 sharedstatedir = @sharedstatedir@
81f3b3
 srcdir = @srcdir@
81f3b3
diff -rup annobin.orig/tests/Makefile.am annobin-9.72/tests/Makefile.am
81f3b3
--- annobin.orig/tests/Makefile.am	2021-10-27 17:34:09.444721127 +0100
81f3b3
+++ annobin-9.72/tests/Makefile.am	2021-10-27 17:34:19.230658399 +0100
81f3b3
@@ -22,6 +22,7 @@ TESTS=compile-test \
81f3b3
       missing-notes-test \
81f3b3
       active-checks-test \
81f3b3
       property-note-test \
81f3b3
+      unicode-test \
81f3b3
       hardening-fail-test
81f3b3
 
81f3b3
 if HAVE_DEBUGINFOD
81f3b3
diff -rup annobin.orig/tests/Makefile.in annobin-9.72/tests/Makefile.in
81f3b3
--- annobin.orig/tests/Makefile.in	2021-10-27 17:34:09.444721127 +0100
81f3b3
+++ annobin-9.72/tests/Makefile.in	2021-10-27 17:34:19.230658399 +0100
81f3b3
@@ -459,6 +459,7 @@ plugindir = @plugindir@
81f3b3
 prefix = @prefix@
81f3b3
 program_transform_name = @program_transform_name@
81f3b3
 psdir = @psdir@
81f3b3
+runstatedir = @runstatedir@
81f3b3
 sbindir = @sbindir@
81f3b3
 sharedstatedir = @sharedstatedir@
81f3b3
 srcdir = @srcdir@
81f3b3
@@ -479,7 +480,7 @@ TESTS = compile-test abi-test active-che
81f3b3
 	hardening-test instrumentation-test lto-test \
81f3b3
 	missing-notes-test objcopy-test section-size-test \
81f3b3
 	missing-notes-test active-checks-test property-note-test \
81f3b3
-	hardening-fail-test $(am__append_1)
81f3b3
+	unicode-test hardening-fail-test $(am__append_1)
81f3b3
 all: all-am
81f3b3
 
81f3b3
 .SUFFIXES:
81f3b3
@@ -764,6 +765,13 @@ property-note-test.log: property-note-te
81f3b3
 	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
81f3b3
 	--log-file $$b.log --trs-file $$b.trs \
81f3b3
 	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
81f3b3
+	"$$tst" $(AM_TESTS_FD_REDIRECT)
81f3b3
+unicode-test.log: unicode-test
81f3b3
+	@p='unicode-test'; \
81f3b3
+	b='unicode-test'; \
81f3b3
+	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
81f3b3
+	--log-file $$b.log --trs-file $$b.trs \
81f3b3
+	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
81f3b3
 	"$$tst" $(AM_TESTS_FD_REDIRECT)
81f3b3
 debuginfod-test.log: debuginfod-test
81f3b3
 	@p='debuginfod-test'; \
81f3b3
Only in annobin-9.72/tests: trick-hello.s
81f3b3
Only in annobin-9.72/tests: unicode-test