[git] GCRYPT - branch, master, updated. libgcrypt-1.5.0-294-gd3fa0bc

by Jussi Kivilinna cvs at cvs.gnupg.org
Wed Oct 2 20:21:27 CEST 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU crypto library".

The branch, master has been updated
       via  d3fa0bcf62bdb77b70fc96034d86b9f76ba4d4c1 (commit)
      from  99810404bee86aa55822740ea5ae670848074856 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d3fa0bcf62bdb77b70fc96034d86b9f76ba4d4c1
Author: Jussi Kivilinna <jussi.kivilinna at iki.fi>
Date:   Wed Oct 2 20:47:56 2013 +0300

    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 at iki.fi>

diff --git a/configure.ac b/configure.ac
index 2c92028..1460dfd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -921,7 +921,7 @@ fi
 
 #
 # Check whether the compiler supports 'asm' or '__asm__' keyword for
-# assembler blocks
+# assembler blocks.
 #
 AC_CACHE_CHECK([whether 'asm' assembler keyword is supported],
        [gcry_cv_have_asm],
@@ -945,6 +945,32 @@ fi
 
 
 #
+# Check whether the compiler supports inline assembly memory barrier.
+#
+if test "$gcry_cv_have_asm" = "no" ; then
+   if test "$gcry_cv_have___asm__" = "yes" ; then
+      AC_CACHE_CHECK([whether inline assembly memory barrier is supported],
+          [gcry_cv_have_asm_volatile_memory],
+          [gcry_cv_have_asm_volatile_memory=no
+           AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+             [[void a(void) { __asm__ volatile("":::"memory"); }]])],
+             [gcry_cv_have_asm_volatile_memory=yes])])
+   fi
+else
+   AC_CACHE_CHECK([whether inline assembly memory barrier is supported],
+       [gcry_cv_have_asm_volatile_memory],
+       [gcry_cv_have_asm_volatile_memory=no
+        AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+          [[void a(void) { asm volatile("":::"memory"); }]])],
+          [gcry_cv_have_asm_volatile_memory=yes])])
+fi
+if test "$gcry_cv_have_asm_volatile_memory" = "yes" ; then
+   AC_DEFINE(HAVE_GCC_ASM_VOLATILE_MEMORY,1,
+     [Define if inline asm memory barrier is supported])
+fi
+
+
+#
 # Check whether GCC inline assembler supports SSSE3 instructions
 # This is required for the AES-NI instructions.
 #
diff --git a/src/g10lib.h b/src/g10lib.h
index 43281ad..85bd93b 100644
--- a/src/g10lib.h
+++ b/src/g10lib.h
@@ -254,7 +254,16 @@ int strcasecmp (const char *a, const char *b) _GCRY_GCC_ATTR_PURE;
 
 /* Stack burning.  */
 
-void _gcry_burn_stack (unsigned int bytes);
+#ifdef HAVE_GCC_ASM_VOLATILE_MEMORY
+#define  __gcry_burn_stack_dummy() asm volatile ("":::"memory")
+#else
+void __gcry_burn_stack_dummy (void);
+#endif
+
+void __gcry_burn_stack (unsigned int bytes);
+#define _gcry_burn_stack(bytes) \
+	do { __gcry_burn_stack (bytes); \
+	     __gcry_burn_stack_dummy (); } while(0)
 
 
 /* To avoid that a compiler optimizes certain memset calls away, these
diff --git a/src/misc.c b/src/misc.c
index 912039a..9b30ac3 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)
 {

-----------------------------------------------------------------------

Summary of changes:
 configure.ac |   28 +++++++++++++++++++++++++++-
 src/g10lib.h |   11 ++++++++++-
 src/misc.c   |    9 ++++++++-
 3 files changed, 45 insertions(+), 3 deletions(-)


hooks/post-receive
-- 
The GNU crypto library
http://git.gnupg.org




More information about the Gnupg-commits mailing list