BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jakub Kicinski" <kuba@kernel.org>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net v2 4/4] net: tls: remove bad rollback and UAF on ENOSPC
Date: Wed, 13 May 2026 01:39:15 +0000	[thread overview]
Message-ID: <20260513013916.37E1FC2BCB8@smtp.kernel.org> (raw)
In-Reply-To: <20260511174920.433155-5-kuba@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Silent data loss and stale state usage (UAF) in the -ENOMEM error path.
- [High] BPF policy bypass due to uncleared psock->eval state on -ENOMEM.
--

commit 9867dad26c6eb929c35af6ad7b485aac95c01aef
Author: Jakub Kicinski <kuba@kernel.org>

net: tls: remove bad rollback and UAF on ENOSPC

This commit removes the attempt to roll back the iterator when BPF
encounters an ENOSPC error. Since BPF may have modified the message,
variables like orig_size and other pointers become stale, so rolling
them back leads to use-after-free or corruption.

> diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
> index 360f71fd78842..22b77840e35ae 100644
> --- a/net/tls/tls_sw.c
> +++ b/net/tls/tls_sw.c
> @@ -1164,11 +1164,8 @@ static int tls_sw_sendmsg_locked(struct sock *sk, struct msghdr *msg,
>  				else if (ret == -ENOMEM)
>  					goto wait_for_memory;

The commit message notes that BPF may have modified the message, making
pointers and state stale. Does this same stale state issue still exist in
the -ENOMEM path?

If bpf_exec_tx_verdict() executes BPF (which may push or pop data) and then
fails with -ENOMEM, execution jumps to wait_for_memory:

wait_for_memory:
        ret = sk_stream_wait_memory(sk, &timeo);
        if (ret) {
trim_sgl:
            if (ctx->open_rec)
                tls_trim_both_msgs(sk, orig_size);
            goto send_end;
        }

If sk_stream_wait_memory() fails, the code calls tls_trim_both_msgs(sk,
orig_size). Can trimming to the pre-BPF orig_size corrupt the scatterlist
if BPF changed the size?

Additionally, copied was already incremented by try_to_copy. Since the
function returns copied, might it falsely indicate to userspace that the
discarded bytes were successfully sent, causing silent data corruption?

What happens if sk_stream_wait_memory() succeeds instead? The loop in
tls_sw_sendmsg_locked() restarts, appending more data from userspace to
the open record.

If tls_push_record() inside the bpf_exec_tx_verdict() path returns -ENOMEM,
does it return early without resetting psock->eval to __SK_NONE?

If so, when bpf_exec_tx_verdict() is called again, could it see psock->eval
evaluating to __SK_PASS and skip the BPF evaluation entirely, allowing
the newly appended data to be sent without verification?

>  				else if (ctx->open_rec && ret == -ENOSPC) {
> -					if (msg_pl->cork_bytes) {
> -						ret = 0;
> -						goto send_end;
> -					}
> -					goto rollback_iter;
> +					ret = 0;
> +					goto send_end;
>  				} else if (ret != -EAGAIN)
>  					goto send_end;
>  			}

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260511174920.433155-1-kuba@kernel.org?part=4

  reply	other threads:[~2026-05-13  1:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11 17:49 [PATCH net v2 0/4] net: tls: net: tls: fix a few random bugs Jakub Kicinski
2026-05-11 17:49 ` [PATCH net v2 1/4] net: tls: fix off-by-one in sg_chain entry count for wrapped sk_msg ring Jakub Kicinski
2026-05-12 10:21   ` Sabrina Dubroca
2026-05-11 17:49 ` [PATCH net v2 2/4] net: tls: prevent chain-after-chain in plain text SG Jakub Kicinski
2026-05-12 11:09   ` Sabrina Dubroca
2026-05-12 16:03     ` Jakub Kicinski
2026-05-12 22:30       ` Sabrina Dubroca
2026-05-13  0:14         ` Jakub Kicinski
2026-05-13  0:10   ` sashiko-bot
2026-05-11 17:49 ` [PATCH net v2 3/4] net: tls: fix use-after-free in tls_sw_sendmsg_locked after bpf verdict Jakub Kicinski
2026-05-12  9:47   ` Jiayuan Chen
2026-05-12 16:04     ` Jakub Kicinski
2026-05-13  0:39   ` sashiko-bot
2026-05-11 17:49 ` [PATCH net v2 4/4] net: tls: remove bad rollback and UAF on ENOSPC Jakub Kicinski
2026-05-13  1:39   ` sashiko-bot [this message]
2026-05-12  9:28 ` [PATCH net v2 0/4] net: tls: net: tls: fix a few random bugs Jakub Sitnicki
2026-05-12  9:37   ` Sabrina Dubroca

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=20260513013916.37E1FC2BCB8@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=sashiko-reviews@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