Skip to content

Commit f9929ef

Browse files
namjaejeonSteve French
authored andcommitted
ksmbd: add support for key exchange
When mounting cifs client, can see the following warning message. CIFS: decode_ntlmssp_challenge: authentication has been weakened as server does not support key exchange To remove this warning message, Add support for key exchange feature to ksmbd. This patch decrypts 16-byte ciphertext value sent by the client using RC4 with session key. The decrypted value is the recovered secondary key that will use instead of the session key for signing and sealing. Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent deae24b commit f9929ef

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

fs/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ source "fs/ksmbd/Kconfig"
369369

370370
config SMBFS_COMMON
371371
tristate
372-
default y if CIFS=y
373-
default m if CIFS=m
372+
default y if CIFS=y || SMB_SERVER=y
373+
default m if CIFS=m || SMB_SERVER=m
374374

375375
source "fs/coda/Kconfig"
376376
source "fs/afs/Kconfig"

fs/ksmbd/auth.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "mgmt/user_config.h"
3030
#include "crypto_ctx.h"
3131
#include "transport_ipc.h"
32+
#include "../smbfs_common/arc4.h"
3233

3334
/*
3435
* Fixed format data defining GSS header and fixed string
@@ -336,6 +337,29 @@ int ksmbd_decode_ntlmssp_auth_blob(struct authenticate_message *authblob,
336337
nt_len - CIFS_ENCPWD_SIZE,
337338
domain_name, conn->ntlmssp.cryptkey);
338339
kfree(domain_name);
340+
341+
/* The recovered secondary session key */
342+
if (conn->ntlmssp.client_flags & NTLMSSP_NEGOTIATE_KEY_XCH) {
343+
struct arc4_ctx *ctx_arc4;
344+
unsigned int sess_key_off, sess_key_len;
345+
346+
sess_key_off = le32_to_cpu(authblob->SessionKey.BufferOffset);
347+
sess_key_len = le16_to_cpu(authblob->SessionKey.Length);
348+
349+
if (blob_len < (u64)sess_key_off + sess_key_len)
350+
return -EINVAL;
351+
352+
ctx_arc4 = kmalloc(sizeof(*ctx_arc4), GFP_KERNEL);
353+
if (!ctx_arc4)
354+
return -ENOMEM;
355+
356+
cifs_arc4_setkey(ctx_arc4, sess->sess_key,
357+
SMB2_NTLMV2_SESSKEY_SIZE);
358+
cifs_arc4_crypt(ctx_arc4, sess->sess_key,
359+
(char *)authblob + sess_key_off, sess_key_len);
360+
kfree_sensitive(ctx_arc4);
361+
}
362+
339363
return ret;
340364
}
341365

@@ -408,6 +432,9 @@ ksmbd_build_ntlmssp_challenge_blob(struct challenge_message *chgblob,
408432
(cflags & NTLMSSP_NEGOTIATE_EXTENDED_SEC))
409433
flags |= NTLMSSP_NEGOTIATE_EXTENDED_SEC;
410434

435+
if (cflags & NTLMSSP_NEGOTIATE_KEY_XCH)
436+
flags |= NTLMSSP_NEGOTIATE_KEY_XCH;
437+
411438
chgblob->NegotiateFlags = cpu_to_le32(flags);
412439
len = strlen(ksmbd_netbios_name());
413440
name = kmalloc(2 + UNICODE_LEN(len), GFP_KERNEL);

0 commit comments

Comments
 (0)