A zero-length application_data record decrypts to full_len == 0,
so tls_sw_splice_read() splices zero bytes and returns zero. A zero
return from a splice read means EOF, and the caller tears down a
connection that is still live.

Consume the record and fetch the next one, as tls_sw_recvmsg()
does. Test for a pending signal before each retry, so a peer that
streams empty records cannot make the splicing task unkillable.

When an empty record precedes a close_notify, splice(2) now returns
-EINVAL from the control-record test instead of the false EOF it
returned before. A splice that reaches an alert record already
reports -EINVAL.

Fixes: c46234ebb4d1 ("tls: RX path for ktls")
Reported-by: Sabrina Dubroca <[email protected]>
Closes: https://lore.kernel.org/netdev/akaoXcfamBp8_mYe@krikkit/
Signed-off-by: Chuck Lever <[email protected]>
---
 net/tls/tls_sw.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index ee50b9028264..79a807e51bc7 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -2018,6 +2018,7 @@ ssize_t tls_sw_splice_read(struct socket *sock,  loff_t 
*ppos,
        struct sock *sk = sock->sk;
        struct tls_msg *tlm;
        struct sk_buff *skb;
+       bool released = true;
        ssize_t copied = 0;
        int chunk;
        int err;
@@ -2031,13 +2032,14 @@ ssize_t tls_sw_splice_read(struct socket *sock,  loff_t 
*ppos,
        if (err)
                goto splice_read_end;
 
+retry:
        if (!skb_queue_empty(&ctx->rx_list)) {
                skb = __skb_dequeue(&ctx->rx_list);
        } else {
                struct tls_decrypt_arg darg;
 
                err = tls_rx_rec_wait(sk, flags & SPLICE_F_NONBLOCK,
-                                     true, false);
+                                     released, false);
                if (err <= 0)
                        goto splice_read_end;
 
@@ -2049,6 +2051,9 @@ ssize_t tls_sw_splice_read(struct socket *sock,  loff_t 
*ppos,
 
                tls_rx_rec_done(ctx);
                skb = darg.skb;
+
+               /* The retry's wait runs with the socket lock still held. */
+               released = false;
        }
 
        rxm = strp_msg(skb);
@@ -2060,6 +2065,19 @@ ssize_t tls_sw_splice_read(struct socket *sock,  loff_t 
*ppos,
                goto splice_requeue;
        }
 
+       /* Splicing zero bytes reads as EOF to the caller. */
+       if (rxm->full_len == 0) {
+               consume_skb(skb);
+               if (signal_pending(current)) {
+                       long timeo;
+
+                       timeo = sock_rcvtimeo(sk, flags & SPLICE_F_NONBLOCK);
+                       err = sock_intr_errno(timeo);
+                       goto splice_read_end;
+               }
+               goto retry;
+       }
+
        chunk = min_t(unsigned int, rxm->full_len, len);
        copied = skb_splice_bits(skb, sk, rxm->offset, pipe, chunk, flags);
        if (copied < 0)

-- 
2.55.0


Reply via email to