Skip to content
  1. Jun 14, 2017
  2. Jun 13, 2017
  3. Jun 12, 2017
  4. Jun 10, 2017
  5. Jun 09, 2017
  6. Jun 08, 2017
  7. Jun 07, 2017
  8. Jun 05, 2017
  9. Jun 02, 2017
  10. Jun 01, 2017
  11. May 31, 2017
  12. May 30, 2017
  13. May 27, 2017
  14. May 26, 2017
  15. May 25, 2017
  16. May 24, 2017
  17. May 23, 2017
  18. May 22, 2017
    • Alex Gaynor's avatar
    • Todd Short's avatar
      Fix infinite loops in secure memory allocation. · ddcccb65
      Todd Short authored
      Remove assertion when mmap() fails.
      Only give the 1<<31 limit test as an example.
      
      Fix the small arena test to just check for the symptom of the infinite
      loop (i.e. initialized set on failure), rather than the actual infinite
      loop. This avoids some valgrind errors.
      
      Backport of:
      PR #3512 commit fee423bb
      PR #3510 commit a486561b
      PR #3455 commit c8e89d58
      PR #3449 commit 7031ddac
      
      
      
      Issue 1:
      
      sh.bittable_size is a size_t but i is and int, which can result in
      freelist == -1 if sh.bittable_size exceeds an int.
      
      This seems to result in an OPENSSL_assert due to invalid allocation
      size, so maybe that is "ok."
      
      Worse, if sh.bittable_size is exactly 1<<31, then this becomes an
      infinite loop (because 1<<31 is a negative int, so it can be shifted
      right forever and sticks at -1).
      
      Issue 2:
      
      CRYPTO_secure_malloc_init() sets secure_mem_initialized=1 even when
      sh_init() returns 0.
      
      If sh_init() fails, we end up with secure_mem_initialized=1 but
      sh.minsize=0. If you then call secure_malloc(), which then calls,
      sh_malloc(), this then enters an infite loop since 0 << anything will
      never be larger than size.
      
      Issue 3:
      
      That same sh_malloc loop will loop forever for a size greater
      than size_t/2 because i will proceed (assuming sh.minsize=16):
      i=16, 32, 64, ..., size_t/8, size_t/4, size_t/2, 0, 0, 0, 0, ....
      This sequence will never be larger than "size".
      
      Reviewed-by: default avatarAndy Polyakov <appro@openssl.org>
      Reviewed-by: default avatarRich Salz <rsalz@openssl.org>
      (Merged from https://github.com/openssl/openssl/pull/3453)
      ddcccb65