Skip to content

Commit 7b43233

Browse files
namjaejeonSteve French
authored andcommitted
ksmbd: fix deadlock in ksmbd_find_crypto_ctx()
Deadlock is triggered by sending multiple concurrent session setup requests. It should be reused after releasing when getting ctx for crypto. Multiple consecutive ctx uses cause deadlock while waiting for releasing due to the limited number of ctx. Cc: stable@vger.kernel.org Reported-by: zdi-disclosures@trendmicro.com # ZDI-CAN-20591 Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent b096d97 commit 7b43233

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

fs/ksmbd/auth.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,22 +221,22 @@ int ksmbd_auth_ntlmv2(struct ksmbd_conn *conn, struct ksmbd_session *sess,
221221
{
222222
char ntlmv2_hash[CIFS_ENCPWD_SIZE];
223223
char ntlmv2_rsp[CIFS_HMAC_MD5_HASH_SIZE];
224-
struct ksmbd_crypto_ctx *ctx;
224+
struct ksmbd_crypto_ctx *ctx = NULL;
225225
char *construct = NULL;
226226
int rc, len;
227227

228-
ctx = ksmbd_crypto_ctx_find_hmacmd5();
229-
if (!ctx) {
230-
ksmbd_debug(AUTH, "could not crypto alloc hmacmd5\n");
231-
return -ENOMEM;
232-
}
233-
234228
rc = calc_ntlmv2_hash(conn, sess, ntlmv2_hash, domain_name);
235229
if (rc) {
236230
ksmbd_debug(AUTH, "could not get v2 hash rc %d\n", rc);
237231
goto out;
238232
}
239233

234+
ctx = ksmbd_crypto_ctx_find_hmacmd5();
235+
if (!ctx) {
236+
ksmbd_debug(AUTH, "could not crypto alloc hmacmd5\n");
237+
return -ENOMEM;
238+
}
239+
240240
rc = crypto_shash_setkey(CRYPTO_HMACMD5_TFM(ctx),
241241
ntlmv2_hash,
242242
CIFS_HMAC_MD5_HASH_SIZE);
@@ -272,6 +272,8 @@ int ksmbd_auth_ntlmv2(struct ksmbd_conn *conn, struct ksmbd_session *sess,
272272
ksmbd_debug(AUTH, "Could not generate md5 hash\n");
273273
goto out;
274274
}
275+
ksmbd_release_crypto_ctx(ctx);
276+
ctx = NULL;
275277

276278
rc = ksmbd_gen_sess_key(sess, ntlmv2_hash, ntlmv2_rsp);
277279
if (rc) {
@@ -282,7 +284,8 @@ int ksmbd_auth_ntlmv2(struct ksmbd_conn *conn, struct ksmbd_session *sess,
282284
if (memcmp(ntlmv2->ntlmv2_hash, ntlmv2_rsp, CIFS_HMAC_MD5_HASH_SIZE) != 0)
283285
rc = -EINVAL;
284286
out:
285-
ksmbd_release_crypto_ctx(ctx);
287+
if (ctx)
288+
ksmbd_release_crypto_ctx(ctx);
286289
kfree(construct);
287290
return rc;
288291
}

0 commit comments

Comments
 (0)