Print this page
NEX-10231 SMB logon fails in fksmbd
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
NEX-5273 SMB 3 Encryption
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
NEX-3728 SMB1 signing should use KCF like SMB2/3
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Dan Fields <dan.fields@nexenta.com>
NEX-3610 CLONE NEX-3591 SMB3 signing
Reviewed by: Gordon Ross <gwr@nexenta.com>
Reviewed by: Dan Fields <dan.fields@nexenta.com>
NEX-3080 SMB1 signing problem with Kerberos auth.
Reviewed by: Bayard Bell <bayard.bell@nexenta.com>
Reviewed by: Dan Fields <dan.fields@nexenta.com>
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
Reviewed by: Matt Barden <Matt.Barden@nexenta.com>
SMB-55 SMB2 signing
SMB-56 extended security NTLMSSP, inbound
SMB-50 User-mode SMB server
 Includes work by these authors:
 Thomas Keiser <thomas.keiser@nexenta.com>
 Albert Lee <trisk@nexenta.com>
SMB-65 SMB server in non-global zones (kmem_caches)
common kmem_cache instances across zones
separate GZ-only init from NGZ init

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/smbsrv/smb_signing.c
          +++ new/usr/src/uts/common/fs/smbsrv/smb_signing.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) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  23      - * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
       23 + * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
  24   24   */
  25   25  /*
  26   26   * These routines provide the SMB MAC signing for the SMB server.
  27   27   * The routines calculate the signature of a SMB message in an mbuf chain.
  28   28   *
  29   29   * The following table describes the client server
  30   30   * signing registry relationship
  31   31   *
  32   32   *              | Required      | Enabled     | Disabled
  33   33   * -------------+---------------+------------ +--------------
  34   34   * Required     | Signed        | Signed      | Fail
  35   35   * -------------+---------------+-------------+-----------------
  36   36   * Enabled      | Signed        | Signed      | Not Signed
  37   37   * -------------+---------------+-------------+----------------
  38   38   * Disabled     | Fail          | Not Signed  | Not Signed
  39   39   */
  40   40  
  41   41  #include <sys/uio.h>
  42   42  #include <smbsrv/smb_kproto.h>
  43      -#include <smbsrv/smb_signing.h>
       43 +#include <smbsrv/smb_kcrypt.h>
  44   44  #include <sys/isa_defs.h>
  45   45  #include <sys/byteorder.h>
  46   46  
  47   47  #define SMB_SIG_SIZE    8
  48   48  #define SMB_SIG_OFFS    14
  49   49  #define SMB_HDRLEN      32
  50   50  
  51   51  #ifdef _LITTLE_ENDIAN
  52   52  #define htolel(x)       ((uint32_t)(x))
  53   53  #else
↓ open down ↓ 43 lines elided ↑ open up ↑
  97   97          return (0);
  98   98  }
  99   99  #endif
 100  100  
 101  101  /*
 102  102   * Called during session destroy.
 103  103   */
 104  104  static void
 105  105  smb_sign_fini(smb_session_t *s)
 106  106  {
 107      -        smb_sign_mech_t *mech;
      107 +        smb_crypto_mech_t *mech;
 108  108  
 109  109          if ((mech = s->sign_mech) != NULL) {
 110  110                  kmem_free(mech, sizeof (*mech));
 111  111                  s->sign_mech = NULL;
 112  112          }
 113  113  }
 114  114  
 115  115  /*
 116  116   * smb_sign_begin
 117  117   *
 118  118   * Intializes MAC key based on the user session key and
 119  119   * NTLM response and store it in the signing structure.
 120  120   * This is what begins SMB signing.
 121  121   */
 122      -int
      122 +void
 123  123  smb_sign_begin(smb_request_t *sr, smb_token_t *token)
 124  124  {
 125  125          smb_arg_sessionsetup_t *sinfo = sr->sr_ssetup;
 126  126          smb_session_t *session = sr->session;
 127  127          struct smb_sign *sign = &session->signing;
 128      -        smb_sign_mech_t *mech;
      128 +        smb_crypto_mech_t *mech;
 129  129          int rc;
 130  130  
 131  131          /*
 132  132           * We should normally have a session key here because
 133  133           * our caller filters out Anonymous and Guest logons.
 134  134           * However, buggy clients could get us here without a
 135  135           * session key, in which case: just don't sign.
 136  136           */
 137  137          if (token->tkn_ssnkey.val == NULL || token->tkn_ssnkey.len == 0)
 138      -                return (0);
      138 +                return;
 139  139  
 140  140          /*
 141  141           * Session-level initialization (once per session)
 142  142           */
 143  143          smb_rwx_rwenter(&session->s_lock, RW_WRITER);
 144  144  
 145  145          /*
 146  146           * Signing may already have been setup by a prior logon,
 147  147           * in which case we're done here.
 148  148           */
 149  149          if (sign->mackey != NULL) {
 150  150                  smb_rwx_rwexit(&session->s_lock);
 151      -                return (0);
      151 +                return;
 152  152          }
 153  153  
 154  154          /*
 155  155           * Get the mech handle
 156  156           */
 157  157          if (session->sign_mech == NULL) {
 158  158                  mech = kmem_zalloc(sizeof (*mech), KM_SLEEP);
 159  159                  rc = smb_md5_getmech(mech);
 160  160                  if (rc != 0) {
 161  161                          kmem_free(mech, sizeof (*mech));
 162  162                          smb_rwx_rwexit(&session->s_lock);
 163      -                        return (rc);
      163 +                        return;
 164  164                  }
 165  165                  session->sign_mech = mech;
 166  166                  session->sign_fini = smb_sign_fini;
 167  167          }
 168  168  
 169  169          /*
 170  170           * Compute and store the signing (MAC) key.
 171  171           *
 172  172           * With extended security, the MAC key is the same as the
 173  173           * session key (and we'll have sinfo->ssi_ntpwlen == 0).
↓ open down ↓ 6 lines elided ↑ open up ↑
 180  180          if (sinfo->ssi_ntpwlen > 0) {
 181  181                  bcopy(sinfo->ssi_ntpwd, sign->mackey + token->tkn_ssnkey.len,
 182  182                      sinfo->ssi_ntpwlen);
 183  183          }
 184  184  
 185  185          session->signing.seqnum = 0;
 186  186          sr->sr_seqnum = 2;
 187  187          sr->reply_seqnum = 1;
 188  188          sign->flags = 0;
 189  189  
 190      -        if (session->secmode & NEGOTIATE_SECURITY_SIGNATURES_ENABLED) {
      190 +        if (session->srv_secmode & NEGOTIATE_SECURITY_SIGNATURES_ENABLED) {
 191  191                  sign->flags |= SMB_SIGNING_ENABLED;
 192      -                if (session->secmode & NEGOTIATE_SECURITY_SIGNATURES_REQUIRED)
      192 +                if (session->srv_secmode &
      193 +                    NEGOTIATE_SECURITY_SIGNATURES_REQUIRED)
 193  194                          sign->flags |= SMB_SIGNING_CHECK;
 194  195          }
 195  196  
 196  197          smb_rwx_rwexit(&session->s_lock);
 197      -        return (0);
 198  198  }
 199  199  
 200  200  /*
 201  201   * smb_sign_calc
 202  202   *
 203  203   * Calculates MAC signature for the given buffer and returns
 204  204   * it in the mac_sign parameter.
 205  205   *
 206  206   * The sequence number is placed in the first four bytes of the signature
 207  207   * field of the signature and the other 4 bytes are zeroed.
↓ open down ↓ 231 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX