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_kernel/common/kernelSoftCommon.c
          +++ new/usr/src/lib/pkcs11/pkcs11_kernel/common/kernelSoftCommon.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  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 2007 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
       25 + * Copyright (c) 2018, Joyent, Inc.
  25   26   */
  26   27  
  27      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  28      -
  29   28  #include <pthread.h>
  30   29  #include <errno.h>
  31   30  #include <stdio.h>
  32   31  #include <strings.h>
  33   32  #include <sys/crypto/ioctl.h>
  34   33  #include <security/cryptoki.h>
  35   34  #include <security/pkcs11t.h>
  36   35  #include "softSession.h"
  37   36  #include "softObject.h"
  38   37  #include "softOps.h"
↓ open down ↓ 188 lines elided ↑ open up ↑
 227  226  void
 228  227  free_soft_ctx(void *s, int opflag)
 229  228  {
 230  229          soft_session_t *session_p;
 231  230  
 232  231          session_p = (soft_session_t *)s;
 233  232          if (session_p == NULL)
 234  233                  return;
 235  234  
 236  235          if (opflag & OP_SIGN) {
 237      -                if (session_p->sign.context == NULL)
 238      -                        return;
 239      -                bzero(session_p->sign.context, sizeof (soft_hmac_ctx_t));
 240      -                free(session_p->sign.context);
      236 +                freezero(session_p->sign.context,
      237 +                    sizeof (soft_hmac_ctx_t));
 241  238                  session_p->sign.context = NULL;
 242  239                  session_p->sign.flags = 0;
 243  240          } else if (opflag & OP_VERIFY) {
 244      -                if (session_p->verify.context == NULL)
 245      -                        return;
 246      -                bzero(session_p->verify.context, sizeof (soft_hmac_ctx_t));
 247      -                free(session_p->verify.context);
      241 +                freezero(session_p->verify.context,
      242 +                    sizeof (soft_hmac_ctx_t));
 248  243                  session_p->verify.context = NULL;
 249  244                  session_p->verify.flags = 0;
 250  245          } else {
 251      -                if (session_p->digest.context == NULL)
 252      -                        return;
 253  246                  free(session_p->digest.context);
 254  247                  session_p->digest.context = NULL;
 255  248                  session_p->digest.flags = 0;
 256  249          }
 257  250  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX