From: Chuck Lever 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_read_sock() does. The cap on consecutive empty records bounds the loop. When an empty record precedes a close_notify, splice(2) now returns -EINVAL from the control-record test instead of a false EOF. A splice that reaches an alert record already reports -EINVAL. Fixes: c46234ebb4d1 ("tls: RX path for ktls") Reported-by: Sabrina Dubroca Closes: https://lore.kernel.org/netdev/akaoXcfamBp8_mYe@krikkit/ Signed-off-by: Chuck Lever Signed-off-by: Jakub Kicinski --- Jakub: - rewrite as a loop to avoid the non-error-handling goto --- net/tls/tls_sw.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index adf3b26b8a75..b05b9e76bd25 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -2044,32 +2044,40 @@ ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos, if (err) goto splice_read_end; - if (!skb_queue_empty(&ctx->rx_list)) { - skb = __skb_dequeue(&ctx->rx_list); - } else { - struct tls_decrypt_arg darg; + for (;;) { + 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, nonblock, true, false); - if (err <= 0) - goto splice_read_end; + err = tls_rx_rec_wait(sk, nonblock, true, false); + if (err <= 0) + goto splice_read_end; - memset(&darg.inargs, 0, sizeof(darg.inargs)); + memset(&darg.inargs, 0, sizeof(darg.inargs)); - err = tls_rx_one_record(sk, NULL, &darg); - if (err < 0) - goto splice_read_end; + err = tls_rx_one_record(sk, NULL, &darg); + if (err < 0) + goto splice_read_end; - tls_rx_rec_done(ctx); - skb = darg.skb; - } + tls_rx_rec_done(ctx); + skb = darg.skb; + } - rxm = strp_msg(skb); - tlm = tls_msg(skb); + rxm = strp_msg(skb); + tlm = tls_msg(skb); - /* splice does not support reading control messages */ - if (tlm->control != TLS_RECORD_TYPE_DATA) { - err = -EINVAL; - goto splice_requeue; + /* splice does not support reading control messages */ + if (tlm->control != TLS_RECORD_TYPE_DATA) { + err = -EINVAL; + goto splice_requeue; + } + + /* Splicing zero bytes would read as EOF */ + if (rxm->full_len) + break; + + consume_skb(skb); } chunk = min_t(unsigned int, rxm->full_len, len); -- 2.56.0