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/metaObjectManager.c
          +++ new/usr/src/lib/pkcs11/libpkcs11/common/metaObjectManager.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  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   * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
       23 + * Copyright (c) 2018, Joyent, Inc.
  23   24   */
  24   25  
  25   26  
  26   27  #include <stdlib.h>
  27   28  #include <string.h>
  28   29  #include <strings.h>
  29   30  #include <errno.h>
  30   31  #include <fcntl.h>
  31   32  #include <sys/types.h>
  32   33  #include <sys/stat.h>
↓ open down ↓ 556 lines elided ↑ open up ↑
 589  590          }
 590  591  
 591  592          /* Now erase and delete any attributes in the metaobject. */
 592  593          dealloc_attributes(object->attributes, object->num_attributes);
 593  594  
 594  595          free(object->clones);
 595  596          free(object->tried_create_clone);
 596  597  
 597  598          if (object->clone_template) {
 598  599                  for (i = 0; i < object->clone_template_size; i++) {
 599      -                        free(((object->clone_template)[i]).pValue);
      600 +                        freezero((object->clone_template)[i].pValue,
      601 +                            (object->clone_template)[i].ulValueLen);
 600  602                  }
 601  603                  free(object->clone_template);
 602  604          }
 603  605  
 604  606          /* Cleanup remaining object fields. */
 605  607          (void) pthread_rwlock_destroy(&object->object_lock);
 606  608          (void) pthread_rwlock_destroy(&object->attribute_lock);
 607  609          (void) pthread_mutex_destroy(&object->isClosingObject_lock);
 608  610          (void) pthread_mutex_destroy(&object->clone_create_lock);
 609  611  
↓ open down ↓ 242 lines elided ↑ open up ↑
 852  854                          if (attrs[i].pValue != NULL) {
 853  855                                  free(attrs[i].pValue);
 854  856                          }
 855  857                  }
 856  858                  free(attrs);
 857  859          }
 858  860  
 859  861          if (attrs_with_val) {
 860  862                  for (i = 0; i < num_attrs; i++) {
 861  863                          if (attrs_with_val[i].pValue != NULL) {
 862      -                                free(attrs_with_val[i].pValue);
      864 +                                freezero(attrs_with_val[i].pValue,
      865 +                                    attrs_with_val[i].ulValueLen);
 863  866                          }
 864  867                  }
 865  868                  free(attrs_with_val);
 866  869          }
 867  870          return (rv);
 868  871  }
 869  872  
 870  873  /*
 871  874   * Create an object to be used for wrapping and unwrapping.
 872  875   * The same template will be used for all wrapping/unwrapping keys all
↓ open down ↓ 611 lines elided ↑ open up ↑
1484 1487          if (tmp_meta_obj) {
1485 1488                  (void) meta_object_dealloc(tmp_meta_session, tmp_meta_obj,
1486 1489                      B_TRUE);
1487 1490          }
1488 1491  
1489 1492          if (tmp_meta_session) {
1490 1493                  (void) meta_session_dealloc(tmp_meta_session);
1491 1494          }
1492 1495  
1493 1496          if (wrappedKey) {
1494      -                free(wrappedKey);
     1497 +                freezero(wrappedKey, wrappedKeyLen);
1495 1498          }
1496 1499  
1497 1500          if (src_slot_session) {
1498 1501                  meta_release_slot_session(src_slot_session);
1499 1502          }
1500 1503  
1501 1504          return (rv);
1502 1505  
1503 1506  }
1504 1507  
↓ open down ↓ 671 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX