Blame SOURCES/annobin.unicode.patch

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