From: Jakub Jelinek Date: Fri, 29 Jul 2005 16:56:26 +0000 (+0000) Subject: * sysdeps/unix/sysv/dl-osinfo.h: Include errno.h, hp-timing.h, X-Git-Tag: cvs/fedora-glibc-2_3_90-7~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=979da19ab840553e3862f3b2aea50ad07118616f;p=thirdparty%2Fglibc.git * 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. --- diff --git a/ChangeLog b/ChangeLog index f68792c8f2e..e08224bbde7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-07-29 Jakub Jelinek + + * 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 * misc/error.c [_LIBC]: Include and . diff --git a/elf/tst-stackguard1.c b/elf/tst-stackguard1.c index 480f9297d02..ed1b5687a28 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 0128865672d..38983a81d1e 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,3 +1,8 @@ +2005-07-29 Jakub Jelinek + + * tst-stackguard1.c (do_test): Don't fail if the poor man's + randomization doesn't work well enough. + 2005-07-11 Jakub Jelinek [BZ #1102] diff --git a/nptl/tst-stackguard1.c b/nptl/tst-stackguard1.c index 15c30aeb6b3..d9bbe206c34 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 e374023841a..fb885330f94 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 +#include #include #include #include #include "kernel-features.h" #include #include +#include +#include #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; }