smb3.1.1: rename nonces used for GCM and CCM encryption
[linux-2.6-microblaze.git] / fs / cifs / smb2ops.c
index 32f90dc..dd1edab 100644 (file)
@@ -651,7 +651,8 @@ smb2_cached_lease_break(struct work_struct *work)
  * Open the directory at the root of a share
  */
 int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
-               struct cifs_sb_info *cifs_sb, struct cifs_fid *pfid)
+               struct cifs_sb_info *cifs_sb,
+               struct cached_fid **cfid)
 {
        struct cifs_ses *ses = tcon->ses;
        struct TCP_Server_Info *server = ses->server;
@@ -666,11 +667,12 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
        int rc, flags = 0;
        __le16 utf16_path = 0; /* Null - since an open of top of share */
        u8 oplock = SMB2_OPLOCK_LEVEL_II;
+       struct cifs_fid *pfid;
 
        mutex_lock(&tcon->crfid.fid_mutex);
        if (tcon->crfid.is_valid) {
                cifs_dbg(FYI, "found a cached root file handle\n");
-               memcpy(pfid, tcon->crfid.fid, sizeof(struct cifs_fid));
+               *cfid = &tcon->crfid;
                kref_get(&tcon->crfid.refcount);
                mutex_unlock(&tcon->crfid.fid_mutex);
                return 0;
@@ -691,6 +693,7 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
        if (!server->ops->new_lease_key)
                return -EIO;
 
+       pfid = tcon->crfid.fid;
        server->ops->new_lease_key(pfid);
 
        memset(rqst, 0, sizeof(rqst));
@@ -820,6 +823,8 @@ oshr_free:
        SMB2_query_info_free(&rqst[1]);
        free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
        free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
+       if (rc == 0)
+               *cfid = &tcon->crfid;
        return rc;
 }
 
@@ -833,6 +838,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
        struct cifs_open_parms oparms;
        struct cifs_fid fid;
        bool no_cached_open = tcon->nohandlecache;
+       struct cached_fid *cfid = NULL;
 
        oparms.tcon = tcon;
        oparms.desired_access = FILE_READ_ATTRIBUTES;
@@ -841,12 +847,14 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
        oparms.fid = &fid;
        oparms.reconnect = false;
 
-       if (no_cached_open)
+       if (no_cached_open) {
                rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
                               NULL, NULL);
-       else
-               rc = open_shroot(xid, tcon, cifs_sb, &fid);
-
+       } else {
+               rc = open_shroot(xid, tcon, cifs_sb, &cfid);
+               if (rc == 0)
+                       memcpy(&fid, cfid->fid, sizeof(struct cifs_fid));
+       }
        if (rc)
                return;
 
@@ -863,7 +871,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
        if (no_cached_open)
                SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
        else
-               close_shroot(&tcon->crfid);
+               close_shroot(cfid);
 }
 
 static void
@@ -1208,7 +1216,7 @@ smb2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
        rqst[1].rq_iov = si_iov;
        rqst[1].rq_nvec = 1;
 
-       len = sizeof(ea) + ea_name_len + ea_value_len + 1;
+       len = sizeof(*ea) + ea_name_len + ea_value_len + 1;
        ea = kzalloc(len, GFP_KERNEL);
        if (ea == NULL) {
                rc = -ENOMEM;
@@ -2346,6 +2354,17 @@ smb2_is_session_expired(char *buf)
        return true;
 }
 
+static bool
+smb2_is_status_io_timeout(char *buf)
+{
+       struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)buf;
+
+       if (shdr->Status == STATUS_IO_TIMEOUT)
+               return true;
+       else
+               return false;
+}
+
 static int
 smb2_oplock_response(struct cifs_tcon *tcon, struct cifs_fid *fid,
                     struct cifsInodeInfo *cinode)
@@ -3802,9 +3821,9 @@ fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
        tr_hdr->OriginalMessageSize = cpu_to_le32(orig_len);
        tr_hdr->Flags = cpu_to_le16(0x01);
        if (cipher_type == SMB2_ENCRYPTION_AES128_GCM)
-               get_random_bytes(&tr_hdr->Nonce, SMB3_AES128GCM_NONCE);
+               get_random_bytes(&tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
        else
-               get_random_bytes(&tr_hdr->Nonce, SMB3_AES128CCM_NONCE);
+               get_random_bytes(&tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
        memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
 }
 
@@ -3974,10 +3993,10 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
        }
 
        if (server->cipher_type == SMB2_ENCRYPTION_AES128_GCM)
-               memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES128GCM_NONCE);
+               memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
        else {
                iv[0] = 3;
-               memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES128CCM_NONCE);
+               memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
        }
 
        aead_request_set_crypt(req, sg, sg, crypt_len, iv);
@@ -4809,6 +4828,7 @@ struct smb_version_operations smb20_operations = {
        .make_node = smb2_make_node,
        .fiemap = smb3_fiemap,
        .llseek = smb3_llseek,
+       .is_status_io_timeout = smb2_is_status_io_timeout,
 };
 
 struct smb_version_operations smb21_operations = {
@@ -4909,6 +4929,7 @@ struct smb_version_operations smb21_operations = {
        .make_node = smb2_make_node,
        .fiemap = smb3_fiemap,
        .llseek = smb3_llseek,
+       .is_status_io_timeout = smb2_is_status_io_timeout,
 };
 
 struct smb_version_operations smb30_operations = {
@@ -5019,6 +5040,7 @@ struct smb_version_operations smb30_operations = {
        .make_node = smb2_make_node,
        .fiemap = smb3_fiemap,
        .llseek = smb3_llseek,
+       .is_status_io_timeout = smb2_is_status_io_timeout,
 };
 
 struct smb_version_operations smb311_operations = {
@@ -5130,6 +5152,7 @@ struct smb_version_operations smb311_operations = {
        .make_node = smb2_make_node,
        .fiemap = smb3_fiemap,
        .llseek = smb3_llseek,
+       .is_status_io_timeout = smb2_is_status_io_timeout,
 };
 
 struct smb_version_values smb20_values = {