Skip to content

Commit bce037a

Browse files
committed
tls: fix race between tx work scheduling and socket close
jira VULN-8187 cve CVE-2024-26585 commit-author Jakub Kicinski <kuba@kernel.org> commit e01e393 upstream-diff No actual difference from the upstream patch, but required manual conflicts resolution due to differences in neighbouring code Similarly to previous commit, the submitting thread (recvmsg/sendmsg) may exit as soon as the async crypto handler calls complete(). Reorder scheduling the work before calling complete(). This seems more logical in the first place, as it's the inverse order of what the submitting thread will do. Reported-by: valis <sec@valis.email> Fixes: a42055e ("net/tls: Add support for async encryption of records for performance") Signed-off-by: Jakub Kicinski <kuba@kernel.org> Reviewed-by: Simon Horman <horms@kernel.org> Reviewed-by: Sabrina Dubroca <sd@queasysnail.net> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit e01e393) Signed-off-by: Marcin Wcisło <marcin.wcislo@conclusive.pl>
1 parent b4f997e commit bce037a

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

net/tls/tls_sw.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ static void tls_encrypt_done(struct crypto_async_request *req, int err)
427427
struct scatterlist *sge;
428428
struct sk_msg *msg_en;
429429
struct tls_rec *rec;
430-
bool ready = false;
431430
int pending;
432431

433432
rec = container_of(aead_req, struct tls_rec, aead_req);
@@ -459,8 +458,12 @@ static void tls_encrypt_done(struct crypto_async_request *req, int err)
459458
/* If received record is at head of tx_list, schedule tx */
460459
first_rec = list_first_entry(&ctx->tx_list,
461460
struct tls_rec, list);
462-
if (rec == first_rec)
463-
ready = true;
461+
if (rec == first_rec) {
462+
/* Schedule the transmission */
463+
if (!test_and_set_bit(BIT_TX_SCHEDULED,
464+
&ctx->tx_bitmask))
465+
schedule_delayed_work(&ctx->tx_work.work, 1);
466+
}
464467
}
465468

466469
spin_lock_bh(&ctx->encrypt_compl_lock);
@@ -469,13 +472,6 @@ static void tls_encrypt_done(struct crypto_async_request *req, int err)
469472
if (!pending && ctx->async_notify)
470473
complete(&ctx->async_wait.completion);
471474
spin_unlock_bh(&ctx->encrypt_compl_lock);
472-
473-
if (!ready)
474-
return;
475-
476-
/* Schedule the transmission */
477-
if (!test_and_set_bit(BIT_TX_SCHEDULED, &ctx->tx_bitmask))
478-
schedule_delayed_work(&ctx->tx_work.work, 1);
479475
}
480476

481477
static int tls_do_encryption(struct sock *sk,

0 commit comments

Comments
 (0)