From: Hengyu Liang <hengyul@cs.unc.edu>
To: John Fastabend <john.fastabend@gmail.com>,
Jakub Kicinski <kuba@kernel.org>,
Sabrina Dubroca <sd@queasysnail.net>
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Benjamin Coddington <bcodding@hammerspace.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net] tls: fix send() returning success after the TCP send failed
Date: Fri, 13 Nov 2026 14:36:48 -0500 [thread overview]
Message-ID: <20261113193649.3822306-1-hengyul@cs.unc.edu> (raw)
Commit b341ca51d267 ("tls: Fix tls_sw_sendmsg error handling") made
tls_tx_records() pass the error of the TCP send to tls_err_abort()
instead of -EBADMSG.
However, bpf_exec_tx_verdict() still looks for EBADMSG in sk_err to
tell that the record was not sent. With any other error, the record
stays counted. As of now, send() on a kTLS socket returns success after
the TCP connection can no longer send, for example after
shutdown(SHUT_WR) or after a reset. Nothing reaches the peer, and the
caller is not told.
The issue can be reproduced with:
python3 - <<'EOF'
import socket, struct
l = socket.create_server(("127.0.0.1", 0))
c = socket.create_connection(l.getsockname())
c.setsockopt(socket.SOL_TCP, 31, b"tls")
c.setsockopt(282, 1, struct.pack("HH", 0x0303, 51) + bytes(36))
c.shutdown(socket.SHUT_WR)
print(c.send(b"hello"))
EOF
Before commit b341ca51d267 ("tls: Fix tls_sw_sendmsg error handling"),
the result is:
OSError: [Errno 74] Bad message
After that commit, the result is:
5
This patch will make bpf_exec_tx_verdict() check for any error in
sk_err. The send() above then fails with EPIPE, as it does on a plain
TCP socket.
Fixes: b341ca51d267 ("tls: Fix tls_sw_sendmsg error handling")
Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
---
Tested on net: with this patch, the send() above and a send() after a
reset fail with EPIPE, and a send() on a TCP_REPAIR socket fails with
EINVAL, as they do on a plain TCP socket. The tls selftests pass.
Not addressed here: a caller that ignores the error and sends again
still gets one more record queued per send(), because
sk_stream_error() clears sk_err for EPIPE. Before commit b341ca51d267
the EBADMSG stayed set and later sends failed early.
net/tls/tls_sw.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index 226e0f176fdc..f3e496fa47ae 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -711,7 +711,7 @@ static int bpf_exec_tx_verdict(struct sk_msg *msg, struct sock *sk,
int err;
err = tls_push_record(sk, flags, record_type);
- if (err && err != -EINPROGRESS && sk->sk_err == EBADMSG) {
+ if (err && err != -EINPROGRESS && sk->sk_err) {
*copied -= sk_msg_free(sk, msg);
tls_free_open_rec(sk);
err = -sk->sk_err;
base-commit: ead6fa9a0ab194f02a2f36d634b193e9c5f9a1c6
--
2.53.0
next reply other threads:[~2026-11-13 19:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 19:36 Hengyu Liang [this message]
2026-11-13 19:41 ` netdev-bot+sinfo
2026-11-13 19:46 ` Hengyu Liang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261113193649.3822306-1-hengyul@cs.unc.edu \
--to=hengyul@cs.unc.edu \
--cc=bcodding@hammerspace.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sd@queasysnail.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®