Print this page
    
10132 smatch fixes for MDB
Reviewed by: Andy Fiddaman <andy@omniosce.org>
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/cmd/mdb/common/modules/crypto/spi.c
          +++ new/usr/src/cmd/mdb/common/modules/crypto/spi.c
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License (the "License").
   6    6   * You may not use this file except in compliance with the License.
   7    7   *
   8    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9    9   * or http://www.opensolaris.org/os/licensing.
  10   10   * See the License for the specific language governing permissions
  11   11   * and limitations under the License.
  12   12   *
  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
  
    | 
      ↓ open down ↓ | 
    16 lines elided | 
    
      ↑ open up ↑ | 
  
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  
  26   26  /*
       27 + * Copyright (c) 2018, Joyent, Inc.
       28 + */
       29 +
       30 +/*
  27   31   * mdb dcmds for selected structures from
  28   32   * usr/src/uts/common/sys/crypto/spi.h
  29   33   *
  30   34   * Also the mdb module housekeeping
  31   35   */
  32   36  
  33   37  #include <sys/mdb_modapi.h>
  34   38  #include <sys/modctl.h>
  35   39  #include <sys/crypto/api.h>
  36   40  #include <sys/crypto/common.h>
  37   41  #include <sys/crypto/spi.h>
  38   42  #include <sys/crypto/impl.h>
  39   43  #include "crypto_cmds.h"
  40   44  
  41   45  
  42   46  const mdb_bitmask_t extf_flags[] = {
  43   47          { "NIL", (ulong_t)-1, 0L },
  44   48          { "CRYPTO_EXTF_RNG", CRYPTO_EXTF_RNG, CRYPTO_EXTF_RNG },
  45   49          { "CRYPTO_EXTF_WRITE_PROTECTED", CRYPTO_EXTF_WRITE_PROTECTED,
  46   50                  CRYPTO_EXTF_WRITE_PROTECTED },
  47   51          { "CRYPTO_EXTF_LOGIN_REQUIRED", CRYPTO_EXTF_LOGIN_REQUIRED,
  48   52                  CRYPTO_EXTF_LOGIN_REQUIRED },
  49   53          { "CRYPTO_EXTF_USER_PIN_INITIALIZED", CRYPTO_EXTF_USER_PIN_INITIALIZED,
  50   54                  CRYPTO_EXTF_USER_PIN_INITIALIZED },
  51   55          { "CRYPTO_EXTF_CLOCK_ON_TOKEN", CRYPTO_EXTF_CLOCK_ON_TOKEN,
  52   56                  CRYPTO_EXTF_CLOCK_ON_TOKEN },
  53   57          { "CRYPTO_EXTF_PROTECTED_AUTHENTICATION_PATH",
  54   58                  CRYPTO_EXTF_PROTECTED_AUTHENTICATION_PATH,
  55   59                  CRYPTO_EXTF_PROTECTED_AUTHENTICATION_PATH },
  56   60          { "CRYPTO_EXTF_DUAL_CRYPTO_OPERATIONS",
  57   61                  CRYPTO_EXTF_DUAL_CRYPTO_OPERATIONS,
  58   62                  CRYPTO_EXTF_DUAL_CRYPTO_OPERATIONS },
  59   63          { "CRYPTO_EXTF_TOKEN_INITIALIZED", CRYPTO_EXTF_TOKEN_INITIALIZED,
  60   64                  CRYPTO_EXTF_TOKEN_INITIALIZED },
  61   65          { "CRYPTO_EXTF_USER_PIN_COUNT_LOW", CRYPTO_EXTF_USER_PIN_COUNT_LOW,
  62   66                  CRYPTO_EXTF_USER_PIN_COUNT_LOW },
  63   67          { "CRYPTO_EXTF_USER_PIN_FINAL_TRY", CRYPTO_EXTF_USER_PIN_FINAL_TRY,
  64   68                  CRYPTO_EXTF_USER_PIN_FINAL_TRY },
  65   69          { "CRYPTO_EXTF_USER_PIN_LOCKED", CRYPTO_EXTF_USER_PIN_LOCKED,
  66   70                  CRYPTO_EXTF_USER_PIN_LOCKED },
  67   71          { "CRYPTO_EXTF_USER_PIN_TO_BE_CHANGED",
  68   72                  CRYPTO_EXTF_USER_PIN_TO_BE_CHANGED,
  69   73                  CRYPTO_EXTF_USER_PIN_TO_BE_CHANGED },
  70   74          { "CRYPTO_EXTF_SO_PIN_COUNT_LOW", CRYPTO_EXTF_SO_PIN_COUNT_LOW,
  71   75                  CRYPTO_EXTF_SO_PIN_COUNT_LOW },
  72   76          { "CRYPTO_EXTF_SO_PIN_FINAL_TRY", CRYPTO_EXTF_SO_PIN_FINAL_TRY,
  73   77                  CRYPTO_EXTF_SO_PIN_FINAL_TRY },
  74   78          { "CRYPTO_EXTF_SO_PIN_LOCKED", CRYPTO_EXTF_SO_PIN_LOCKED,
  75   79                  CRYPTO_EXTF_SO_PIN_LOCKED },
  76   80          { "CRYPTO_EXTF_SO_PIN_TO_BE_CHANGED", CRYPTO_EXTF_SO_PIN_TO_BE_CHANGED,
  77   81                  CRYPTO_EXTF_SO_PIN_TO_BE_CHANGED },
  78   82          { NULL, 0, 0 }
  79   83  };
  80   84  
  81   85  /*ARGSUSED*/
  82   86  int
  83   87  crypto_provider_ext_info(uintptr_t addr, uint_t flags, int argc,
  84   88      const mdb_arg_t *argv)
  85   89  {
  86   90          crypto_provider_ext_info_t ext_prov;
  87   91          /*
  88   92           * 33 is 1 + MAX(CRYPTO_EXT_SIZE_LABEL, CRYPTO_EXT_SIZE_MANUF,
  89   93           *               CRYPTO_EXT_SIZE_MODEL, CRYPTO_EXT_SIZE_SERIAL)
  90   94           */
  91   95          char scratch[33];
  92   96  
  93   97          if (!(flags & DCMD_ADDRSPEC))
  94   98                  return (DCMD_USAGE);
  95   99  
  96  100          if (mdb_vread(&ext_prov, sizeof (crypto_provider_ext_info_t), addr)
  97  101              == -1) {
  98  102                  mdb_warn("cannot read addr");
  99  103                  return (DCMD_ERR);
 100  104          }
 101  105          bcopy(ext_prov.ei_label, scratch, CRYPTO_EXT_SIZE_LABEL);
 102  106          scratch[CRYPTO_EXT_SIZE_LABEL] = '\0';
 103  107          mdb_printf("ei_label\t\t%s\n", scratch);
 104  108  
 105  109          bcopy(ext_prov.ei_manufacturerID, scratch, CRYPTO_EXT_SIZE_MANUF);
 106  110          scratch[CRYPTO_EXT_SIZE_MANUF] = '\0';
 107  111          mdb_printf("ei_manufacturerID\t%s\n", scratch);
 108  112  
 109  113          bcopy(ext_prov.ei_model, scratch, CRYPTO_EXT_SIZE_MODEL);
 110  114          scratch[CRYPTO_EXT_SIZE_MODEL] = '\0';
 111  115          mdb_printf("ei_model\t\t%s\n", scratch);
 112  116  
 113  117          bcopy(ext_prov.ei_serial_number, scratch, CRYPTO_EXT_SIZE_SERIAL);
 114  118          scratch[CRYPTO_EXT_SIZE_SERIAL] = '\0';
 115  119          mdb_printf("ei_serial_number\t%s\n", scratch);
 116  120  
 117  121          mdb_printf("ei_flags\t0x%x:\t<%lb>\n", ext_prov.ei_flags,
 118  122              ext_prov.ei_flags, extf_flags);
 119  123          mdb_printf("ei_max_session_count\t%lu\n",
 120  124              ext_prov.ei_max_session_count);
 121  125          mdb_printf("ei_max_pin_len\t\t%lu\n", ext_prov.ei_max_pin_len);
 122  126          mdb_printf("ei_min_pin_len\t\t%lu\n", ext_prov.ei_min_pin_len);
 123  127          mdb_printf("ei_total_public_memory\t%lu\n",
 124  128              ext_prov.ei_total_public_memory);
 125  129          mdb_printf("ei_free_public_memory\t%lu\n",
 126  130              ext_prov.ei_free_public_memory);
 127  131          mdb_printf("ei_total_private_memory\t%lu\n",
 128  132              ext_prov.ei_total_private_memory);
 129  133          mdb_printf("ei_free_private_memory\t%lu\n",
 130  134              ext_prov.ei_free_private_memory);
 131  135          mdb_printf("ei_hardware_version\tmajor %c minor %c\n",
 132  136              ext_prov.ei_hardware_version.cv_major,
 133  137              ext_prov.ei_hardware_version.cv_minor);
 134  138          mdb_printf("ei_firmware_version\tmajor %c minor %c\n",
 135  139              ext_prov.ei_firmware_version.cv_major,
 136  140              ext_prov.ei_firmware_version.cv_minor);
 137  141          mdb_printf("ei_time\t%s\n", ext_prov.ei_time);
 138  142          return (DCMD_OK);
 139  143  }
 140  144  
 141  145  const mdb_bitmask_t mech_bits[] = {
 142  146          { "NIL", (uint32_t)-1, 0 },
 143  147          { "CRYPTO_FG_ENCRYPT", CRYPTO_FG_ENCRYPT, CRYPTO_FG_ENCRYPT },
 144  148          { "CRYPTO_FG_DECRYPT", CRYPTO_FG_DECRYPT, CRYPTO_FG_DECRYPT },
 145  149          { "CRYPTO_FG_DIGEST", CRYPTO_FG_DIGEST, CRYPTO_FG_DIGEST },
 146  150          { "CRYPTO_FG_SIGN", CRYPTO_FG_SIGN, CRYPTO_FG_SIGN },
 147  151          { "CRYPTO_FG_SIGN_RECOVER", CRYPTO_FG_SIGN_RECOVER,
 148  152                  CRYPTO_FG_SIGN_RECOVER },
 149  153          { "CRYPTO_FG_VERIFY", CRYPTO_FG_VERIFY, CRYPTO_FG_VERIFY },
 150  154          { "CRYPTO_FG_VERIFY_RECOVER", CRYPTO_FG_VERIFY_RECOVER,
 151  155                  CRYPTO_FG_VERIFY_RECOVER },
 152  156          { "CRYPTO_FG_GENERATE", CRYPTO_FG_GENERATE, CRYPTO_FG_GENERATE },
 153  157          { "CRYPTO_FG_GENERATE_KEY_PAIR", CRYPTO_FG_GENERATE_KEY_PAIR,
 154  158                  CRYPTO_FG_GENERATE_KEY_PAIR },
 155  159          { "CRYPTO_FG_WRAP", CRYPTO_FG_WRAP, CRYPTO_FG_WRAP },
 156  160          { "CRYPTO_FG_UNWRAP", CRYPTO_FG_UNWRAP, CRYPTO_FG_UNWRAP },
 157  161          { "CRYPTO_FG_DERIVE", CRYPTO_FG_DERIVE, CRYPTO_FG_DERIVE },
 158  162          { "CRYPTO_FG_MAC", CRYPTO_FG_MAC, CRYPTO_FG_MAC },
 159  163          { "CRYPTO_FG_ENCRYPT_MAC", CRYPTO_FG_ENCRYPT_MAC,
 160  164                  CRYPTO_FG_ENCRYPT_MAC },
 161  165          { "CRYPTO_FG_MAC_DECRYPT", CRYPTO_FG_MAC_DECRYPT,
 162  166                  CRYPTO_FG_MAC_DECRYPT },
 163  167          { "CRYPTO_FG_ENCRYPT_ATOMIC", CRYPTO_FG_ENCRYPT_ATOMIC,
 164  168                  CRYPTO_FG_ENCRYPT_ATOMIC },
 165  169          { "CRYPTO_FG_DECRYPT_ATOMIC", CRYPTO_FG_DECRYPT_ATOMIC,
 166  170                  CRYPTO_FG_DECRYPT_ATOMIC },
 167  171          { "CRYPTO_FG_MAC_ATOMIC", CRYPTO_FG_MAC_ATOMIC, CRYPTO_FG_MAC_ATOMIC },
 168  172          { "CRYPTO_FG_DIGEST_ATOMIC", CRYPTO_FG_DIGEST_ATOMIC,
 169  173                  CRYPTO_FG_DIGEST_ATOMIC },
 170  174          { "CRYPTO_FG_SIGN_ATOMIC", CRYPTO_FG_SIGN_ATOMIC,
 171  175                  CRYPTO_FG_SIGN_ATOMIC },
 172  176          { "CRYPTO_FG_SIGN_RECOVER_ATOMIC", CRYPTO_FG_SIGN_RECOVER_ATOMIC,
 173  177                  CRYPTO_FG_SIGN_RECOVER_ATOMIC },
 174  178          { "CRYPTO_FG_VERIFY_ATOMIC", CRYPTO_FG_VERIFY_ATOMIC,
 175  179                  CRYPTO_FG_VERIFY_ATOMIC },
 176  180          { "CRYPTO_FG_VERIFY_RECOVER_ATOMIC", CRYPTO_FG_VERIFY_RECOVER_ATOMIC,
 177  181                  CRYPTO_FG_VERIFY_RECOVER_ATOMIC },
 178  182          { "CRYPTO_FG_ENCRYPT_MAC_ATOMIC", CRYPTO_FG_ENCRYPT_MAC_ATOMIC,
 179  183                  CRYPTO_FG_ENCRYPT_MAC_ATOMIC },
 180  184          { "CRYPTO_FG_MAC_DECRYPT_ATOMIC", CRYPTO_FG_MAC_DECRYPT_ATOMIC,
 181  185                  CRYPTO_FG_MAC_DECRYPT_ATOMIC },
 182  186          { "CRYPTO_FG_RANDOM", CRYPTO_FG_RANDOM, CRYPTO_FG_RANDOM},
 183  187          { NULL, 0, 0 }
  
    | 
      ↓ open down ↓ | 
    147 lines elided | 
    
      ↑ open up ↑ | 
  
 184  188  };
 185  189  
 186  190  /*ARGSUSED*/
 187  191  int
 188  192  crypto_mech_info(uintptr_t addr, uint_t flags, int argc,
 189  193      const mdb_arg_t *argv)
 190  194  {
 191  195          crypto_mech_info_t minfo;
 192  196          const char *unit = "bits";
 193  197  
 194      -        if (! flags & DCMD_ADDRSPEC)
      198 +        if (!(flags & DCMD_ADDRSPEC))
 195  199                  return (DCMD_USAGE);
 196  200  
 197  201          if (mdb_vread(&minfo, sizeof (crypto_mech_info_t), addr)
 198  202              == -1) {
 199  203                  mdb_warn("cannot read addr %p", addr);
 200  204                  return (DCMD_ERR);
 201  205          }
 202  206          mdb_printf("cm_mech_name_t\t%s\n", minfo.cm_mech_name);
 203  207          mdb_printf("cm_mech_number\t%lld\n", minfo.cm_mech_number);
 204  208          mdb_printf("cm_func_group_mask\t0x%x:\t<%b>\n",
 205  209              minfo.cm_func_group_mask, minfo.cm_func_group_mask, mech_bits);
 206  210          if (minfo.cm_keysize_unit & CRYPTO_KEYSIZE_UNIT_IN_BYTES)
 207  211                  unit = "bytes";
 208  212          mdb_printf("cm_min_key_length\t%lu %s\n", minfo.cm_min_key_length,
 209  213              unit);
 210  214          mdb_printf("cm_max_key_length\t%lu %s\n", minfo.cm_max_key_length,
 211  215              unit);
 212  216  
 213  217          return (DCMD_OK);
 214  218  }
 215  219  
 216  220  /*
 217  221   * MDB module linkage information:
 218  222   *
 219  223   * We declare a list of structures describing our dcmds, and a function
 220  224   * named _mdb_init to return a pointer to our module information.
 221  225   */
 222  226  
 223  227  static const mdb_dcmd_t dcmds[] = {
 224  228  
 225  229          /* spi.c */
 226  230          { "crypto_provider_ext_info", ":",
 227  231              "module-private crypto provider info",
 228  232              crypto_provider_ext_info, NULL },
 229  233          { "crypto_mech_info", ":",
 230  234              "print as crypto_mech_info",
 231  235              crypto_mech_info, NULL },
 232  236  
 233  237          /* common.c */
 234  238          { "crypto_mechanism", ":",
 235  239              "details about a crypto mechanism", crypto_mechanism, NULL },
 236  240          { "crypto_data", ":",
 237  241              "print as crypto_data",
 238  242              crypto_data, NULL },
 239  243          { "crypto_dual_data", ":",
 240  244              "print as crypto_dual_data",
 241  245              crypto_dual_data, NULL },
 242  246          { "crypto_key", ":",
 243  247              "print as crypto_key", crypto_key, NULL },
 244  248  
 245  249  
 246  250          /* impl.c */
 247  251          { "kcf_provider_desc", ":",
 248  252              "crypto provider description struct", kcf_provider_desc, NULL },
 249  253  
 250  254          { "prov_tab", "",
 251  255              "global table of crypto providers ", prov_tab, NULL },
 252  256  
 253  257          { "policy_tab", "",
 254  258              "print global policy_tab", policy_tab, NULL },
 255  259  
 256  260          /* sched_impl.c */
 257  261          { "kcf_areq_node", ":[-v]",
 258  262              "print asynchronous crypto request struct, [ verbose ]",
 259  263                  kcf_areq_node, NULL },
 260  264  
 261  265          { "kcf_global_swq", "?[-v]",
 262  266              "global or addr global crypto queue.  [ -v = verbose ]",
 263  267                  kcf_global_swq, NULL },
 264  268          { "crypto_find_reqid", "?[-v] reqid",
 265  269              "look for reqid, print if found [ -v = verbose ]",
 266  270                  crypto_find_reqid, NULL },
 267  271  
 268  272          { "kcf_reqid_table", ":[-v]",
 269  273              "print contents of a request ID hash table [ -v = verbose ]",
 270  274                  kcf_reqid_table_dcmd, NULL },
 271  275  
 272  276          { "kcf_soft_conf_entry", "?",
 273  277              "head or addr of configured software crypto providers",
 274  278                  kcf_soft_conf_entry, NULL },
 275  279  
 276  280          { "kcf_policy_desc", ":", "policy descriptors for crypto",
 277  281                  kcf_policy_desc, NULL },
 278  282          { NULL }
 279  283  };
 280  284  
 281  285  static const mdb_walker_t walkers[] = {
 282  286          { "an_next", "walk kcf_areq_node's by an_next",
 283  287                  areq_first_walk_init, an_next_walk_step, areq_walk_fini },
 284  288          { "an_prev", "walk kcf_areq_node's by an_prev",
 285  289                  areq_last_walk_init, an_prev_walk_step, areq_walk_fini },
 286  290          { "an_idnext", "walk kcf_areq_node's by an_idnext",
 287  291                  an_idnext_walk_init, an_idnext_walk_step, areq_walk_fini },
 288  292          { "an_idprev", "walk kcf_areq_node's by an_idprev",
 289  293                  an_idprev_walk_init, an_idprev_walk_step, areq_walk_fini },
 290  294          { "an_ctxchain_next",
 291  295                  "walk kcf_areq_node's by an_ctxchain_next",
 292  296                  an_ctxchain_walk_init, an_ctxchain_walk_step, areq_walk_fini },
 293  297          { "kcf_reqid_table", "table of asynchronous crypto requests",
 294  298                  reqid_table_walk_init, reqid_table_walk_step,
 295  299                      reqid_table_walk_fini },
 296  300          { "soft_conf_entry", "table of software providers or addr",
 297  301                  soft_conf_walk_init, soft_conf_walk_step,
 298  302                      soft_conf_walk_fini },
 299  303          { NULL }
 300  304  };
 301  305  
 302  306  
 303  307  static const mdb_modinfo_t modinfo = {
 304  308          MDB_API_VERSION, dcmds, walkers
 305  309  };
 306  310  
 307  311  const mdb_modinfo_t *
 308  312  _mdb_init(void)
 309  313  {
 310  314          return (&modinfo);
 311  315  }
  
    | 
      ↓ open down ↓ | 
    107 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX