]> sourceware.org Git - annobin.git/commitdiff
10.68: Annocheck: Add more glibc exceptions
authorNick Clifton <nickc@redhat.com>
Tue, 3 May 2022 13:38:33 +0000 (14:38 +0100)
committerNick Clifton <nickc@redhat.com>
Tue, 3 May 2022 13:38:33 +0000 (14:38 +0100)
annobin-global.h
annocheck/hardened.c
annocheck/libannocheck.h
doc/annobin.info
doc/annobin.texi

index 36066ecaee64a7962befd5994ba808b9d5b7faed..64516c7faf9292b55c62408a503541d433550750 100644 (file)
@@ -23,7 +23,7 @@ extern "C" {
 
    NB/ Keep this value in sync with libannochck_version defined in
    annocheck/libannocheck.h.  */
-#define ANNOBIN_VERSION 1067
+#define ANNOBIN_VERSION 1068
 
 /* The version of the annotation specification supported.  */
 #define SPEC_VERSION  3
index 810ec984a0f86f9005a4ddca58ec2356b6259cc2..45e783dfbbc40b79c6afea47f06143493626754c 100644 (file)
@@ -1176,6 +1176,24 @@ is_special_glibc_binary (const char * path)
 {
   int i;
 
+  /* The contents of static glibc libraries should be ignored.  */
+  if (strchr (path, ':'))
+    {
+      static const char * known_glibc_libraries [] =
+       {
+         "libBrokenLocale.a",
+         "libc.a:",
+         "libc_nonshared.a:",
+         "libm-2.34.a:",
+         "libmvec.a:",
+         "libresolv.a:"
+       };
+
+      for (i = ARRAY_SIZE (known_glibc_libraries); i--;)
+       if (strstr (path, known_glibc_libraries[i]) != NULL)
+         return true;
+    }
+  
   /* If we are testing an uninstalled rpm then the paths will start with "."
      so skip this.  */
   if (path[0] == '.')
@@ -1213,7 +1231,7 @@ is_special_glibc_binary (const char * path)
              path += len;
              break;
            }
-         /* Do not abort this loop if res > 0/
+         /* Do not abort this loop if res > 0
             We can have a file like /usr/lib64/libmcheck.a which will
             not match /usr/lib64/gconv but which should match /usr/lib64.  */
        }
@@ -1510,8 +1528,10 @@ is_special_glibc_binary (const char * path)
       "libBrokenLocale-2.28.so",
       "libBrokenLocale.so.1",
       "libSegFault.so",
+      "libanl.so.1",
       "libc.so.6",
       "libc_malloc_debug.so.0",
+      "libdl.so.2",
       "libg.a:dummy.o",
       "libm.so.6",
       "libmcheck.a",      
@@ -1523,10 +1543,12 @@ is_special_glibc_binary (const char * path)
       "libnss_compat.so.2",
       "libpcprofile.so",
       "libpthread-2.28.so",
+      "libpthread.so.0",
       "libresolv-2.28.so",
       "libresolv.so.2",
       "librt.so.1",
       "libthread_db.so.1",
+      "libutil.so.1",
       "locale",
       "localedef",
       "makedb",
@@ -1979,6 +2001,7 @@ skip_fortify_checks_for_function (annocheck_data * data, enum test_index check,
       "_nss_files_sethostent",
       "_start",
       "abort",
+      "atexit",
       "blacklist_store_name",
       "buffer_free",
       "cabsf128",
@@ -4124,19 +4147,18 @@ interesting_seg (annocheck_data *    data,
   if (disabled)
     return false;
 
-  if (! skip_test (TEST_RWX_SEG))
+  switch (seg->phdr->p_type)
     {
-      if ((seg->phdr->p_flags & (PF_X | PF_W | PF_R)) == (PF_X | PF_W | PF_R))
+    case PT_TLS:
+      if (! skip_test (TEST_RWX_SEG)
+         && seg->phdr->p_memsz > 0
+         && (seg->phdr->p_flags & PF_X))
        {
-         /* Object files should not have segments.  */
-         assert (! is_object_file ());
-         fail (data, TEST_RWX_SEG, SOURCE_SEGMENT_HEADERS, "segment has Read, Write and eXecute flags set");
-         einfo (VERBOSE2, "RWX segment number: %d", seg->number);
+         fail (data, TEST_RWX_SEG, SOURCE_SEGMENT_HEADERS, "TLS segment has eXecute flag set");
+         einfo (VERBOSE2, "TLS segment number: %d", seg->number);
        }
-    }
-
-  switch (seg->phdr->p_type)
-    {
+      break;
+      
     case PT_INTERP:
       per_file.has_program_interpreter = true;
       break;
@@ -4154,6 +4176,7 @@ interesting_seg (annocheck_data *    data,
            fail (data, TEST_GNU_STACK, SOURCE_SEGMENT_HEADERS, "the GNU stack segment has execute permission");
          else if ((seg->phdr->p_flags & PF_X) == 0)
            pass (data, TEST_GNU_STACK, SOURCE_SEGMENT_HEADERS, "stack segment exists with the correct permissions");
+         /* FIXME: Check for multiple PT_GNU_STACK segments ?  */
        }
       break;
 
@@ -4172,6 +4195,18 @@ interesting_seg (annocheck_data *    data,
       return supports_property_notes (per_file.e_machine);
 
     case PT_LOAD:
+      if (! skip_test (TEST_RWX_SEG))
+       {
+         if (seg->phdr->p_memsz > 0
+             && (seg->phdr->p_flags & (PF_X | PF_W | PF_R)) == (PF_X | PF_W | PF_R))
+           {
+             /* Object files should not have segments.  */
+             assert (! is_object_file ());
+             fail (data, TEST_RWX_SEG, SOURCE_SEGMENT_HEADERS, "segment has Read, Write and eXecute flags set");
+             einfo (VERBOSE2, "RWX segment number: %d", seg->number);
+           }
+       }
+
       /* If we are checking the entry point instruction then we need to load
         the segment.  We check segments rather than sections because executables
         do not have to have sections.  */
@@ -5074,7 +5109,7 @@ finish (annocheck_data * data)
              else if (is_special_glibc_binary (data->full_filename))
                skip (data, i, SOURCE_FINAL_SCAN, "glibc binaries not compiled with LTO");
              else
-               maybe (data, i, SOURCE_FINAL_SCAN, "no indication that LTO was used");
+               info (data, i, SOURCE_FINAL_SCAN, "no indication that LTO was used");
              break;
 
            case TEST_PIE:
index 87c409b34af808a95e9052740c28f87ae7fc523c..64bbccbff70c713eb0360efc7accd3ab7bf1770a 100644 (file)
@@ -18,7 +18,7 @@ extern "C" {
 
 /* NB/ Keep this value in sync with ANNOBIN_VERSION defined in
    annobin-global.h.  */
-const unsigned int libannocheck_version = 1067;
+const unsigned int libannocheck_version = 1068;
 
 typedef enum libannocheck_error
 {
index eaea78b53f699807ec47ca166920f33186c82205..eade2b3d8f9c608f7dc190c8c4dbd170df40a184 100644 (file)
@@ -1701,13 +1701,17 @@ File: annobin.info,  Node: Test rwx seg,  Next: Test short enums,  Prev: Test ru
 
        Example:  FAIL: rwx-seg test because segment has Read, Write and eXecute flags set
 
-   This test checks that the file does not have any segments that have
-all three of the READ, WRITE and EXECUTE permissions.  Code segments
-should have read and execute permissions, but they should not be
-writable as otherwise an attacker can overwrite the code.  Data segments
-should have read permission, and possibly write permission as well, but
-never execute permission as otherwise an attacker might be able to
-create their own code in a data area.
+   This test checks that the file does not have any segments that are
+  1. have all three of the READ, WRITE and EXECUTE permissions.
+  2. have a non-zero size
+  3. are resident in memory when the program runs
+  4. do not have an architecture/OS specific type
+
+   Code segments should have read and execute permissions, but they
+should not be writable as otherwise an attacker can overwrite the code.
+Data segments should have read permission, and possibly write permission
+as well, but never execute permission as otherwise an attacker might be
+able to create their own code in a data area.
 
    The linker will normally never create a binary file with a segment
 with all three permissions, but it is possible to force it to do so by
@@ -3565,40 +3569,40 @@ Node: Test production\7f64729
 Node: Test property note\7f65542
 Node: Test run path\7f68019
 Node: Test rwx seg\7f70240
-Node: Test short enums\7f71512
-Node: Test stack clash\7f72529
-Node: Test stack prot\7f73990
-Node: Test stack realign\7f75322
-Node: Test textrel\7f76592
-Node: Test threads\7f77849
-Node: Test unicode\7f78664
-Node: Test warnings\7f80155
-Node: Test writable got\7f80990
-Node: Hardened Command Line Options\7f82276
-Node: Waiving Hardened Results\7f87716
-Node: Notes\7f89662
-Node: Size\7f90298
-Node: Timing\7f92667
-Node: Libannocheck\7f93306
-Node: libannocheck_init\7f95245
-Node: libannocheck_finish\7f96167
-Node: libannocheck_get_version\7f96715
-Node: libannocheck_get_error_message\7f97124
-Node: libannocheck_get_known_tests\7f97764
-Node: libannocheck_enable_all_tests\7f98930
-Node: libannocheck_disable_all_tests\7f99409
-Node: libannocheck_enable_test\7f99965
-Node: libannocheck_disable_test\7f100633
-Node: libannocheck_enable_profile\7f101302
-Node: libannocheck_get_known_profiles\7f101824
-Node: libannocheck_run_tests\7f102527
-Node: Configure Options\7f103372
-Node: Legacy Scripts\7f105714
-Node: Who Built Me\7f106489
-Node: ABI Checking\7f109249
-Node: Hardening Checks\7f111365
-Node: Checking Archives\7f115451
-Node: GNU FDL\7f117872
+Node: Test short enums\7f71649
+Node: Test stack clash\7f72666
+Node: Test stack prot\7f74127
+Node: Test stack realign\7f75459
+Node: Test textrel\7f76729
+Node: Test threads\7f77986
+Node: Test unicode\7f78801
+Node: Test warnings\7f80292
+Node: Test writable got\7f81127
+Node: Hardened Command Line Options\7f82413
+Node: Waiving Hardened Results\7f87853
+Node: Notes\7f89799
+Node: Size\7f90435
+Node: Timing\7f92804
+Node: Libannocheck\7f93443
+Node: libannocheck_init\7f95382
+Node: libannocheck_finish\7f96304
+Node: libannocheck_get_version\7f96852
+Node: libannocheck_get_error_message\7f97261
+Node: libannocheck_get_known_tests\7f97901
+Node: libannocheck_enable_all_tests\7f99067
+Node: libannocheck_disable_all_tests\7f99546
+Node: libannocheck_enable_test\7f100102
+Node: libannocheck_disable_test\7f100770
+Node: libannocheck_enable_profile\7f101439
+Node: libannocheck_get_known_profiles\7f101961
+Node: libannocheck_run_tests\7f102664
+Node: Configure Options\7f103509
+Node: Legacy Scripts\7f105851
+Node: Who Built Me\7f106626
+Node: ABI Checking\7f109386
+Node: Hardening Checks\7f111502
+Node: Checking Archives\7f115588
+Node: GNU FDL\7f118009
 \1f
 End Tag Table
 
index e82336d773b4f80a3b1362b0b5bcfe6e63bb6afe..8136d05a8babe9c6cce76bc0dfbbe6a5e275f00e 100644 (file)
@@ -1836,14 +1836,24 @@ option and re-enabled via the @option{--test-run-path} option.
   Example:  FAIL: rwx-seg test because segment has Read, Write and eXecute flags set
 @end smallexample
 
-This test checks that the file does not have any segments that have
-all three of the @var{read}, @var{write} and @var{execute}
-permissions.  Code segments should have read and execute permissions,
-but they should not be writable as otherwise an attacker can
-overwrite the code.  Data segments should have read permission, and
-possibly write permission as well, but never execute permission 
-as otherwise an attacker might be able to create their own code in a
-data area. 
+This test checks that the file does not have any segments that are
+@enumerate
+@item
+have all three of the @var{read}, @var{write} and @var{execute}
+permissions.
+@item
+have a non-zero size
+@item
+are resident in memory when the program runs
+@item
+do not have an architecture/OS specific type
+@end enumerate
+
+Code segments should have read and execute permissions, but they
+should not be writable as otherwise an attacker can overwrite the
+code.  Data segments should have read permission, and possibly write
+permission as well, but never execute permission as otherwise an
+attacker might be able to create their own code in a data area. 
 
 The linker will normally never create a binary file with a segment
 with all three permissions, but it is possible to force it to do so by
This page took 0.043989 seconds and 5 git commands to generate.