Skip to content

Commit a2c144d

Browse files
socram8888gregkh
authored andcommitted
ksmbd: disable SMB2_GLOBAL_CAP_ENCRYPTION for SMB 3.1.1
commit 83912d6 upstream. According to the official Microsoft MS-SMB2 document section 3.3.5.4, this flag should be used only for 3.0 and 3.0.2 dialects. Setting it for 3.1.1 is a violation of the specification. This causes my Windows 10 client to detect an anomaly in the negotiation, and disable encryption entirely despite being explicitly enabled in ksmbd, causing all data transfers to go in plain text. Fixes: e2f3448 ("cifsd: add server-side procedures for SMB3") Cc: stable@vger.kernel.org # v5.15 Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Marcos Del Sol Vives <marcos@orca.pet> Signed-off-by: Steve French <stfrench@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f43ba86 commit a2c144d

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

fs/ksmbd/smb2ops.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,6 @@ int init_smb3_11_server(struct ksmbd_conn *conn)
272272
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
273273
conn->vals->capabilities |= SMB2_GLOBAL_CAP_LEASING;
274274

275-
if (conn->cipher_type)
276-
conn->vals->capabilities |= SMB2_GLOBAL_CAP_ENCRYPTION;
277-
278275
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB3_MULTICHANNEL)
279276
conn->vals->capabilities |= SMB2_GLOBAL_CAP_MULTI_CHANNEL;
280277

fs/ksmbd/smb2pdu.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,25 @@ static void decode_encrypt_ctxt(struct ksmbd_conn *conn,
917917
}
918918
}
919919

920+
/**
921+
* smb3_encryption_negotiated() - checks if server and client agreed on enabling encryption
922+
* @conn: smb connection
923+
*
924+
* Return: true if connection should be encrypted, else false
925+
*/
926+
static bool smb3_encryption_negotiated(struct ksmbd_conn *conn)
927+
{
928+
if (!conn->ops->generate_encryptionkey)
929+
return false;
930+
931+
/*
932+
* SMB 3.0 and 3.0.2 dialects use the SMB2_GLOBAL_CAP_ENCRYPTION flag.
933+
* SMB 3.1.1 uses the cipher_type field.
934+
*/
935+
return (conn->vals->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION) ||
936+
conn->cipher_type;
937+
}
938+
920939
static void decode_compress_ctxt(struct ksmbd_conn *conn,
921940
struct smb2_compression_ctx *pneg_ctxt)
922941
{
@@ -1471,8 +1490,7 @@ static int ntlm_authenticate(struct ksmbd_work *work)
14711490
(req->SecurityMode & SMB2_NEGOTIATE_SIGNING_REQUIRED))
14721491
sess->sign = true;
14731492

1474-
if (conn->vals->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION &&
1475-
conn->ops->generate_encryptionkey &&
1493+
if (smb3_encryption_negotiated(conn) &&
14761494
!(req->Flags & SMB2_SESSION_REQ_FLAG_BINDING)) {
14771495
rc = conn->ops->generate_encryptionkey(sess);
14781496
if (rc) {
@@ -1562,8 +1580,7 @@ static int krb5_authenticate(struct ksmbd_work *work)
15621580
(req->SecurityMode & SMB2_NEGOTIATE_SIGNING_REQUIRED))
15631581
sess->sign = true;
15641582

1565-
if ((conn->vals->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION) &&
1566-
conn->ops->generate_encryptionkey) {
1583+
if (smb3_encryption_negotiated(conn)) {
15671584
retval = conn->ops->generate_encryptionkey(sess);
15681585
if (retval) {
15691586
ksmbd_debug(SMB,

0 commit comments

Comments
 (0)