Skip to content

Commit 7a29b11

Browse files
committed
Merge tag '5.16-rc5-ksmbd-fixes' of git://git.samba.org/ksmbd
Pull ksmbd fixes from Steve French: "Three ksmbd fixes, all for stable as well. Two fix potential unitialized memory and one fixes a security problem where encryption is unitentionally disabled from some clients" * tag '5.16-rc5-ksmbd-fixes' of git://git.samba.org/ksmbd: ksmbd: disable SMB2_GLOBAL_CAP_ENCRYPTION for SMB 3.1.1 ksmbd: fix uninitialized symbol 'pntsd_size' ksmbd: fix error code in ndr_read_int32()
2 parents 95b4011 + 83912d6 commit 7a29b11

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

fs/ksmbd/ndr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static int ndr_read_int16(struct ndr *n, __u16 *value)
148148
static int ndr_read_int32(struct ndr *n, __u32 *value)
149149
{
150150
if (n->offset + sizeof(__u32) > n->length)
151-
return 0;
151+
return -EINVAL;
152152

153153
if (value)
154154
*value = le32_to_cpu(*(__le32 *)ndr_get_field(n));

fs/ksmbd/smb2ops.c

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

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

fs/ksmbd/smb2pdu.c

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

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

1472-
if (conn->vals->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION &&
1473-
conn->ops->generate_encryptionkey &&
1491+
if (smb3_encryption_negotiated(conn) &&
14741492
!(req->Flags & SMB2_SESSION_REQ_FLAG_BINDING)) {
14751493
rc = conn->ops->generate_encryptionkey(sess);
14761494
if (rc) {
@@ -1559,8 +1577,7 @@ static int krb5_authenticate(struct ksmbd_work *work)
15591577
(req->SecurityMode & SMB2_NEGOTIATE_SIGNING_REQUIRED))
15601578
sess->sign = true;
15611579

1562-
if ((conn->vals->capabilities & SMB2_GLOBAL_CAP_ENCRYPTION) &&
1563-
conn->ops->generate_encryptionkey) {
1580+
if (smb3_encryption_negotiated(conn)) {
15641581
retval = conn->ops->generate_encryptionkey(sess);
15651582
if (retval) {
15661583
ksmbd_debug(SMB,
@@ -2962,6 +2979,10 @@ int smb2_open(struct ksmbd_work *work)
29622979
&pntsd_size, &fattr);
29632980
posix_acl_release(fattr.cf_acls);
29642981
posix_acl_release(fattr.cf_dacls);
2982+
if (rc) {
2983+
kfree(pntsd);
2984+
goto err_out;
2985+
}
29652986

29662987
rc = ksmbd_vfs_set_sd_xattr(conn,
29672988
user_ns,

0 commit comments

Comments
 (0)