Blame SOURCES/annobin.unicode.patch

6b5924
--- /dev/null	2021-10-25 08:23:06.499675237 +0100
6b5924
+++ annobin-8.79/tests/unicode-test	2021-10-25 12:37:55.699238393 +0100
6b5924
@@ -0,0 +1,41 @@
6b5924
+#!/bin/bash
6b5924
+
6b5924
+# Copyright (c) 2021 Red Hat.
6b5924
+#
6b5924
+# This is free software; you can redistribute it and/or modify it
6b5924
+# under the terms of the GNU General Public License as published
6b5924
+# by the Free Software Foundation; either version 3, or (at your
6b5924
+# option) any later version.
6b5924
+#
6b5924
+# It is distributed in the hope that it will be useful, but
6b5924
+# WITHOUT ANY WARRANTY; without even the implied warranty of
6b5924
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6b5924
+# GNU General Public License for more details.
6b5924
+
6b5924
+ANNOCHECK=${ANNOCHECK:-../annocheck/annocheck}
6b5924
+GCC=${GCC:-gcc}
6b5924
+
6b5924
+# Mimics how glibc builds C sources without annotation.
6b5924
+
6b5924
+OPTS="-O2 -g -Wl,-z,now -pie -fpie"
6b5924
+
6b5924
+$GCC $OPTS $srcdir/trick-hello.s -o trick-hello.exe
6b5924
+if [ $? != 0 ];
6b5924
+then
6b5924
+    echo "unicode-test: FAIL: Could not compile test source file"
6b5924
+    exit 1
6b5924
+fi
6b5924
+
6b5924
+# Run annocheck
6b5924
+
6b5924
+OPTS="--ignore-gaps --skip-cf-protection --skip-glibcxx-assertions --skip-short-enum --skip-optimization --skip-stack-prot"
6b5924
+
6b5924
+$ANNOCHECK trick-hello.exe $OPTS > unicode.out
6b5924
+grep -e "FAIL: Symbol names containing multibyte characters" unicode.out
6b5924
+if [ $? != 0 ];
6b5924
+then
6b5924
+    echo "unicode-test: FAIL: annocheck did not detect suspicious symbol names"
6b5924
+    $ANNOCHECK trick-hello.exe $OPTS --verbose
6b5924
+    exit 1
6b5924
+fi
6b5924
+
6b5924
--- /dev/null	2021-10-25 08:23:06.499675237 +0100
6b5924
+++ annobin-8.79/tests/trick-hello.s	2021-10-25 15:10:39.722116284 +0100
6b5924
@@ -0,0 +1,33 @@
6b5924
+	.file	"trick-hello.c"
6b5924
+	.text
6b5924
+	.section	.rodata
6b5924
+.LC0:
6b5924
+	.string	"hah, gotcha!"
6b5924
+	.text
6b5924
+	.globl	he‮oll‬
6b5924
+	.type	he‮oll‬, @function
6b5924
+he‮oll‬:
6b5924
+.LFB0:
6b5924
+	nop
6b5924
+.LFE0:
6b5924
+	.size	he‮oll‬, .-he‮oll‬
6b5924
+	.section	.rodata
6b5924
+.LC1:
6b5924
+	.string	"Hello world"
6b5924
+	.text
6b5924
+	.globl	hello
6b5924
+	.type	hello, @function
6b5924
+hello:
6b5924
+.LFB1:
6b5924
+	nop
6b5924
+.LFE1:
6b5924
+	.size	hello, .-hello
6b5924
+	.globl	main
6b5924
+	.type	main, @function
6b5924
+main:
6b5924
+.LFB2:
6b5924
+	nop
6b5924
+.LFE2:
6b5924
+	.size	main, .-main
6b5924
+	.ident	"GCC: (GNU) 11.2.1 20210728 (Red Hat 11.2.1-1)"
6b5924
+	.section	.note.GNU-stack,"",@progbits
6b5924
diff -rup annobin.orig/Makefile.in annobin-9.29/Makefile.in
6b5924
--- annobin.orig/Makefile.in	2021-10-28 10:31:57.060267035 +0100
6b5924
+++ annobin-9.29/Makefile.in	2021-10-28 10:32:06.211206161 +0100
6b5924
@@ -323,6 +323,7 @@ plugindir = @plugindir@
6b5924
 prefix = @prefix@
6b5924
 program_transform_name = @program_transform_name@
6b5924
 psdir = @psdir@
6b5924
+runstatedir = @runstatedir@
6b5924
 sbindir = @sbindir@
6b5924
 sharedstatedir = @sharedstatedir@
6b5924
 srcdir = @srcdir@
6b5924
Only in annobin-9.29: Makefile.in.orig
6b5924
diff -rup annobin.orig/annocheck/Makefile.in annobin-9.29/annocheck/Makefile.in
6b5924
--- annobin.orig/annocheck/Makefile.in	2021-10-28 10:31:57.088266849 +0100
6b5924
+++ annobin-9.29/annocheck/Makefile.in	2021-10-28 10:32:06.212206154 +0100
6b5924
@@ -314,6 +314,7 @@ plugindir = @plugindir@
6b5924
 prefix = @prefix@
6b5924
 program_transform_name = @program_transform_name@
6b5924
 psdir = @psdir@
6b5924
+runstatedir = @runstatedir@
6b5924
 sbindir = @sbindir@
6b5924
 sharedstatedir = @sharedstatedir@
6b5924
 srcdir = @srcdir@
6b5924
Only in annobin-9.29/annocheck: Makefile.in.orig
6b5924
diff -rup annobin.orig/annocheck/hardened.c annobin-9.29/annocheck/hardened.c
6b5924
--- annobin.orig/annocheck/hardened.c	2021-10-28 10:31:57.088266849 +0100
6b5924
+++ annobin-9.29/annocheck/hardened.c	2021-10-28 10:33:13.936755663 +0100
6b5924
@@ -119,6 +119,7 @@ enum test_index
6b5924
   TEST_STACK_REALIGN,
6b5924
   TEST_TEXTREL,
6b5924
   TEST_THREADS,
6b5924
+  TEST_UNICODE,
6b5924
   TEST_WARNINGS,
6b5924
   TEST_WRITEABLE_GOT,
6b5924
 
6b5924
@@ -146,6 +147,7 @@ static void show_STACK_PROT         (ann
6b5924
 static void show_STACK_REALIGN      (annocheck_data *, test *);
6b5924
 static void show_TEXTREL            (annocheck_data *, test *);
6b5924
 static void show_THREADS            (annocheck_data *, test *);
6b5924
+static void show_UNICODE            (annocheck_data *, test *);
6b5924
 static void show_WARNINGS           (annocheck_data *, test *);
6b5924
 static void show_WRITEABLE_GOT      (annocheck_data *, test *);
6b5924
 
6b5924
@@ -177,6 +179,7 @@ static test tests [TEST_MAX] =
6b5924
   TEST (stack-realign,      STACK_REALIGN,      "Compiled with -mstackrealign (i686 only)"),
6b5924
   TEST (textrel,            TEXTREL,            "There are no text relocations in the binary"),
6b5924
   TEST (threads,            THREADS,            "Compiled with -fexceptions"),
6b5924
+  TEST (unicode,            UNICODE,            "No unicode symbol names"),
6b5924
   TEST (warnings,           WARNINGS,           "Compiled with -Wall"),
6b5924
   TEST (writeable-got,      WRITEABLE_GOT,      "The .got section is not writeable"),
6b5924
 };
6b5924
@@ -288,6 +291,11 @@ interesting_sec (annocheck_data *     da
6b5924
   if (streq (sec->secname, ".gdb_index"))
6b5924
     per_file.debuginfo_file = true;
6b5924
 
6b5924
+  if (tests[TEST_UNICODE].enabled
6b5924
+      && (sec->shdr.sh_type == SHT_SYMTAB
6b5924
+	  || sec->shdr.sh_type == SHT_DYNSYM))	  
6b5924
+    return true;
6b5924
+
6b5924
   if (streq (sec->secname, ".text"))
6b5924
     {
6b5924
       /* Separate debuginfo files have a .text section with a non-zero
6b5924
@@ -1830,6 +1838,64 @@ check_comment_section (annocheck_data *
6b5924
 }
6b5924
 
6b5924
 static bool
6b5924
+contains_suspicious_characters (const unsigned char * name)
6b5924
+{
6b5924
+  uint i;
6b5924
+  uint len = strlen ((const char *) name);
6b5924
+
6b5924
+  /* FIXME: Test that locale is UTF-8.  */
6b5924
+
6b5924
+  for (i = 0; i < len; i++)
6b5924
+    {
6b5924
+      unsigned char c = name[i];
6b5924
+
6b5924
+      if (isgraph (c))
6b5924
+	continue;
6b5924
+
6b5924
+      /* Control characters are always suspect.  So are spaces and DEL  */
6b5924
+      if (iscntrl (c) || c == ' ' || c == 0x7f)
6b5924
+	return true;
6b5924
+
6b5924
+      if (c < 0x7f) /* This test is probably redundant.  */
6b5924
+	continue;
6b5924
+
6b5924
+      return true;
6b5924
+    }
6b5924
+
6b5924
+  return false;
6b5924
+}
6b5924
+
6b5924
+static bool
6b5924
+check_symbol_section (annocheck_data * data, annocheck_section * sec)
6b5924
+{
6b5924
+  if (! tests[TEST_UNICODE].enabled)
6b5924
+    return true;
6b5924
+
6b5924
+  /* Scan the symbols looking for non-ASCII characters in their names
6b5924
+     that might cause problems.  Note - we do not examine the string
6b5924
+     tables directly as there are perfectly legitimate reasons why these
6b5924
+     characters might appear in strings.  But when they are used for
6b5924
+     identifier names, their use is ... problematic.  */
6b5924
+  GElf_Sym  sym;
6b5924
+  uint      symndx;
6b5924
+
6b5924
+  for (symndx = 1; gelf_getsym (sec->data, symndx, & sym) != NULL; symndx++)
6b5924
+    {
6b5924
+      const char * symname = elf_strptr (data->elf, sec->shdr.sh_link, sym.st_name);
6b5924
+
6b5924
+      if (contains_suspicious_characters ((const unsigned char *) symname))
6b5924
+	{
6b5924
+	  tests[TEST_UNICODE].num_fail ++;
6b5924
+	  einfo (VERBOSE, "%s: info: multibyte symname: '%s', (%lu bytes long) in section: %s",
6b5924
+		 data->filename, symname, (unsigned long) strlen (symname), sec->secname);
6b5924
+	  if (!BE_VERBOSE)
6b5924
+	    break;
6b5924
+	}
6b5924
+    }
6b5924
+  return true;
6b5924
+}
6b5924
+
6b5924
+static bool
6b5924
 check_sec (annocheck_data *     data,
6b5924
 	   annocheck_section *  sec)
6b5924
 {
6b5924
@@ -1837,6 +1903,8 @@ check_sec (annocheck_data *     data,
6b5924
      selected in interesting_sec().  */
6b5924
   switch (sec->shdr.sh_type)
6b5924
     {
6b5924
+    case SHT_SYMTAB:
6b5924
+    case SHT_DYNSYM:   return check_symbol_section (data, sec);
6b5924
     case SHT_NOTE:     return check_note_section (data, sec);
6b5924
     case SHT_STRTAB:   return check_string_section (data, sec);
6b5924
     case SHT_DYNAMIC:  return check_dynamic_section (data, sec);
6b5924
@@ -2617,6 +2685,19 @@ show_BRANCH_PROTECTION  (annocheck_data
6b5924
     }
6b5924
 }
6b5924
 
6b5924
+static void
6b5924
+show_UNICODE (annocheck_data * data, test * results)
6b5924
+{
6b5924
+  if (results->num_fail > 0)
6b5924
+    {
6b5924
+      fail (data, "Symbol names containing multibyte characters detected");
6b5924
+    }
6b5924
+  else
6b5924
+    {
6b5924
+      pass (data, "No symbol names containing multibyte characters detected");
6b5924
+    }
6b5924
+}
6b5924
+
6b5924
 static void
6b5924
 show_ENTRY (annocheck_data * data, test * results)
6b5924
 {
6b5924
Only in annobin-9.29/annocheck: hardened.c.orig
6b5924
Only in annobin-9.29/annocheck: hardened.c.rej
6b5924
Only in annobin-9.29: autom4te.cache
6b5924
diff -rup annobin.orig/configure annobin-9.29/configure
6b5924
--- annobin.orig/configure	2021-10-28 10:31:57.060267035 +0100
6b5924
+++ annobin-9.29/configure	2021-10-28 10:32:06.215206134 +0100
6b5924
@@ -761,6 +761,7 @@ infodir
6b5924
 docdir
6b5924
 oldincludedir
6b5924
 includedir
6b5924
+runstatedir
6b5924
 localstatedir
6b5924
 sharedstatedir
6b5924
 sysconfdir
6b5924
@@ -857,6 +858,7 @@ datadir='${datarootdir}'
6b5924
 sysconfdir='${prefix}/etc'
6b5924
 sharedstatedir='${prefix}/com'
6b5924
 localstatedir='${prefix}/var'
6b5924
+runstatedir='${localstatedir}/run'
6b5924
 includedir='${prefix}/include'
6b5924
 oldincludedir='/usr/include'
6b5924
 docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
6b5924
@@ -1109,6 +1111,15 @@ do
6b5924
   | -silent | --silent | --silen | --sile | --sil)
6b5924
     silent=yes ;;
6b5924
 
6b5924
+  -runstatedir | --runstatedir | --runstatedi | --runstated \
6b5924
+  | --runstate | --runstat | --runsta | --runst | --runs \
6b5924
+  | --run | --ru | --r)
6b5924
+    ac_prev=runstatedir ;;
6b5924
+  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
6b5924
+  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
6b5924
+  | --run=* | --ru=* | --r=*)
6b5924
+    runstatedir=$ac_optarg ;;
6b5924
+
6b5924
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
6b5924
     ac_prev=sbindir ;;
6b5924
   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
6b5924
@@ -1246,7 +1257,7 @@ fi
6b5924
 for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
6b5924
 		datadir sysconfdir sharedstatedir localstatedir includedir \
6b5924
 		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
6b5924
-		libdir localedir mandir
6b5924
+		libdir localedir mandir runstatedir
6b5924
 do
6b5924
   eval ac_val=\$$ac_var
6b5924
   # Remove trailing slashes.
6b5924
@@ -1399,6 +1410,7 @@ Fine tuning of the installation director
6b5924
   --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
6b5924
   --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
6b5924
   --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
6b5924
+  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
6b5924
   --libdir=DIR            object code libraries [EPREFIX/lib]
6b5924
   --includedir=DIR        C header files [PREFIX/include]
6b5924
   --oldincludedir=DIR     C header files for non-gcc [/usr/include]
6b5924
Only in annobin-9.29: configure.orig
6b5924
diff -rup annobin.orig/doc/Makefile.in annobin-9.29/doc/Makefile.in
6b5924
--- annobin.orig/doc/Makefile.in	2021-10-28 10:31:57.061267029 +0100
6b5924
+++ annobin-9.29/doc/Makefile.in	2021-10-28 10:32:06.215206134 +0100
6b5924
@@ -329,6 +329,7 @@ plugindir = @plugindir@
6b5924
 prefix = @prefix@
6b5924
 program_transform_name = @program_transform_name@
6b5924
 psdir = @psdir@
6b5924
+runstatedir = @runstatedir@
6b5924
 sbindir = @sbindir@
6b5924
 sharedstatedir = @sharedstatedir@
6b5924
 srcdir = @srcdir@
6b5924
Only in annobin-9.29/doc: Makefile.in.orig
6b5924
diff -rup annobin.orig/doc/annobin.info annobin-9.29/doc/annobin.info
6b5924
--- annobin.orig/doc/annobin.info	2021-10-28 10:31:57.061267029 +0100
6b5924
+++ annobin-9.29/doc/annobin.info	2021-10-28 10:32:06.215206134 +0100
6b5924
@@ -609,6 +609,7 @@ File: annobin.info,  Node: Hardened,  Ne
6b5924
        [-skip-stack-realign]
6b5924
        [-skip-textrel]
6b5924
        [-skip-threads]
6b5924
+       [-skip-unicode]
6b5924
        [-skip-writeable-got]
6b5924
        [-ignore-gaps]
6b5924
        [-disable-hardened]
6b5924
@@ -718,6 +719,10 @@ code to support the test.
6b5924
      Check that the program makes consistent use of the '-fshort-enum'
6b5924
      option.
6b5924
 
6b5924
+'Unicode'
6b5924
+     This test checks for the presence of multibyte characters in symbol
6b5924
+     names, which are unusual and potentially dangerous.
6b5924
+
6b5924
    The tool does support a couple of other command line options as well:
6b5924
 
6b5924
 '--enable-hardened'
6b5924
Only in annobin-9.29/doc: annobin.info.orig
6b5924
Only in annobin-9.29/doc: annobin.info.rej
6b5924
diff -rup annobin.orig/doc/annobin.texi annobin-9.29/doc/annobin.texi
6b5924
--- annobin.orig/doc/annobin.texi	2021-10-28 10:31:57.061267029 +0100
6b5924
+++ annobin-9.29/doc/annobin.texi	2021-10-28 10:32:06.215206134 +0100
6b5924
@@ -706,6 +706,7 @@ annocheck
6b5924
   [@b{--skip-stack-realign}]
6b5924
   [@b{--skip-textrel}]
6b5924
   [@b{--skip-threads}]
6b5924
+  [@b{--skip-unicode}]
6b5924
   [@b{--skip-writeable-got}]
6b5924
   [@b{--ignore-gaps}]
6b5924
   [@b{--disable-hardened}]
6b5924
@@ -831,6 +832,10 @@ enabled then this test will be skipped a
6b5924
 Check that the program makes consistent use of the
6b5924
 @option{-fshort-enum} option.
6b5924
 
6b5924
+@item Unicode
6b5924
+This test checks for the presence of multibyte characters in symbol
6b5924
+names, which are unusual and potentially dangerous.
6b5924
+
6b5924
 @end table
6b5924
 
6b5924
 The tool does support a couple of other command line options as well:
6b5924
Only in annobin-9.29/doc: annobin.texi.orig
6b5924
diff -rup annobin.orig/scripts/Makefile.in annobin-9.29/scripts/Makefile.in
6b5924
--- annobin.orig/scripts/Makefile.in	2021-10-28 10:31:57.061267029 +0100
6b5924
+++ annobin-9.29/scripts/Makefile.in	2021-10-28 10:32:08.111193522 +0100
6b5924
@@ -284,6 +284,7 @@ plugindir = @plugindir@
6b5924
 prefix = @prefix@
6b5924
 program_transform_name = @program_transform_name@
6b5924
 psdir = @psdir@
6b5924
+runstatedir = @runstatedir@
6b5924
 sbindir = @sbindir@
6b5924
 sharedstatedir = @sharedstatedir@
6b5924
 srcdir = @srcdir@
6b5924
Only in annobin-9.29/scripts: Makefile.in.orig
6b5924
diff -rup annobin.orig/tests/Makefile.am annobin-9.29/tests/Makefile.am
6b5924
--- annobin.orig/tests/Makefile.am	2021-10-28 10:31:57.089266843 +0100
6b5924
+++ annobin-9.29/tests/Makefile.am	2021-10-28 10:33:47.008535672 +0100
6b5924
@@ -16,6 +16,7 @@ TESTS=compile-test \
6b5924
       assembler-gap-test \
6b5924
       dynamic-notes-test \
6b5924
       instrumentation-test \
6b5924
+      unicode-test \
6b5924
       section-size-test
6b5924
 
6b5924
 if HAVE_DEBUGINFOD
6b5924
Only in annobin-9.29/tests: Makefile.am.orig
6b5924
Only in annobin-9.29/tests: Makefile.am.rej
6b5924
diff -rup annobin.orig/tests/Makefile.in annobin-9.29/tests/Makefile.in
6b5924
--- annobin.orig/tests/Makefile.in	2021-10-28 10:31:57.089266843 +0100
6b5924
+++ annobin-9.29/tests/Makefile.in	2021-10-28 10:34:15.803344120 +0100
6b5924
@@ -459,6 +459,7 @@ plugindir = @plugindir@
6b5924
 prefix = @prefix@
6b5924
 program_transform_name = @program_transform_name@
6b5924
 psdir = @psdir@
6b5924
+runstatedir = @runstatedir@
6b5924
 sbindir = @sbindir@
6b5924
 sharedstatedir = @sharedstatedir@
6b5924
 srcdir = @srcdir@
6b5924
@@ -477,7 +478,8 @@ top_srcdir = @top_srcdir@
6b5924
 TESTS = compile-test hardening-test hardening-fail-test \
6b5924
 	missing-notes-test active-checks-test abi-test \
6b5924
 	function-sections-test assembler-gap-test dynamic-notes-test \
6b5924
-	instrumentation-test section-size-test $(am__append_1)
6b5924
+	instrumentation-test unicode-test section-size-test \
6b5924
+	$(am__append_1)
6b5924
 XFAIL_TESTS = hardening-fail-test \
6b5924
       missing-notes-test \
6b5924
       active-checks-test \
6b5924
@@ -739,6 +741,13 @@ instrumentation-test.log: instrumentatio
6b5924
 	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
6b5924
 	--log-file $$b.log --trs-file $$b.trs \
6b5924
 	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
6b5924
+	"$$tst" $(AM_TESTS_FD_REDIRECT)
6b5924
+unicode-test.log: unicode-test
6b5924
+	@p='unicode-test'; \
6b5924
+	b='unicode-test'; \
6b5924
+	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
6b5924
+	--log-file $$b.log --trs-file $$b.trs \
6b5924
+	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
6b5924
 	"$$tst" $(AM_TESTS_FD_REDIRECT)
6b5924
 section-size-test.log: section-size-test
6b5924
 	@p='section-size-test'; \
6b5924
Only in annobin-9.29/tests: Makefile.in.orig
6b5924
Only in annobin-9.29/tests: Makefile.in.rej
6b5924
Only in annobin-9.29/tests: trick-hello.s
6b5924
Only in annobin-9.29/tests: unicode-test