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/libpkcs11/common/metaAttrManager.c
          +++ new/usr/src/lib/pkcs11/libpkcs11/common/metaAttrManager.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   * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   * Copyright 2012 Milan Jurik. All rights reserved.
       25 + * Copyright (c) 2018, Joyent, Inc.
  25   26   */
  26   27  
  27   28  #include <string.h>
  28   29  #include <stdlib.h>
  29   30  #include <strings.h>
  30   31  #include "metaGlobal.h"
  31   32  #include "metaAttrMasters.h"
  32   33  
  33   34  static void
  34   35  find_attribute(CK_ATTRIBUTE_TYPE attrtype, generic_attr_t *attributes,
↓ open down ↓ 484 lines elided ↑ open up ↑
 519  520  
 520  521          for (i = 0; i < num_attributes; i++) {
 521  522                  attr = attributes + i;
 522  523  
 523  524                  /*
 524  525                   * Zero-out any attribute values. We could do this just for
 525  526                   * attributes with isSensitive == True, but it's not much
 526  527                   * extra work to just do them all. [Most attributes are just
 527  528                   * 1 or 4 bytes]
 528  529                   */
 529      -                bzero(attr->attribute.pValue, attr->attribute.ulValueLen);
      530 +                explicit_bzero(attr->attribute.pValue,
      531 +                    attr->attribute.ulValueLen);
 530  532  
 531  533                  if (attr->isMalloced)
 532  534                          free(attr->attribute.pValue);
 533  535          }
 534  536  
 535  537          free(attributes);
 536  538  }
 537  539  
 538  540  
 539  541  /*
↓ open down ↓ 17 lines elided ↑ open up ↑
 557  559          find_attribute(new_attr->type, attributes, num_attributes, &attr);
 558  560          if (attr == NULL) {
 559  561                  return (CKR_ATTRIBUTE_TYPE_INVALID);
 560  562          }
 561  563  
 562  564          /* Store the new value. */
 563  565          if (attr->attribute.ulValueLen >= new_attr->ulValueLen) {
 564  566                  /* Existing storage is sufficient to store new value. */
 565  567  
 566  568                  /* bzero() out any data that won't be overwritten. */
 567      -                bzero((char *)attr->attribute.pValue + new_attr->ulValueLen,
      569 +                explicit_bzero((char *)attr->attribute.pValue +
      570 +                    new_attr->ulValueLen,
 568  571                      attr->attribute.ulValueLen - new_attr->ulValueLen);
 569  572  
 570  573          } else if (new_attr->ulValueLen <= sizeof (attr->generic_data)) {
 571  574                  /* Use generic storage to avoid a malloc. */
 572  575  
 573      -                bzero(attr->attribute.pValue, attr->attribute.ulValueLen);
      576 +                explicit_bzero(attr->attribute.pValue,
      577 +                    attr->attribute.ulValueLen);
 574  578                  if (attr->isMalloced) {
 575  579                          /*
 576  580                           * If app sets a large value (triggering a malloc),
 577  581                           * then sets a tiny value, and finally again sets
 578  582                           * a large value (phew!) we could end up here.
 579  583                           *
 580  584                           * FUTURE?: Store the original malloc size, so that
 581  585                           * we can regrow the value up to the original size.
 582  586                           * This might avoid some heap churn for pathalogic
 583  587                           * applications.
↓ open down ↓ 142 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX