Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *   fs/cifs/cifsencrypt.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *   Encryption and hashing operations relating to NTLM, NTLMv2.  See MS-NLMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *   for more detailed information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *   Copyright (C) International Business Machines  Corp., 2005,2013
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *   Author(s): Steve French (sfrench@us.ibm.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *   This library is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *   it under the terms of the GNU Lesser General Public License as published
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *   by the Free Software Foundation; either version 2.1 of the License, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *   (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *   This library is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *   the GNU Lesser General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *   You should have received a copy of the GNU Lesser General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *   along with this library; if not, write to the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "cifspdu.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include "cifsglob.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include "cifs_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "cifs_unicode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include "cifsproto.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include "ntlmssp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/fips.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <crypto/arc4.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <crypto/aead.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) int __cifs_calc_signature(struct smb_rqst *rqst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 			struct TCP_Server_Info *server, char *signature,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 			struct shash_desc *shash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct kvec *iov = rqst->rq_iov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	int n_vec = rqst->rq_nvec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	int is_smb2 = server->vals->header_preamble_size == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	/* iov[0] is actual data and not the rfc1002 length for SMB2+ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if (is_smb2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		if (iov[0].iov_len <= 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		if (n_vec < 2 || iov[0].iov_len != 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		i = 1; /* skip rfc1002 length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	for (; i < n_vec; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		if (iov[i].iov_len == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		if (iov[i].iov_base == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			cifs_dbg(VFS, "null iovec entry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		rc = crypto_shash_update(shash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 					 iov[i].iov_base, iov[i].iov_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			cifs_dbg(VFS, "%s: Could not update with payload\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 				 __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	/* now hash over the rq_pages array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	for (i = 0; i < rqst->rq_npages; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		void *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		unsigned int len, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		rqst_page_get_length(rqst, i, &len, &offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		kaddr = (char *) kmap(rqst->rq_pages[i]) + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		rc = crypto_shash_update(shash, kaddr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			cifs_dbg(VFS, "%s: Could not update with payload\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 				 __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			kunmap(rqst->rq_pages[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		kunmap(rqst->rq_pages[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	rc = crypto_shash_final(shash, signature);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		cifs_dbg(VFS, "%s: Could not generate hash\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * Calculate and return the CIFS signature based on the mac key and SMB PDU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * The 16 byte signature must be allocated by the caller. Note we only use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * 1st eight bytes and that the smb header signature field on input contains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * the sequence number before this function is called. Also, this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * should be called with the server->srv_mutex held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static int cifs_calc_signature(struct smb_rqst *rqst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			struct TCP_Server_Info *server, char *signature)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (!rqst->rq_iov || !signature || !server)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	rc = cifs_alloc_hash("md5", &server->secmech.md5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			     &server->secmech.sdescmd5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	rc = crypto_shash_init(&server->secmech.sdescmd5->shash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		cifs_dbg(VFS, "%s: Could not init md5\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	rc = crypto_shash_update(&server->secmech.sdescmd5->shash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		server->session_key.response, server->session_key.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		cifs_dbg(VFS, "%s: Could not update with response\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	return __cifs_calc_signature(rqst, server, signature,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				     &server->secmech.sdescmd5->shash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /* must be called with server->srv_mutex held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		   __u32 *pexpected_response_sequence_number)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	char smb_signature[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct smb_hdr *cifs_pdu = (struct smb_hdr *)rqst->rq_iov[0].iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (rqst->rq_iov[0].iov_len != 4 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	    rqst->rq_iov[0].iov_base + 4 != rqst->rq_iov[1].iov_base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if ((cifs_pdu == NULL) || (server == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (!(cifs_pdu->Flags2 & SMBFLG2_SECURITY_SIGNATURE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	    server->tcpStatus == CifsNeedNegotiate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (!server->session_estab) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		memcpy(cifs_pdu->Signature.SecuritySignature, "BSRSPYL", 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	cifs_pdu->Signature.Sequence.SequenceNumber =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 				cpu_to_le32(server->sequence_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	cifs_pdu->Signature.Sequence.Reserved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	*pexpected_response_sequence_number = ++server->sequence_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	++server->sequence_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	rc = cifs_calc_signature(rqst, server, smb_signature);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		memset(cifs_pdu->Signature.SecuritySignature, 0, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		memcpy(cifs_pdu->Signature.SecuritySignature, smb_signature, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		   __u32 *pexpected_response_sequence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct smb_rqst rqst = { .rq_iov = iov,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 				 .rq_nvec = n_vec };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	return cifs_sign_rqst(&rqst, server, pexpected_response_sequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /* must be called with server->srv_mutex held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		  __u32 *pexpected_response_sequence_number)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	struct kvec iov[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	iov[0].iov_base = cifs_pdu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	iov[0].iov_len = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	iov[1].iov_base = (char *)cifs_pdu + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	iov[1].iov_len = be32_to_cpu(cifs_pdu->smb_buf_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	return cifs_sign_smbv(iov, 2, server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			      pexpected_response_sequence_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) int cifs_verify_signature(struct smb_rqst *rqst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			  struct TCP_Server_Info *server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			  __u32 expected_sequence_number)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	unsigned int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	char server_response_sig[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	char what_we_think_sig_should_be[20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	struct smb_hdr *cifs_pdu = (struct smb_hdr *)rqst->rq_iov[0].iov_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	if (rqst->rq_iov[0].iov_len != 4 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	    rqst->rq_iov[0].iov_base + 4 != rqst->rq_iov[1].iov_base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (cifs_pdu == NULL || server == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (!server->session_estab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (cifs_pdu->Command == SMB_COM_LOCKING_ANDX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		struct smb_com_lock_req *pSMB =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			(struct smb_com_lock_req *)cifs_pdu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		if (pSMB->LockType & LOCKING_ANDX_OPLOCK_RELEASE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	/* BB what if signatures are supposed to be on for session but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	   server does not send one? BB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	/* Do not need to verify session setups with signature "BSRSPYL "  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	if (memcmp(cifs_pdu->Signature.SecuritySignature, "BSRSPYL ", 8) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		cifs_dbg(FYI, "dummy signature received for smb command 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			 cifs_pdu->Command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	/* save off the origiginal signature so we can modify the smb and check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		its signature against what the server sent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	memcpy(server_response_sig, cifs_pdu->Signature.SecuritySignature, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	cifs_pdu->Signature.Sequence.SequenceNumber =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 					cpu_to_le32(expected_sequence_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	cifs_pdu->Signature.Sequence.Reserved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	mutex_lock(&server->srv_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	rc = cifs_calc_signature(rqst, server, what_we_think_sig_should_be);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	mutex_unlock(&server->srv_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /*	cifs_dump_mem("what we think it should be: ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		      what_we_think_sig_should_be, 16); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	if (memcmp(server_response_sig, what_we_think_sig_should_be, 8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) /* first calculate 24 bytes ntlm response and then 16 byte session key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) int setup_ntlm_response(struct cifs_ses *ses, const struct nls_table *nls_cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	unsigned int temp_len = CIFS_SESS_KEY_SIZE + CIFS_AUTH_RESP_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	char temp_key[CIFS_SESS_KEY_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (!ses)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	ses->auth_key.response = kmalloc(temp_len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	if (!ses->auth_key.response)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	ses->auth_key.len = temp_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	rc = SMBNTencrypt(ses->password, ses->server->cryptkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			ses->auth_key.response + CIFS_SESS_KEY_SIZE, nls_cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		cifs_dbg(FYI, "%s Can't generate NTLM response, error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			 __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	rc = E_md4hash(ses->password, temp_key, nls_cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		cifs_dbg(FYI, "%s Can't generate NT hash, error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			 __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	rc = mdfour(ses->auth_key.response, temp_key, CIFS_SESS_KEY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		cifs_dbg(FYI, "%s Can't generate NTLM session key, error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			 __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) #ifdef CONFIG_CIFS_WEAK_PW_HASH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) int calc_lanman_hash(const char *password, const char *cryptkey, bool encrypt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			char *lnm_session_key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	int i, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	char password_with_pad[CIFS_ENCPWD_SIZE] = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (password) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		for (len = 0; len < CIFS_ENCPWD_SIZE; len++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			if (!password[len])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		memcpy(password_with_pad, password, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	if (!encrypt && global_secflags & CIFSSEC_MAY_PLNTXT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		memcpy(lnm_session_key, password_with_pad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 			CIFS_ENCPWD_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	/* calculate old style session key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	/* calling toupper is less broken than repeatedly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	calling nls_toupper would be since that will never
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	work for UTF8, but neither handles multibyte code pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	but the only alternative would be converting to UCS-16 (Unicode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	(using a routine something like UniStrupr) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	uppercasing and then converting back from Unicode - which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	would only worth doing it if we knew it were utf8. Basically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	utf8 and other multibyte codepages each need their own strupper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	function since a byte at a time will ont work. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	for (i = 0; i < CIFS_ENCPWD_SIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		password_with_pad[i] = toupper(password_with_pad[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	rc = SMBencrypt(password_with_pad, cryptkey, lnm_session_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) #endif /* CIFS_WEAK_PW_HASH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /* Build a proper attribute value/target info pairs blob.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)  * Fill in netbios and dns domain name and workstation name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)  * and client time (total five av pairs and + one end of fields indicator.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)  * Allocate domain name which gets freed when session struct is deallocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) build_avpair_blob(struct cifs_ses *ses, const struct nls_table *nls_cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	unsigned int dlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	unsigned int size = 2 * sizeof(struct ntlmssp2_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	char *defdmname = "WORKGROUP";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	unsigned char *blobptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	struct ntlmssp2_name *attrptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	if (!ses->domainName) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		ses->domainName = kstrdup(defdmname, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		if (!ses->domainName)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	dlen = strlen(ses->domainName);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	 * The length of this blob is two times the size of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	 * structure (av pair) which holds name/size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	 * ( for NTLMSSP_AV_NB_DOMAIN_NAME followed by NTLMSSP_AV_EOL ) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	 * unicode length of a netbios domain name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	ses->auth_key.len = size + 2 * dlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	ses->auth_key.response = kzalloc(ses->auth_key.len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	if (!ses->auth_key.response) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		ses->auth_key.len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	blobptr = ses->auth_key.response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	attrptr = (struct ntlmssp2_name *) blobptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	 * As defined in MS-NTLM 3.3.2, just this av pair field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	 * is sufficient as part of the temp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	attrptr->type = cpu_to_le16(NTLMSSP_AV_NB_DOMAIN_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	attrptr->length = cpu_to_le16(2 * dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	blobptr = (unsigned char *)attrptr + sizeof(struct ntlmssp2_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	cifs_strtoUTF16((__le16 *)blobptr, ses->domainName, dlen, nls_cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) /* Server has provided av pairs/target info in the type 2 challenge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)  * packet and we have plucked it and stored within smb session.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)  * We parse that blob here to find netbios domain name to be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)  * as part of ntlmv2 authentication (in Target String), if not already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)  * specified on the command line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)  * If this function returns without any error but without fetching
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)  * domain name, authentication may fail against some server but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)  * may not fail against other (those who are not very particular
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)  * about target string i.e. for some, just user name might suffice.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) find_domain_name(struct cifs_ses *ses, const struct nls_table *nls_cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	unsigned int attrsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	unsigned int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	unsigned int onesize = sizeof(struct ntlmssp2_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	unsigned char *blobptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	unsigned char *blobend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	struct ntlmssp2_name *attrptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	if (!ses->auth_key.len || !ses->auth_key.response)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	blobptr = ses->auth_key.response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	blobend = blobptr + ses->auth_key.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	while (blobptr + onesize < blobend) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		attrptr = (struct ntlmssp2_name *) blobptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		type = le16_to_cpu(attrptr->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		if (type == NTLMSSP_AV_EOL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		blobptr += 2; /* advance attr type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		attrsize = le16_to_cpu(attrptr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		blobptr += 2; /* advance attr size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		if (blobptr + attrsize > blobend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		if (type == NTLMSSP_AV_NB_DOMAIN_NAME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 			if (!attrsize || attrsize >= CIFS_MAX_DOMAINNAME_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 			if (!ses->domainName) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 				ses->domainName =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 					kmalloc(attrsize + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 				if (!ses->domainName)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 						return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 				cifs_from_utf16(ses->domainName,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 					(__le16 *)blobptr, attrsize, attrsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 					nls_cp, NO_MAP_UNI_RSVD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		blobptr += attrsize; /* advance attr  value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* Server has provided av pairs/target info in the type 2 challenge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)  * packet and we have plucked it and stored within smb session.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)  * We parse that blob here to find the server given timestamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)  * as part of ntlmv2 authentication (or local current time as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)  * default in case of failure)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) static __le64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) find_timestamp(struct cifs_ses *ses)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	unsigned int attrsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	unsigned int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	unsigned int onesize = sizeof(struct ntlmssp2_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	unsigned char *blobptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	unsigned char *blobend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	struct ntlmssp2_name *attrptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	struct timespec64 ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	if (!ses->auth_key.len || !ses->auth_key.response)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	blobptr = ses->auth_key.response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	blobend = blobptr + ses->auth_key.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	while (blobptr + onesize < blobend) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		attrptr = (struct ntlmssp2_name *) blobptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		type = le16_to_cpu(attrptr->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		if (type == NTLMSSP_AV_EOL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		blobptr += 2; /* advance attr type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		attrsize = le16_to_cpu(attrptr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		blobptr += 2; /* advance attr size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		if (blobptr + attrsize > blobend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		if (type == NTLMSSP_AV_TIMESTAMP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 			if (attrsize == sizeof(u64))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 				return *((__le64 *)blobptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		blobptr += attrsize; /* advance attr value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	ktime_get_real_ts64(&ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	return cpu_to_le64(cifs_UnixTimeToNT(ts));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 			    const struct nls_table *nls_cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	char nt_hash[CIFS_NTHASH_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	__le16 *user;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	wchar_t *domain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	wchar_t *server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	if (!ses->server->secmech.sdeschmacmd5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		cifs_dbg(VFS, "%s: can't generate ntlmv2 hash\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	/* calculate md4 hash of password */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	E_md4hash(ses->password, nt_hash, nls_cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	rc = crypto_shash_setkey(ses->server->secmech.hmacmd5, nt_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 				CIFS_NTHASH_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		cifs_dbg(VFS, "%s: Could not set NT Hash as a key\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		cifs_dbg(VFS, "%s: Could not init hmacmd5\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	/* convert ses->user_name to unicode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	len = ses->user_name ? strlen(ses->user_name) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	user = kmalloc(2 + (len * 2), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	if (user == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	if (len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		len = cifs_strtoUTF16(user, ses->user_name, len, nls_cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		UniStrupr(user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		memset(user, '\0', 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	rc = crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 				(char *)user, 2 * len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	kfree(user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		cifs_dbg(VFS, "%s: Could not update with user\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	/* convert ses->domainName to unicode and uppercase */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	if (ses->domainName) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		len = strlen(ses->domainName);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		domain = kmalloc(2 + (len * 2), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		if (domain == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		len = cifs_strtoUTF16((__le16 *)domain, ses->domainName, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 				      nls_cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		rc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 		crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 					(char *)domain, 2 * len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		kfree(domain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 			cifs_dbg(VFS, "%s: Could not update with domain\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 				 __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 		/* We use ses->serverName if no domain name available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 		len = strlen(ses->serverName);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 		server = kmalloc(2 + (len * 2), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 		if (server == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		len = cifs_strtoUTF16((__le16 *)server, ses->serverName, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 					nls_cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		rc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 					(char *)server, 2 * len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 		kfree(server);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 			cifs_dbg(VFS, "%s: Could not update with server\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 				 __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 			return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 					ntlmv2_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 		cifs_dbg(VFS, "%s: Could not generate md5 hash\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) CalcNTLMv2_response(const struct cifs_ses *ses, char *ntlmv2_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	struct ntlmv2_resp *ntlmv2 = (struct ntlmv2_resp *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	    (ses->auth_key.response + CIFS_SESS_KEY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	unsigned int hash_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	/* The MD5 hash starts at challenge_key.key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	hash_len = ses->auth_key.len - (CIFS_SESS_KEY_SIZE +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 		offsetof(struct ntlmv2_resp, challenge.key[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	if (!ses->server->secmech.sdeschmacmd5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		cifs_dbg(VFS, "%s: can't generate ntlmv2 hash\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	rc = crypto_shash_setkey(ses->server->secmech.hmacmd5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 				 ntlmv2_hash, CIFS_HMAC_MD5_HASH_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 		cifs_dbg(VFS, "%s: Could not set NTLMV2 Hash as a key\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 			 __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 		cifs_dbg(VFS, "%s: Could not init hmacmd5\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	if (ses->server->negflavor == CIFS_NEGFLAVOR_EXTENDED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		memcpy(ntlmv2->challenge.key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		       ses->ntlmssp->cryptkey, CIFS_SERVER_CHALLENGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 		memcpy(ntlmv2->challenge.key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 		       ses->server->cryptkey, CIFS_SERVER_CHALLENGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	rc = crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 				 ntlmv2->challenge.key, hash_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 		cifs_dbg(VFS, "%s: Could not update with response\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	/* Note that the MD5 digest over writes anon.challenge_key.key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 				ntlmv2->ntlmv2_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 		cifs_dbg(VFS, "%s: Could not generate md5 hash\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	int baselen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	unsigned int tilen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	struct ntlmv2_resp *ntlmv2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	char ntlmv2_hash[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	unsigned char *tiblob = NULL; /* target info blob */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	__le64 rsp_timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	if (ses->server->negflavor == CIFS_NEGFLAVOR_EXTENDED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		if (!ses->domainName) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 			if (ses->domainAuto) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 				rc = find_domain_name(ses, nls_cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 				if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 					cifs_dbg(VFS, "error %d finding domain name\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 						 rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 					goto setup_ntlmv2_rsp_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 				ses->domainName = kstrdup("", GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 		rc = build_avpair_blob(ses, nls_cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 			cifs_dbg(VFS, "error %d building av pair blob\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 			goto setup_ntlmv2_rsp_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	/* Must be within 5 minutes of the server (or in range +/-2h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	 * in case of Mac OS X), so simply carry over server timestamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	 * (as Windows 7 does)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	rsp_timestamp = find_timestamp(ses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	baselen = CIFS_SESS_KEY_SIZE + sizeof(struct ntlmv2_resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	tilen = ses->auth_key.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	tiblob = ses->auth_key.response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	ses->auth_key.response = kmalloc(baselen + tilen, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	if (!ses->auth_key.response) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 		ses->auth_key.len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 		goto setup_ntlmv2_rsp_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	ses->auth_key.len += baselen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	ntlmv2 = (struct ntlmv2_resp *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 			(ses->auth_key.response + CIFS_SESS_KEY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	ntlmv2->blob_signature = cpu_to_le32(0x00000101);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	ntlmv2->reserved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	ntlmv2->time = rsp_timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	get_random_bytes(&ntlmv2->client_chal, sizeof(ntlmv2->client_chal));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	ntlmv2->reserved2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	memcpy(ses->auth_key.response + baselen, tiblob, tilen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	mutex_lock(&ses->server->srv_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 	rc = cifs_alloc_hash("hmac(md5)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 			     &ses->server->secmech.hmacmd5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 			     &ses->server->secmech.sdeschmacmd5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	/* calculate ntlmv2_hash */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	rc = calc_ntlmv2_hash(ses, ntlmv2_hash, nls_cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 		cifs_dbg(VFS, "Could not get v2 hash rc %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	/* calculate first part of the client response (CR1) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	rc = CalcNTLMv2_response(ses, ntlmv2_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 		cifs_dbg(VFS, "Could not calculate CR1 rc: %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	/* now calculate the session key for NTLMv2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	rc = crypto_shash_setkey(ses->server->secmech.hmacmd5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 		ntlmv2_hash, CIFS_HMAC_MD5_HASH_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 		cifs_dbg(VFS, "%s: Could not set NTLMV2 Hash as a key\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 			 __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	rc = crypto_shash_init(&ses->server->secmech.sdeschmacmd5->shash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 		cifs_dbg(VFS, "%s: Could not init hmacmd5\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	rc = crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 		ntlmv2->ntlmv2_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 		CIFS_HMAC_MD5_HASH_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 		cifs_dbg(VFS, "%s: Could not update with response\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 	rc = crypto_shash_final(&ses->server->secmech.sdeschmacmd5->shash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 		ses->auth_key.response);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 		cifs_dbg(VFS, "%s: Could not generate md5 hash\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 	mutex_unlock(&ses->server->srv_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) setup_ntlmv2_rsp_ret:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	kfree(tiblob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) calc_seckey(struct cifs_ses *ses)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 	unsigned char sec_key[CIFS_SESS_KEY_SIZE]; /* a nonce */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 	struct arc4_ctx *ctx_arc4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 	if (fips_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 	get_random_bytes(sec_key, CIFS_SESS_KEY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 	ctx_arc4 = kmalloc(sizeof(*ctx_arc4), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	if (!ctx_arc4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 		cifs_dbg(VFS, "Could not allocate arc4 context\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	arc4_setkey(ctx_arc4, ses->auth_key.response, CIFS_SESS_KEY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 	arc4_crypt(ctx_arc4, ses->ntlmssp->ciphertext, sec_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 		   CIFS_CPHTXT_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 	/* make secondary_key/nonce as session key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 	memcpy(ses->auth_key.response, sec_key, CIFS_SESS_KEY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 	/* and make len as that of session key only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 	ses->auth_key.len = CIFS_SESS_KEY_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 	memzero_explicit(sec_key, CIFS_SESS_KEY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 	kfree_sensitive(ctx_arc4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) cifs_crypto_secmech_release(struct TCP_Server_Info *server)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 	if (server->secmech.cmacaes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 		crypto_free_shash(server->secmech.cmacaes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 		server->secmech.cmacaes = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 	if (server->secmech.hmacsha256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 		crypto_free_shash(server->secmech.hmacsha256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 		server->secmech.hmacsha256 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 	if (server->secmech.md5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 		crypto_free_shash(server->secmech.md5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 		server->secmech.md5 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 	if (server->secmech.sha512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 		crypto_free_shash(server->secmech.sha512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 		server->secmech.sha512 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 	if (server->secmech.hmacmd5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 		crypto_free_shash(server->secmech.hmacmd5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 		server->secmech.hmacmd5 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 	if (server->secmech.ccmaesencrypt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 		crypto_free_aead(server->secmech.ccmaesencrypt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 		server->secmech.ccmaesencrypt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 	if (server->secmech.ccmaesdecrypt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 		crypto_free_aead(server->secmech.ccmaesdecrypt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 		server->secmech.ccmaesdecrypt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 	kfree(server->secmech.sdesccmacaes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 	server->secmech.sdesccmacaes = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 	kfree(server->secmech.sdeschmacsha256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 	server->secmech.sdeschmacsha256 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) 	kfree(server->secmech.sdeschmacmd5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 	server->secmech.sdeschmacmd5 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) 	kfree(server->secmech.sdescmd5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 	server->secmech.sdescmd5 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 	kfree(server->secmech.sdescsha512);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 	server->secmech.sdescsha512 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) }