Skip to content

Commit e01e393

Browse files
kuba-moodavem330
authored andcommitted
tls: fix race between tx work scheduling and socket close
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>
1 parent aec7961 commit e01e393

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
@@ -447,7 +447,6 @@ static void tls_encrypt_done(void *data, int err)
447447
struct tls_rec *rec = data;
448448
struct scatterlist *sge;
449449
struct sk_msg *msg_en;
450-
bool ready = false;
451450
struct sock *sk;
452451

453452
msg_en = &rec->msg_encrypted;
@@ -483,19 +482,16 @@ static void tls_encrypt_done(void *data, int err)
483482
/* If received record is at head of tx_list, schedule tx */
484483
first_rec = list_first_entry(&ctx->tx_list,
485484
struct tls_rec, list);
486-
if (rec == first_rec)
487-
ready = true;
485+
if (rec == first_rec) {
486+
/* Schedule the transmission */
487+
if (!test_and_set_bit(BIT_TX_SCHEDULED,
488+
&ctx->tx_bitmask))
489+
schedule_delayed_work(&ctx->tx_work.work, 1);
490+
}
488491
}
489492

490493
if (atomic_dec_and_test(&ctx->encrypt_pending))
491494
complete(&ctx->async_wait.completion);
492-
493-
if (!ready)
494-
return;
495-
496-
/* Schedule the transmission */
497-
if (!test_and_set_bit(BIT_TX_SCHEDULED, &ctx->tx_bitmask))
498-
schedule_delayed_work(&ctx->tx_work.work, 1);
499495
}
500496

501497
static int tls_encrypt_async_wait(struct tls_sw_context_tx *ctx)

0 commit comments

Comments
 (0)