]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
shred: use explicit_bzero
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 20 Jul 2017 21:01:14 +0000 (14:01 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 20 Jul 2017 21:02:47 +0000 (14:02 -0700)
* NEWS: Document this.
* bootstrap.conf (gnulib_modules): Add explicit_bzero.
* gl/lib/randint.c (randint_free):
* gl/lib/randread.c (randread_free):
* src/blake2/blake2-impl.h (secure_zero_memory):
* src/shred.c (dopass, do_wipefd):
Prefer explicit_bzero to memset when erasing secrets.

NEWS
bootstrap.conf
gl/lib/randint.c
gl/lib/randread.c
src/blake2/blake2-impl.h
src/shred.c

diff --git a/NEWS b/NEWS
index 110229bd8e020e30ff7f290422efaa3883401ee4..dfd2837a070e732401ba266819b5e01f32344a28 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   Now, it prints a diagnostic or a line to stdout for each argument.
   [bug introduced in the bourne-shell-to-C rewrite for coreutils-6.11]
 
+  shred now erases buffers containing secrets via the explicit_bzero
+  function, which should be more reliable.
+  [potential bug has always been present in 'shred']
+
   split no longer exits when invocations of a --filter return EPIPE.
   [bug introduced in coreutils-8.26]
 
index 4db77a3d781d8a6c6440e5ccf550d2a76c6604e7..9064a94bbfdb60582d2872e386fc1bc5d02346d7 100644 (file)
@@ -69,6 +69,7 @@ gnulib_modules="
   euidaccess
   exclude
   exitfail
+  explicit_bzero
   faccessat
   fadvise
   fchdir
index 4561067e848ece935c560c867c79a3ef34421094..b15982f463a7dd9768caed9ee5c5c5a86487ed30 100644 (file)
@@ -198,7 +198,7 @@ randint_genmax (struct randint_source *s, randint genmax)
 void
 randint_free (struct randint_source *s)
 {
-  memset (s, 0, sizeof *s);
+  explicit_bzero (s, sizeof *s);
   free (s);
 }
 
index 9c70a18752d9ffec4f5c6b6970de58bbce389c71..834f8446ab13e270076b7f198282f37599c549a7 100644 (file)
@@ -341,7 +341,7 @@ int
 randread_free (struct randread_source *s)
 {
   FILE *source = s->source;
-  memset (s, 0, sizeof *s);
+  explicit_bzero (s, sizeof *s);
   free (s);
   return (source ? fclose (source) : 0);
 }
index 5dff7fc7a3d836360b5fed69993a8b44ff100f6f..241e5abf5c1871bb25a890d0ec1b32cec7c52958 100644 (file)
@@ -153,8 +153,7 @@ static BLAKE2_INLINE uint64_t rotr64( const uint64_t w, const unsigned c )
 /* prevents compiler optimizing out memset() */
 static BLAKE2_INLINE void secure_zero_memory(void *v, size_t n)
 {
-  static void *(*const volatile memset_v)(void *, int, size_t) = &memset;
-  memset_v(v, 0, n);
+  explicit_bzero (v, n);
 }
 
 #endif
index 7926e7aa42a85363a3b336778bbaf15c9cefdb11..c95546cb7adec8e5f3971aee9507e766ef3e9a22 100644 (file)
@@ -653,7 +653,7 @@ dopass (int fd, struct stat const *st, char const *qname, off_t *sizep,
     }
 
 free_pattern_mem:
-  memset (pbuf, 0, FILLPATTERN_SIZE);
+  explicit_bzero (pbuf, FILLPATTERN_SIZE);
   free (fill_pattern_mem);
 
   return other_error ? -1 : write_error;
@@ -987,7 +987,7 @@ do_wipefd (int fd, char const *qname, struct randint_source *s,
     }
 
 wipefd_out:
-  memset (passarray, 0, flags->n_iterations * sizeof (int));
+  explicit_bzero (passarray, flags->n_iterations * sizeof (int));
   free (passarray);
   return ok;
 }