From: Maxim Ostapenko Date: Fri, 10 Jun 2016 12:57:14 +0000 (+0000) Subject: re PR sanitizer/71480 (ASan should align string constants to shadow granularity.) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7cfa10f33c57e7de87517360e42700bbfc97ef58;p=gcc.git re PR sanitizer/71480 (ASan should align string constants to shadow granularity.) 2016-06-10 Maxim Ostapenko PR sanitizer/71480 * varasm.c (place_block_symbol): Adjust alignment for asan protected STRING_CSTs even if TREE_CONSTANT_POOL_ADDRESS_P. * c-c++-common/asan/pr71480.c: New test. From-SVN: r237306 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 954adf37947..73ba814f135 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-06-10 Maxim Ostapenko + + PR sanitizer/71480 + * varasm.c (place_block_symbol): Adjust alignment for asan protected + STRING_CSTs even if TREE_CONSTANT_POOL_ADDRESS_P. + 2016-06-10 Jan Hubicka * profile.c: Include cfgloop.h. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2e640a5b189..19f37934023 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-06-10 Maxim Ostapenko + + PR sanitizer/71480 + * c-c++-common/asan/pr71480.c: New test. + 2016-06-10 H.J. Lu * gcc.dg/guality/pr68037-1.c (ASMNAME): New. diff --git a/gcc/testsuite/c-c++-common/asan/pr71480.c b/gcc/testsuite/c-c++-common/asan/pr71480.c new file mode 100644 index 00000000000..c23ea5385b4 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/pr71480.c @@ -0,0 +1,42 @@ +/* { dg-do run } */ + +__attribute__ ((noinline, noclone)) int +foo (char *c) +{ + asm volatile ("" : : "r" (c) : "memory"); + return 1; +} + +__attribute__ ((noinline, noclone)) void +bar (char *c) +{ + asm volatile ("" : : "r" (c) : "memory"); +} + +int main () +{ + char tpl[20] = "/tmp/test.XXXXXX"; + char tpl2[20] = "/tmp/test.XXXXXX"; + int fd = foo (tpl); + int fd2 = foo (tpl2); + if (fd == -1) + { + if (fd2 != -1) + bar (tpl2); + return 1; + } + + if (fd2 == -1) + return 1; + + bar (tpl); + bar (tpl2); + + if (__builtin_strcmp (tpl, "/tmp/test.XXXXXX") != 0) + return 1; + + if (__builtin_strcmp (tpl, tpl2) != 0) + return 1; + + return 0; +} diff --git a/gcc/varasm.c b/gcc/varasm.c index 4a7124e73be..de8bcd6f20c 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -7201,7 +7201,11 @@ place_block_symbol (rtx symbol) if ((flag_sanitize & SANITIZE_ADDRESS) && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST && asan_protect_global (DECL_INITIAL (decl))) - size += asan_red_zone_size (size); + { + size += asan_red_zone_size (size); + alignment = MAX (alignment, + ASAN_RED_ZONE_SIZE * BITS_PER_UNIT); + } } else {