]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
* sysdeps/unix/sysv/dl-osinfo.h: Include errno.h, hp-timing.h,
authorJakub Jelinek <jakub@redhat.com>
Fri, 29 Jul 2005 16:56:26 +0000 (16:56 +0000)
committerJakub Jelinek <jakub@redhat.com>
Fri, 29 Jul 2005 16:56:26 +0000 (16:56 +0000)
endian.h.
(_dl_setup_stack_chk_guard): Even without
--enable-stackguard-randomization attempt to do some guard
randomization using hp-timing (if available) and kernel stack and
mmap randomization.
* elf/tst-stackguard1.c (do_test): Don't fail if the poor man's
randomization doesn't work well enough.
nptl/
* tst-stackguard1.c (do_test): Don't fail if the poor man's
randomization doesn't work well enough.

ChangeLog
elf/tst-stackguard1.c
nptl/ChangeLog
nptl/tst-stackguard1.c
sysdeps/unix/sysv/linux/dl-osinfo.h

index f68792c8f2e0fcf5e45404f5fcf8526a2e213d2a..e08224bbde75cc2df43a48f13c27d794cd911481 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2005-07-29  Jakub Jelinek  <jakub@redhat.com>
+
+       * sysdeps/unix/sysv/dl-osinfo.h: Include errno.h, hp-timing.h,
+       endian.h.
+       (_dl_setup_stack_chk_guard): Even without
+       --enable-stackguard-randomization attempt to do some guard
+       randomization using hp-timing (if available) and kernel stack and
+       mmap randomization.
+       * elf/tst-stackguard1.c (do_test): Don't fail if the poor man's
+       randomization doesn't work well enough.
+
 2005-07-28  Thomas Schwinge  <schwinge@nic-nac-project.de>
 
        * misc/error.c [_LIBC]: Include <stdbool.h> and <stdint.h>.
index 480f9297d02389cdda4d94d459ef529bb3599651..ed1b5687a2801173cc47748f68732d604fb8d2d0 100644 (file)
@@ -160,17 +160,21 @@ do_test (void)
      the 16 runs, something is very wrong.  */
   int ndifferences = 0;
   int ndefaults = 0;
+  int npartlyrandomized = 0;
   for (i = 0; i < N; ++i) 
     {
       if (child_stack_chk_guards[i] != child_stack_chk_guards[i+1])
        ndifferences++;
       else if (child_stack_chk_guards[i] == default_guard)
        ndefaults++;
+      else if (*(char *) &child_stack_chk_guards[i] == 0)
+       npartlyrandomized = 0;
     }
 
-  printf ("differences %d defaults %d\n", ndifferences, ndefaults);
+  printf ("differences %d defaults %d partly randomized %d\n",
+         ndifferences, ndefaults, npartlyrandomized);
 
-  if (ndifferences < N / 2 && ndefaults < N / 2)
+  if ((ndifferences + ndefaults + npartlyrandomized) < 3 * N / 4)
     {
       puts ("stack guard canaries are not randomized enough");
       puts ("nor equal to the default canary value");
index 0128865672d65991d3844072ba5a26a97378cd9d..38983a81d1e0bb17585665a2a7a5df6996deba4b 100644 (file)
@@ -1,3 +1,8 @@
+2005-07-29  Jakub Jelinek  <jakub@redhat.com>
+
+       * tst-stackguard1.c (do_test): Don't fail if the poor man's
+       randomization doesn't work well enough.
+
 2005-07-11  Jakub Jelinek  <jakub@redhat.com>
 
        [BZ #1102]
index 15c30aeb6b300e8299736922530dbe224b2b5e3f..d9bbe206c34d1d9cf62a0bb6203f3deac74073b4 100644 (file)
@@ -190,17 +190,21 @@ do_test (void)
      the 16 runs, something is very wrong.  */
   int ndifferences = 0;
   int ndefaults = 0;
+  int npartlyrandomized = 0;
   for (i = 0; i < N; ++i) 
     {
       if (child_stack_chk_guards[i] != child_stack_chk_guards[i+1])
        ndifferences++;
       else if (child_stack_chk_guards[i] == default_guard)
        ndefaults++;
+      else if (*(char *) &child_stack_chk_guards[i] == 0)
+       npartlyrandomized = 0;
     }
 
-  printf ("differences %d defaults %d\n", ndifferences, ndefaults);
+  printf ("differences %d defaults %d partly randomized %d\n",
+         ndifferences, ndefaults, npartlyrandomized);
 
-  if (ndifferences < N / 2 && ndefaults < N / 2)
+  if ((ndifferences + ndefaults + npartlyrandomized) < 3 * N / 4)
     {
       puts ("stack guard canaries are not randomized enough");
       puts ("nor equal to the default canary value");
index e374023841a629e45855141ced6e346ffb15e2aa..fb885330f94d24b4424be8818400e6ab57e3dcc4 100644 (file)
    02111-1307 USA.  */
 
 #include <string.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <sys/sysctl.h>
 #include <sys/utsname.h>
 #include "kernel-features.h"
 #include <dl-sysdep.h>
 #include <stdint.h>
+#include <hp-timing.h>
+#include <endian.h>
 
 #ifndef MIN
 # define MIN(a,b) (((a)<(b))?(a):(b))
@@ -177,5 +180,31 @@ _dl_setup_stack_chk_guard (void)
   unsigned char *p = (unsigned char *) &ret;
   p[sizeof (ret) - 1] = 255;
   p[sizeof (ret) - 2] = '\n';
+#ifdef HP_TIMING_NOW
+  hp_timing_t hpt;
+  HP_TIMING_NOW (hpt);
+  hpt = (hpt & 0xffff) << 8;
+  ret ^= hpt;
+#endif
+  uintptr_t stk;
+  /* Avoid GCC being too smart.  */
+  asm ("" : "=r" (stk) : "r" (p));
+  stk &= 0x7ffff0;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+  stk <<= (__WORDSIZE - 23);
+#elif __WORDSIZE == 64
+  stk <<= 31;
+#endif
+  ret ^= stk;
+  /* Avoid GCC being too smart.  */
+  p = (unsigned char *) &errno;
+  asm ("" : "=r" (stk) : "r" (p));
+  stk &= 0x7fff00;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+  stk <<= (__WORDSIZE - 29);
+#else
+  stk <<= (__WORDSIZE == 64 ? 24 : 5);
+#endif
+  ret ^= stk;
   return ret;
 }