Print this page
9644 Double-free in crypto tests on failure
Reviewed by: Dan McDonald <danmcd@joyent.com>
Reviewed by: Mike Zeller <mike.zeller@joyent.com>
   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.

  14  */
  15 
  16 #include <fcntl.h>
  17 #include <strings.h>
  18 #include <unistd.h>
  19 #include <errno.h>
  20 #include <stdio.h>
  21 #include <stdlib.h>
  22 
  23 #include "cryptotest.h"
  24 
  25 struct crypto_op {
  26         char *in;
  27         char *out;
  28         char *key;
  29         char *param;
  30 
  31         size_t inlen;
  32         size_t outlen;
  33         size_t keylen;


 117         free(op);
 118         if (fd >= 0)
 119                 return (close(fd));
 120         return (0);
 121 }
 122 
 123 int
 124 get_mech_info(crypto_op_t *op)
 125 {
 126         crypto_get_mechanism_number_t get_number;
 127 
 128         bzero(&get_number, sizeof (get_number));
 129 
 130         get_number.pn_mechanism_string = op->mechname;
 131         get_number.pn_mechanism_len = strlen(op->mechname) + 1;
 132 
 133         if (kcf_do_ioctl(CRYPTO_GET_MECHANISM_NUMBER,
 134             (uint_t *)&get_number, "get_mech_info") != CRYPTO_SUCCESS) {
 135                 (void) fprintf(stderr, "failed to resolve mechanism name %s\n",
 136                     op->mechname);
 137                 (void) cryptotest_close(op);
 138                 return (CTEST_NAME_RESOLVE_FAILED);
 139         }
 140         op->mech = get_number.pn_internal_number;
 141         return (CRYPTO_SUCCESS);
 142 }
 143 
 144 int
 145 get_hsession_by_mech(crypto_op_t *op)
 146 {
 147         crypto_by_mech_t mech;
 148         int rv;
 149 
 150         mech.mech_keylen = op->keylen;
 151         mech.mech_type = op->mech;
 152         mech.mech_fg = op->fg;
 153 
 154         rv = kcf_do_ioctl(CRYPTO_GET_PROVIDER_BY_MECH, (uint_t *)&mech,
 155             "get_hsession_by_mech");
 156 
 157         if (rv != 0 || mech.rv != CRYPTO_SUCCESS) {
 158                 (void) fprintf(stderr,
 159                     "could not find provider for mechanism %llu\n",
 160                     mech.mech_type);
 161                 (void) cryptotest_close(op);
 162                 return (CTEST_MECH_NO_PROVIDER);
 163         }
 164 
 165         op->hsession = mech.session_id;
 166 
 167         return (CRYPTO_SUCCESS);
 168 }
 169 
 170 /*
 171  * CRYPTO_MAC_* functions
 172  */
 173 int
 174 mac_init(crypto_op_t *op)
 175 {
 176         crypto_mac_init_t init;
 177 
 178         bzero((void *)&init, sizeof (init));
 179 
 180         init.mi_session = op->hsession;
 181 


   1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  14  * Copyright 2018, Joyent, Inc.
  15  */
  16 
  17 #include <fcntl.h>
  18 #include <strings.h>
  19 #include <unistd.h>
  20 #include <errno.h>
  21 #include <stdio.h>
  22 #include <stdlib.h>
  23 
  24 #include "cryptotest.h"
  25 
  26 struct crypto_op {
  27         char *in;
  28         char *out;
  29         char *key;
  30         char *param;
  31 
  32         size_t inlen;
  33         size_t outlen;
  34         size_t keylen;


 118         free(op);
 119         if (fd >= 0)
 120                 return (close(fd));
 121         return (0);
 122 }
 123 
 124 int
 125 get_mech_info(crypto_op_t *op)
 126 {
 127         crypto_get_mechanism_number_t get_number;
 128 
 129         bzero(&get_number, sizeof (get_number));
 130 
 131         get_number.pn_mechanism_string = op->mechname;
 132         get_number.pn_mechanism_len = strlen(op->mechname) + 1;
 133 
 134         if (kcf_do_ioctl(CRYPTO_GET_MECHANISM_NUMBER,
 135             (uint_t *)&get_number, "get_mech_info") != CRYPTO_SUCCESS) {
 136                 (void) fprintf(stderr, "failed to resolve mechanism name %s\n",
 137                     op->mechname);

 138                 return (CTEST_NAME_RESOLVE_FAILED);
 139         }
 140         op->mech = get_number.pn_internal_number;
 141         return (CRYPTO_SUCCESS);
 142 }
 143 
 144 int
 145 get_hsession_by_mech(crypto_op_t *op)
 146 {
 147         crypto_by_mech_t mech;
 148         int rv;
 149 
 150         mech.mech_keylen = op->keylen;
 151         mech.mech_type = op->mech;
 152         mech.mech_fg = op->fg;
 153 
 154         rv = kcf_do_ioctl(CRYPTO_GET_PROVIDER_BY_MECH, (uint_t *)&mech,
 155             "get_hsession_by_mech");
 156 
 157         if (rv != 0 || mech.rv != CRYPTO_SUCCESS) {
 158                 (void) fprintf(stderr,
 159                     "could not find provider for mechanism %llu\n",
 160                     mech.mech_type);

 161                 return (CTEST_MECH_NO_PROVIDER);
 162         }
 163 
 164         op->hsession = mech.session_id;
 165 
 166         return (CRYPTO_SUCCESS);
 167 }
 168 
 169 /*
 170  * CRYPTO_MAC_* functions
 171  */
 172 int
 173 mac_init(crypto_op_t *op)
 174 {
 175         crypto_mac_init_t init;
 176 
 177         bzero((void *)&init, sizeof (init));
 178 
 179         init.mi_session = op->hsession;
 180