summaryrefslogtreecommitdiff
path: root/src/misc.c
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@iki.fi>2013-10-02 20:47:56 +0300
committerJussi Kivilinna <jussi.kivilinna@iki.fi>2013-10-10 15:51:09 +0300
commit150c0313f971bcea62d2802f0389c883e11ebb31 (patch)
tree098296cd6558d7096aea7ad4f8f45c1f1545fafa /src/misc.c
parent94b652ecb006c29fa2ffb1badc9f02b758581737 (diff)
downloadlibgcrypt-150c0313f971bcea62d2802f0389c883e11ebb31.tar.gz
Prevent tail call optimization with _gcry_burn_stack
* configure.ac: New check, HAVE_GCC_ASM_VOLATILE_MEMORY. * src/g10lib.h (_gcry_burn_stack): Rename to __gcry_burn_stack. (__gcry_burn_stack_dummy): New. (_gcry_burn_stack): New macro. * src/misc.c (_gcry_burn_stack): Rename to __gcry_burn_stack. (__gcry_burn_stack_dummy): New. -- Tail call optimization can turn _gcry_burn_stack call in to tail jump. When this happens, stack pointer is restored to initial state of current function. This causes problem for _gcry_burn_stack because its callers do not count in current function stack depth. One solution is to prevent gcry_burn_stack being tail optimized by inserting dummy function call behind it. Another would be to add memory barrier 'asm volatile("":::"memory")' behind every _gcry_burn_stack call. This however requires GCC asm support from compiler. Patch adds detection for memory barrier support and when available uses memory barrier to prevent when tail call optimization. If not available dummy function call is used instead. Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'src/misc.c')
-rw-r--r--src/misc.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/misc.c b/src/misc.c
index 912039a5..9b30ac3d 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -438,7 +438,7 @@ _gcry_log_printsxp (const char *text, gcry_sexp_t sexp)
void
-_gcry_burn_stack (unsigned int bytes)
+__gcry_burn_stack (unsigned int bytes)
{
#ifdef HAVE_VLA
/* (bytes == 0 ? 1 : bytes) == (!bytes + bytes) */
@@ -456,6 +456,13 @@ _gcry_burn_stack (unsigned int bytes)
#endif
}
+#ifndef HAVE_GCC_ASM_VOLATILE_MEMORY
+void
+__gcry_burn_stack_dummy (void)
+{
+}
+#endif
+
void
_gcry_divide_by_zero (void)
{