Linux Documentation
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: v0idpwn@gmail.com
Cc: john.fastabend@gmail.com, kuba@kernel.org, sd@queasysnail.net,
	davem@davemloft.net, edumazet@kernel.org, pabeni@redhat.com,
	horms@kernel.org, corbet@lwn.net, skhan@linuxfoundation.org,
	rdunlap@infradead.org, shuah@kernel.org, netdev@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net 1/2] tls: don't hide a queued KeyUpdate from poll()
Date: Sun, 22 Nov 2026 21:26:35 +0000	[thread overview]
Message-ID: <179538279534.3135.17423952957860887247@kernel.org> (raw)
In-Reply-To: <20261118-v0idpwn-tls-poll-parked-keyupdate-v1-1-8e25101e7be6@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] Lost wakeup: a KeyUpdate that is moved onto rx_list while
  another task is polling stays hidden from that poller.

--

tls: don't hide a queued KeyUpdate from poll()

This commit changes tls_sk_poll() so that records already decrypted
onto rx_list show up as readable even while a rekey is pending. Records
still held by the strparser stay hidden until the new key is provided.
The documentation is updated to match.

[ ... ]

> diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
> index b8d5a843f7617..4c4c2801ae065 100644
> --- a/net/tls/tls_main.c
> +++ b/net/tls/tls_main.c
> @@ -414,9 +414,9 @@ static __poll_t tls_sk_poll(struct file *file, struct socket *sock,
>  	tls_ctx = tls_get_ctx(sk);
>  	ctx = tls_sw_ctx_rx(tls_ctx);
>  
> -	if ((skb_queue_empty_lockless(&ctx->rx_list) &&
> -	     !tls_strp_msg_ready(ctx)) ||
> -	    READ_ONCE(ctx->key_update_pending))
> +	if (skb_queue_empty_lockless(&ctx->rx_list) &&
> +	    (!tls_strp_msg_ready(ctx) ||
> +	     READ_ONCE(ctx->key_update_pending)))
>  		mask &= ~(EPOLLIN | EPOLLRDNORM);

[Severity: Medium]
Can a poller that is already waiting still miss the KeyUpdate here?

tls_sk_poll() takes no lock. The KeyUpdate only lands on rx_list at the
very end of the tls_sw_recvmsg() step that decrypts it:

tls_sw_recvmsg()
  tls_rx_one_record()
    tls_check_pending_rekey()
      WRITE_ONCE(rx_ctx->key_update_pending, true);
  tls_record_content_type()      /* returns 0, record type differs */
  tls_rx_rec_done(ctx);          /* clears msg_ready / msg_announced */
  __skb_queue_tail(&ctx->rx_list, darg.skb);

A tls_sk_poll() from another task can run between the point where
key_update_pending is set and __skb_queue_tail(). It can also run in the
earlier gap, after the data record is consumed and before the KeyUpdate
is parsed, when msg_ready is 0. Either way it sees an empty rx_list and
clears EPOLLIN.

Nothing seems to wake the socket after the KeyUpdate is queued. The
deferred wakeup in tls_rx_reader_release() doesn't fire in this state:

net/tls/tls_sw.c:tls_rx_msg_maybe_announce() {
	...
	if (!READ_ONCE(strp->msg_ready) || strp->msg_announced)
		return;
	strp->msg_announced = 1;
	...
	ctx->saved_data_ready(strp->sk);
}

The same reader already consumed the KeyUpdate from the strparser, so
msg_ready is 0 at that point. The only other wakeup, in
tls_finish_key_update(), runs after userspace installs the new key.

One way to hit this is several threads sharing one level-triggered
epoll instance on the TLS fd:

T1 gets the event and enters recvmsg().
The LT item is re-queued and T2 is woken.
T2's ep_item_poll() lands in the window above, gets no events and
  drops the item from the ready list.
T1 queues the KeyUpdate on rx_list, returns the data and calls
  epoll_wait() again. The ready list is empty, so it sleeps.

No task reads the KeyUpdate, so no new key is installed. The connection
then stalls until the peer sends more data. That may never happen if the
peer is waiting for a reply, for example when update_requested is set.
The same wakeup is lost when a poller thread signals a separate reader
thread.

The commit message says:

    A reader that waits for a read event before each recv()
    never reads it, never provides the new key and receives nothing more.

That fix seems to hold only when the same task polls again after
recvmsg() returns. This matches the single-threaded LT reader described
here and the selftest added in "selftests: tls: add a poll test for a
queued KeyUpdate".

Would it make sense to also call ctx->saved_data_ready(sk)? One place
would be where the KeyUpdate is queued on rx_list. Another would be in
tls_rx_reader_release() when rx_list is not empty and key_update_pending
is set.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-v0idpwn-tls-poll-parked-keyupdate-v1-0-8e25101e7be6%40gmail.com

  reply	other threads:[~2026-11-22 21:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 20:35 [PATCH net 0/2] tls: don't hide a queued KeyUpdate from poll() Felipe Pereira Stival via B4 Relay
2026-11-18 20:35 ` [PATCH net 1/2] " Felipe Pereira Stival via B4 Relay
2026-11-22 21:26   ` netdev-bot+sashiko [this message]
2026-11-18 20:35 ` [PATCH net 2/2] selftests: tls: add a poll test for a queued KeyUpdate Felipe Pereira Stival via B4 Relay

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=179538279534.3135.17423952957860887247@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=sd@queasysnail.net \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=v0idpwn@gmail.com \
    /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