Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

cifs: have calc_lanman_hash take more granular args

cifs: have calc_lanman_hash take more granular args

We need to use this routine to encrypt passwords associated with the
tcon too. Don't assume that the password will be attached to the
smb_session.

Also, make some of the values in the lower encryption functions
const since they aren't changed.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Steve French <sfrench@us.ibm.com>

authored by

Jeff Layton and committed by
Steve French
4e53a3fb 55162dec

+33 -25
+13 -15
fs/cifs/cifsencrypt.c
··· 37 37 38 38 extern void mdfour(unsigned char *out, unsigned char *in, int n); 39 39 extern void E_md4hash(const unsigned char *passwd, unsigned char *p16); 40 - extern void SMBencrypt(unsigned char *passwd, unsigned char *c8, 40 + extern void SMBencrypt(unsigned char *passwd, const unsigned char *c8, 41 41 unsigned char *p24); 42 42 43 43 static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu, ··· 280 280 } 281 281 282 282 #ifdef CONFIG_CIFS_WEAK_PW_HASH 283 - void calc_lanman_hash(struct cifsSesInfo *ses, char *lnm_session_key) 283 + void calc_lanman_hash(const char *password, const char *cryptkey, bool encrypt, 284 + char *lnm_session_key) 284 285 { 285 286 int i; 286 287 char password_with_pad[CIFS_ENCPWD_SIZE]; 287 288 288 - if (ses->server == NULL) 289 - return; 290 - 291 289 memset(password_with_pad, 0, CIFS_ENCPWD_SIZE); 292 - if (ses->password) 293 - strncpy(password_with_pad, ses->password, CIFS_ENCPWD_SIZE); 290 + if (password) 291 + strncpy(password_with_pad, password, CIFS_ENCPWD_SIZE); 294 292 295 - if ((ses->server->secMode & SECMODE_PW_ENCRYPT) == 0) 296 - if (extended_security & CIFSSEC_MAY_PLNTXT) { 297 - memset(lnm_session_key, 0, CIFS_SESS_KEY_SIZE); 298 - memcpy(lnm_session_key, password_with_pad, 299 - CIFS_ENCPWD_SIZE); 300 - return; 301 - } 293 + if (!encrypt && extended_security & CIFSSEC_MAY_PLNTXT) { 294 + memset(lnm_session_key, 0, CIFS_SESS_KEY_SIZE); 295 + memcpy(lnm_session_key, password_with_pad, 296 + CIFS_ENCPWD_SIZE); 297 + return; 298 + } 302 299 303 300 /* calculate old style session key */ 304 301 /* calling toupper is less broken than repeatedly ··· 311 314 for (i = 0; i < CIFS_ENCPWD_SIZE; i++) 312 315 password_with_pad[i] = toupper(password_with_pad[i]); 313 316 314 - SMBencrypt(password_with_pad, ses->server->cryptKey, lnm_session_key); 317 + SMBencrypt(password_with_pad, cryptkey, lnm_session_key); 318 + 315 319 /* clear password before we return/free memory */ 316 320 memset(password_with_pad, 0, CIFS_ENCPWD_SIZE); 317 321 }
+2 -1
fs/cifs/cifsencrypt.h
··· 26 26 extern void mdfour(unsigned char *out, unsigned char *in, int n); 27 27 /* smbdes.c */ 28 28 extern void E_P16(unsigned char *p14, unsigned char *p16); 29 - extern void E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24); 29 + extern void E_P24(unsigned char *p21, const unsigned char *c8, 30 + unsigned char *p24); 30 31 31 32 32 33
+2 -1
fs/cifs/cifsproto.h
··· 330 330 extern void setup_ntlmv2_rsp(struct cifsSesInfo *, char *, 331 331 const struct nls_table *); 332 332 #ifdef CONFIG_CIFS_WEAK_PW_HASH 333 - extern void calc_lanman_hash(struct cifsSesInfo *ses, char *lnm_session_key); 333 + extern void calc_lanman_hash(const char *password, const char *cryptkey, 334 + bool encrypt, char *lnm_session_key); 334 335 #endif /* CIFS_WEAK_PW_HASH */ 335 336 extern int CIFSSMBCopy(int xid, 336 337 struct cifsTconInfo *source_tcon,
+4 -1
fs/cifs/connect.c
··· 3533 3533 #ifdef CONFIG_CIFS_WEAK_PW_HASH 3534 3534 if ((extended_security & CIFSSEC_MAY_LANMAN) && 3535 3535 (ses->server->secType == LANMAN)) 3536 - calc_lanman_hash(ses, bcc_ptr); 3536 + calc_lanman_hash(ses->password, ses->server->cryptKey, 3537 + ses->server->secMode & 3538 + SECMODE_PW_ENCRYPT ? true : false, 3539 + bcc_ptr); 3537 3540 else 3538 3541 #endif /* CIFS_WEAK_PW_HASH */ 3539 3542 SMBNTencrypt(ses->password,
+4 -1
fs/cifs/sess.c
··· 417 417 /* BB calculate hash with password */ 418 418 /* and copy into bcc */ 419 419 420 - calc_lanman_hash(ses, lnm_session_key); 420 + calc_lanman_hash(ses->password, ses->server->cryptKey, 421 + ses->server->secMode & SECMODE_PW_ENCRYPT ? 422 + true : false, lnm_session_key); 423 + 421 424 ses->flags |= CIFS_SES_LANMAN; 422 425 memcpy(bcc_ptr, (char *)lnm_session_key, CIFS_SESS_KEY_SIZE); 423 426 bcc_ptr += CIFS_SESS_KEY_SIZE;
+3 -2
fs/cifs/smbdes.c
··· 318 318 } 319 319 320 320 static void 321 - smbhash(unsigned char *out, unsigned char *in, unsigned char *key, int forw) 321 + smbhash(unsigned char *out, const unsigned char *in, unsigned char *key, 322 + int forw) 322 323 { 323 324 int i; 324 325 char *outb; /* outb[64] */ ··· 364 363 } 365 364 366 365 void 367 - E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24) 366 + E_P24(unsigned char *p21, const unsigned char *c8, unsigned char *p24) 368 367 { 369 368 smbhash(p24, c8, p21, 1); 370 369 smbhash(p24 + 8, c8, p21 + 7, 1);
+5 -4
fs/cifs/smbencrypt.c
··· 49 49 50 50 /*The following definitions come from libsmb/smbencrypt.c */ 51 51 52 - void SMBencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24); 52 + void SMBencrypt(unsigned char *passwd, const unsigned char *c8, 53 + unsigned char *p24); 53 54 void E_md4hash(const unsigned char *passwd, unsigned char *p16); 54 - static void SMBOWFencrypt(unsigned char passwd[16], unsigned char *c8, 55 + static void SMBOWFencrypt(unsigned char passwd[16], const unsigned char *c8, 55 56 unsigned char p24[24]); 56 57 void SMBNTencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24); 57 58 ··· 62 61 encrypted password into p24 */ 63 62 /* Note that password must be uppercased and null terminated */ 64 63 void 65 - SMBencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24) 64 + SMBencrypt(unsigned char *passwd, const unsigned char *c8, unsigned char *p24) 66 65 { 67 66 unsigned char p14[15], p21[21]; 68 67 ··· 213 212 214 213 /* Does the des encryption from the NT or LM MD4 hash. */ 215 214 static void 216 - SMBOWFencrypt(unsigned char passwd[16], unsigned char *c8, 215 + SMBOWFencrypt(unsigned char passwd[16], const unsigned char *c8, 217 216 unsigned char p24[24]) 218 217 { 219 218 unsigned char p21[21];