Print this page
9642 PKCS#11 softtoken should use explicit_bzero
Reviewed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Alex Wilson <alex.wilson@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/pkcs11/pkcs11_softtoken/common/softDESCrypt.c
          +++ new/usr/src/lib/pkcs11/pkcs11_softtoken/common/softDESCrypt.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
       24 + * Copyright (c) 2018, Joyent, Inc.
  24   25   */
  25   26  
  26   27  #include <pthread.h>
  27   28  #include <stdlib.h>
  28   29  #include <string.h>
  29   30  #include <strings.h>
  30   31  #include <sys/types.h>
  31   32  #include <security/cryptoki.h>
  32   33  #include <modes/modes.h>
  33   34  #include <des_impl.h>
↓ open down ↓ 407 lines elided ↑ open up ↑
 441  442                  return (CKR_OK);
 442  443  
 443  444          /*
 444  445           * The following code will be executed if the caller is
 445  446           * soft_encrypt() or an error occurred. The encryption
 446  447           * operation will be terminated so we need to do some cleanup.
 447  448           */
 448  449  cleanup:
 449  450          (void) pthread_mutex_lock(&session_p->session_mutex);
 450  451          des_ctx = (des_ctx_t *)soft_des_ctx->des_cbc;
 451      -        if (des_ctx != NULL) {
 452      -                bzero(des_ctx->dc_keysched, des_ctx->dc_keysched_len);
 453      -                free(soft_des_ctx->des_cbc);
 454      -        }
 455      -
 456      -        bzero(soft_des_ctx->key_sched, soft_des_ctx->keysched_len);
 457      -        free(soft_des_ctx->key_sched);
 458      -        free(session_p->encrypt.context);
      452 +        free(des_ctx);
      453 +        freezero(soft_des_ctx->key_sched, soft_des_ctx->keysched_len);
      454 +        freezero(session_p->encrypt.context, sizeof (soft_des_ctx_t));
 459  455          session_p->encrypt.context = NULL;
 460  456          (void) pthread_mutex_unlock(&session_p->session_mutex);
 461  457  
 462  458          return (rv);
 463  459  }
 464  460  
 465  461  
 466  462  /*
 467  463   * soft_des_decrypt_common()
 468  464   *
↓ open down ↓ 301 lines elided ↑ open up ↑
 770  766                  return (CKR_OK);
 771  767  
 772  768          /*
 773  769           * The following code will be executed if the caller is
 774  770           * soft_decrypt() or an error occurred. The decryption
 775  771           * operation will be terminated so we need to do some cleanup.
 776  772           */
 777  773  cleanup:
 778  774          (void) pthread_mutex_lock(&session_p->session_mutex);
 779  775          des_ctx = (des_ctx_t *)soft_des_ctx->des_cbc;
 780      -        if (des_ctx != NULL) {
 781      -                bzero(des_ctx->dc_keysched, des_ctx->dc_keysched_len);
 782      -                free(soft_des_ctx->des_cbc);
 783      -        }
 784      -
 785      -        bzero(soft_des_ctx->key_sched, soft_des_ctx->keysched_len);
 786      -        free(soft_des_ctx->key_sched);
 787      -        free(session_p->decrypt.context);
 788      -        session_p->decrypt.context = NULL;
      776 +        free(des_ctx);
      777 +        freezero(soft_des_ctx->key_sched, soft_des_ctx->keysched_len);
      778 +        freezero(session_p->decrypt.context, sizeof (soft_des_ctx_t));
 789  779          (void) pthread_mutex_unlock(&session_p->session_mutex);
 790  780  
 791  781          return (rv);
 792  782  }
 793  783  
 794  784  
 795  785  /*
 796  786   * Allocate and initialize a context for DES CBC mode of operation.
 797  787   */
 798  788  void *
↓ open down ↓ 309 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX