krb5 commit: Avoid allocating a register in zap() assembly

Greg Hudson ghudson at mit.edu
Mon Jan 14 11:33:26 EST 2019


https://github.com/krb5/krb5/commit/7391e8b541061d0f584193b4a53365b64364b0e8
commit 7391e8b541061d0f584193b4a53365b64364b0e8
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Jan 3 17:19:32 2019 +0100

    Avoid allocating a register in zap() assembly
    
    See https://bugs.llvm.org/show_bug.cgi?id=15495
    
    Also add explicit_bzero() (glibc, FreeBSD) and explicit_memset()
    (NetBSD) as alternatives.
    
    [ghudson at mit.edu: added explicit_bzero() and explicit_memset()]

 src/configure.in          |    2 +-
 src/include/k5-platform.h |    6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/configure.in b/src/configure.in
index 61ef738..54cf107 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -421,7 +421,7 @@ AC_PROG_LEX
 AC_C_CONST
 AC_HEADER_DIRENT
 AC_FUNC_STRERROR_R
-AC_CHECK_FUNCS(strdup setvbuf seteuid setresuid setreuid setegid setresgid setregid setsid flock fchmod chmod strptime geteuid setenv unsetenv getenv gmtime_r localtime_r bswap16 bswap64 mkstemp getusershell access getcwd srand48 srand srandom stat strchr strerror timegm)
+AC_CHECK_FUNCS(strdup setvbuf seteuid setresuid setreuid setegid setresgid setregid setsid flock fchmod chmod strptime geteuid setenv unsetenv getenv gmtime_r localtime_r bswap16 bswap64 mkstemp getusershell access getcwd srand48 srand srandom stat strchr strerror timegm explicit_bzero explicit_memset)
 
 AC_CHECK_FUNC(mkstemp,
 [MKSTEMP_ST_OBJ=
diff --git a/src/include/k5-platform.h b/src/include/k5-platform.h
index 997b655..1fcd68e 100644
--- a/src/include/k5-platform.h
+++ b/src/include/k5-platform.h
@@ -1023,6 +1023,10 @@ static inline void zap(void *ptr, size_t len)
     if (len > 0)
         memset_s(ptr, len, 0, len);
 }
+#elif defined(HAVE_EXPLICIT_BZERO)
+# define zap(ptr, len) explicit_bzero(ptr, len)
+#elif defined(HAVE_EXPLICIT_MEMSET)
+# define zap(ptr, len) explicit_memset(ptr, 0, len)
 #elif defined(__GNUC__) || defined(__clang__)
 /*
  * Use an asm statement which declares a memory clobber to force the memset to
@@ -1032,7 +1036,7 @@ static inline void zap(void *ptr, size_t len)
 {
     if (len > 0)
         memset(ptr, 0, len);
-    __asm__ __volatile__("" : : "r" (ptr) : "memory");
+    __asm__ __volatile__("" : : "g" (ptr) : "memory");
 }
 #else
 /*


More information about the cvs-krb5 mailing list