hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/tls/tls_sw.c
....@@ -810,7 +810,7 @@
810810 psock = sk_psock_get(sk);
811811 if (!psock || !policy) {
812812 err = tls_push_record(sk, flags, record_type);
813
- if (err && sk->sk_err == EBADMSG) {
813
+ if (err && err != -EINPROGRESS && sk->sk_err == EBADMSG) {
814814 *copied -= sk_msg_free(sk, msg);
815815 tls_free_open_rec(sk);
816816 err = -sk->sk_err;
....@@ -839,7 +839,7 @@
839839 switch (psock->eval) {
840840 case __SK_PASS:
841841 err = tls_push_record(sk, flags, record_type);
842
- if (err && sk->sk_err == EBADMSG) {
842
+ if (err && err != -EINPROGRESS && sk->sk_err == EBADMSG) {
843843 *copied -= sk_msg_free(sk, msg);
844844 tls_free_open_rec(sk);
845845 err = -sk->sk_err;
....@@ -949,7 +949,9 @@
949949 MSG_CMSG_COMPAT))
950950 return -EOPNOTSUPP;
951951
952
- mutex_lock(&tls_ctx->tx_lock);
952
+ ret = mutex_lock_interruptible(&tls_ctx->tx_lock);
953
+ if (ret)
954
+ return ret;
953955 lock_sock(sk);
954956
955957 if (unlikely(msg->msg_controllen)) {
....@@ -1283,7 +1285,9 @@
12831285 MSG_SENDPAGE_NOTLAST | MSG_SENDPAGE_NOPOLICY))
12841286 return -EOPNOTSUPP;
12851287
1286
- mutex_lock(&tls_ctx->tx_lock);
1288
+ ret = mutex_lock_interruptible(&tls_ctx->tx_lock);
1289
+ if (ret)
1290
+ return ret;
12871291 lock_sock(sk);
12881292 ret = tls_sw_do_sendpage(sk, page, offset, size, flags);
12891293 release_sock(sk);
....@@ -2266,11 +2270,19 @@
22662270
22672271 if (!test_and_clear_bit(BIT_TX_SCHEDULED, &ctx->tx_bitmask))
22682272 return;
2269
- mutex_lock(&tls_ctx->tx_lock);
2270
- lock_sock(sk);
2271
- tls_tx_records(sk, -1);
2272
- release_sock(sk);
2273
- mutex_unlock(&tls_ctx->tx_lock);
2273
+
2274
+ if (mutex_trylock(&tls_ctx->tx_lock)) {
2275
+ lock_sock(sk);
2276
+ tls_tx_records(sk, -1);
2277
+ release_sock(sk);
2278
+ mutex_unlock(&tls_ctx->tx_lock);
2279
+ } else if (!test_and_set_bit(BIT_TX_SCHEDULED, &ctx->tx_bitmask)) {
2280
+ /* Someone is holding the tx_lock, they will likely run Tx
2281
+ * and cancel the work on their way out of the lock section.
2282
+ * Schedule a long delay just in case.
2283
+ */
2284
+ schedule_delayed_work(&ctx->tx_work.work, msecs_to_jiffies(10));
2285
+ }
22742286 }
22752287
22762288 void tls_sw_write_space(struct sock *sk, struct tls_context *ctx)