All of lore.kernel.org
 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 3/4] net: tls: fix use-after-free in tls_sw_sendmsg_locked after bpf verdict
Date: Wed, 13 May 2026 00:39:46 +0000	[thread overview]
Message-ID: <20260513003947.336D6C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260511174920.433155-4-kuba@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Silent data loss, stream corruption, and race condition in the trim_sgl error path on wait_for_memory failure.
- [High] Removing the alloc_encrypted shortcut eliminates the verdict retry mechanism, causing connection hangs on ENOMEM.
--

commit 1c563620cb643329347417380b885f1f7483dc0f
Author: Jakub Kicinski <kuba@kernel.org>

net: tls: fix use-after-free in tls_sw_sendmsg_locked after bpf verdict

bpf_exec_tx_verdict() may modify the record and the plaintext/encrypted
sk_msg pointers, requiring them to be reloaded. The post-wait shortcut
could dereference a cached msg_en pointing to a freed record if the
verdict split the open rec before returning -ENOMEM. This commit drops
the shortcut to prevent a use-after-free.

> diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
> index 3bfdaf5e64f50..360f71fd78842 100644
> --- a/net/tls/tls_sw.c
> +++ b/net/tls/tls_sw.c

[ ... ]

> @@ -1255,9 +1254,6 @@ static int tls_sw_sendmsg_locked(struct sock *sk, struct msghdr *msg,
>  				tls_trim_both_msgs(sk, orig_size);

While this error path wasn't introduced by this patch, is it safe?

If bpf_exec_tx_verdict() returns -ENOMEM, execution jumps to wait_for_memory.
At this point, try_to_copy bytes have already been appended to the record,
msg_iter advanced, and copied incremented.

sk_stream_wait_memory() releases the socket lock and sleeps. If it wakes up and
returns an error, execution jumps to trim_sgl and calls
tls_trim_both_msgs(sk, orig_size) to truncate the record.

Does this discard the try_to_copy bytes without decrementing copied or
reverting msg_iter, returning success to userspace for deleted data?

Because the socket lock was dropped during the sleep, could a concurrent thread
have pushed the record and allocated a new one, meaning trimming this new
record using the stale orig_size from before the sleep corrupts the concurrent
thread's stream?

Also, if the verdict split the record before returning -ENOMEM, would orig_size
refer to the freed record, causing out-of-bounds trimming logic?

>  			goto send_end;
>  		}
> -
> -		if (ctx->open_rec && msg_en->sg.size < required_size)
> -			goto alloc_encrypted;

Does removing this shortcut eliminate the verdict retry mechanism?

If the verdict fails with -ENOMEM on the final data chunk (where
msg_data_left(msg) == 0) and memory subsequently becomes available, removing
this jump means execution falls through to the loop condition and immediately
terminates.

The record is fully constructed in ctx->open_rec but is never pushed to the
engine or transmitted. Does this leave the data stuck in the buffer
indefinitely until a subsequent sendmsg or socket close triggers a flush,
causing the protocol to hang?

>  	}
>  
>  send_end:

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

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

Thread overview: 23+ 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 [this message]
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
2026-05-14 11:18   ` Paolo Abeni
2026-05-14 12:55     ` Sabrina Dubroca
2026-05-14 14:55       ` Jakub Kicinski
2026-05-14 15:05         ` Sabrina Dubroca
2026-05-14 15:09           ` Jakub Kicinski
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
2026-05-14 11:30 ` 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=20260513003947.336D6C2BCB0@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.