From: sashiko-bot@kernel.org
To: "Jakub Kicinski" <kuba@kernel.org>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net 6/7] net: tls: fix use-after-free in tls_sw_sendmsg_locked after bpf verdict
Date: Thu, 30 Apr 2026 22:31:32 +0000 [thread overview]
Message-ID: <20260430223133.844A3C2BCC6@smtp.kernel.org> (raw)
In-Reply-To: <20260429222944.2139041-7-kuba@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Arithmetic underflow, state corruption, and silent data duplication in the iterator rollback path.
- [High] Use-After-Free when `bpf_exec_tx_verdict` returns `-ENOMEM`.
--
commit ba7ab075901b934710734a96c18f344dbc28cf04
Author: Jakub Kicinski <kuba@kernel.org>
net: tls: fix use-after-free in tls_sw_sendmsg_locked after bpf verdict
This patch fixes a use-after-free in tls_sw_sendmsg_locked() when
bpf_exec_tx_verdict() returns -ENOSPC. It updates msg_pl and msg_en after a
possible record split to avoid referencing a freed record.
> diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
> index 2c6a3c4a9fcc..4f8d656f39a3 100644
> --- a/net/tls/tls_sw.c
> +++ b/net/tls/tls_sw.c
> @@ -1157,6 +1157,13 @@ static int tls_sw_sendmsg_locked(struct sock *sk, struct msghdr *msg,
> else if (ret == -ENOMEM)
> goto wait_for_memory;
If bpf_exec_tx_verdict() splits the record, pushes it to tx_list, and then
encounters an -ENOMEM error while transmitting, it returns -ENOMEM.
This jumps to wait_for_memory without refetching msg_en. If
sk_stream_wait_memory() returns 0, the loop continues and evaluates:
if (ctx->open_rec && msg_en->sg.size < required_size)
goto alloc_encrypted;
Could this result in a use-after-free read when dereferencing msg_en->sg.size,
since msg_en still points to the freed original record?
> else if (ctx->open_rec && ret == -ENOSPC) {
> + /* bpf_exec_tx_verdict() may have
> + * called tls_split_open_record(),
> + * freeing the old record. Re-fetch.
> + */
> + rec = ctx->open_rec;
> + msg_pl = &rec->msg_plaintext;
> + msg_en = &rec->msg_encrypted;
> if (msg_pl->cork_bytes) {
> ret = 0;
> goto send_end;
If bpf_exec_tx_verdict() splits the record and then returns -ENOSPC (for
example, from a failed sk_msg_alloc on the remainder), the new msg_pl points
to the remainder record. If msg_pl->cork_bytes is 0, execution falls through
to rollback_iter:
rollback_iter:
copied -= try_to_copy;
sk_msg_sg_copy_clear(msg_pl, first);
iov_iter_revert(&msg->msg_iter,
msg_pl->sg.size - orig_size);
Since msg_pl is now the remainder record, its size might be smaller than
orig_size. Does the subtraction in iov_iter_revert() underflow and corrupt
the iterator state?
Also, sk_msg_sg_copy_clear(msg_pl, first) is called, but 'first' was captured
from the original record. Could this cause an out-of-bounds access on the
remainder's scatterlist?
Additionally, is it safe to roll back the iterator after the first chunk of
the split record was successfully transmitted? It seems this could lead to
the application re-sending already committed data.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260429222944.2139041-1-kuba@kernel.org?part=6
next prev parent reply other threads:[~2026-04-30 22:31 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 22:29 [PATCH net 0/7] net: tls: fix a few random bugs Jakub Kicinski
2026-04-29 22:29 ` [PATCH net 1/7] net: tls: fix silent data drop under pipe back-pressure Jakub Kicinski
2026-04-29 22:29 ` [PATCH net 2/7] selftests: tls: add test for data loss on small pipe Jakub Kicinski
2026-04-30 22:31 ` sashiko-bot
2026-04-29 22:29 ` [PATCH net 3/7] net: tls: fix page pin leak on sendpage_ok() failure Jakub Kicinski
2026-04-30 22:31 ` sashiko-bot
2026-04-29 22:29 ` [PATCH net 4/7] net: tls: fix off-by-one in sg_chain entry count for wrapped sk_msg ring Jakub Kicinski
2026-04-30 22:31 ` sashiko-bot
2026-05-01 16:40 ` Sabrina Dubroca
2026-05-03 1:26 ` Jakub Kicinski
2026-04-29 22:29 ` [PATCH net 5/7] selftests: bpf: cover wrapped sk_msg ring chaining in ktls TX path Jakub Kicinski
2026-04-30 17:58 ` Jiayuan Chen
2026-04-30 22:31 ` sashiko-bot
2026-04-29 22:29 ` [PATCH net 6/7] net: tls: fix use-after-free in tls_sw_sendmsg_locked after bpf verdict Jakub Kicinski
2026-04-30 17:50 ` Jiayuan Chen
2026-04-30 22:31 ` sashiko-bot [this message]
2026-04-29 22:29 ` [PATCH net 7/7] selftests: bpf: cover tls_sw_sendmsg UAF after bpf_exec_tx_verdict split Jakub Kicinski
2026-04-30 17:55 ` Jiayuan Chen
2026-05-03 2:20 ` [PATCH net 0/7] net: tls: fix a few random bugs patchwork-bot+netdevbpf
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=20260430223133.844A3C2BCC6@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kuba@kernel.org \
--cc=sashiko@lists.linux.dev \
/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