diff options
author | Jakub Jelinek <jakub@redhat.com> | 2005-07-29 16:56:26 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2005-07-29 16:56:26 +0000 |
commit | 979da19ab840553e3862f3b2aea50ad07118616f (patch) | |
tree | 150fffcd4616402c468e87600cf96568d7c34302 | |
parent | 1ce6c1300b11dcd825ee372b9354607f5069a6f1 (diff) | |
download | glibc-979da19ab840553e3862f3b2aea50ad07118616f.tar glibc-979da19ab840553e3862f3b2aea50ad07118616f.tar.gz glibc-979da19ab840553e3862f3b2aea50ad07118616f.tar.bz2 glibc-979da19ab840553e3862f3b2aea50ad07118616f.zip |
* 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.
nptl/
* tst-stackguard1.c (do_test): Don't fail if the poor man's
randomization doesn't work well enough.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | elf/tst-stackguard1.c | 8 | ||||
-rw-r--r-- | nptl/ChangeLog | 5 | ||||
-rw-r--r-- | nptl/tst-stackguard1.c | 8 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/dl-osinfo.h | 29 |
5 files changed, 57 insertions, 4 deletions
@@ -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>. diff --git a/elf/tst-stackguard1.c b/elf/tst-stackguard1.c index 480f9297d0..ed1b5687a2 100644 --- a/elf/tst-stackguard1.c +++ b/elf/tst-stackguard1.c @@ -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"); diff --git a/nptl/ChangeLog b/nptl/ChangeLog index 0128865672..38983a81d1 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -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] diff --git a/nptl/tst-stackguard1.c b/nptl/tst-stackguard1.c index 15c30aeb6b..d9bbe206c3 100644 --- a/nptl/tst-stackguard1.c +++ b/nptl/tst-stackguard1.c @@ -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"); diff --git a/sysdeps/unix/sysv/linux/dl-osinfo.h b/sysdeps/unix/sysv/linux/dl-osinfo.h index e374023841..fb885330f9 100644 --- a/sysdeps/unix/sysv/linux/dl-osinfo.h +++ b/sysdeps/unix/sysv/linux/dl-osinfo.h @@ -18,12 +18,15 @@ 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; } |