From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: Paolo Abeni <pabeni@redhat.com>, netdev@vger.kernel.org
Cc: John Fastabend <john.fastabend@gmail.com>,
Jakub Kicinski <kuba@kernel.org>,
Sabrina Dubroca <sd@queasysnail.net>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Simon Horman <horms@kernel.org>,
Wilfred Mallawa <wilfred.mallawa@wdc.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v2] tls: fix the open record check in the max payload size setsockopt
Date: Thu, 3 Sep 2026 17:40:13 +0800 [thread overview]
Message-ID: <7735a43a-98f4-4402-8bb7-790bee064f7f@linux.dev> (raw)
In-Reply-To: <2ba43d6b-f521-415e-a4a1-64b313051c88@redhat.com>
在 9/3/26 5:06 PM, Paolo Abeni 写道:
> On 9/1/26 9:29 AM, Jiayuan Chen wrote:
>> @@ -862,6 +876,7 @@ static int do_tls_setsockopt_tx_payload_len(struct sock *sk, sockptr_t optval,
>> static int do_tls_setsockopt(struct sock *sk, int optname, sockptr_t optval,
>> unsigned int optlen)
>> {
>> + struct tls_context *ctx;
>> int rc = 0;
>>
>> switch (optname) {
>> @@ -881,9 +896,17 @@ static int do_tls_setsockopt(struct sock *sk, int optname, sockptr_t optval,
>> rc = do_tls_setsockopt_no_pad(sk, optval, optlen);
>> break;
>> case TLS_TX_MAX_PAYLOAD_LEN:
>> + /* Take tx_lock like the sendmsg paths do, the socket lock is
>> + * dropped while a sender waits for memory, with no record open.
>> + */
>> + ctx = tls_get_ctx(sk);
>> + rc = mutex_lock_interruptible(&ctx->tx_lock);
>> + if (rc)
> Why using the interruptible variant? the blocking lock just after will
> still ignore signals, and this sockopt will now surprisingly fail if a
> signal happens at the wrong time.
>
> /P
Hi Paolo,
The two waits are very different. The xmit path holds tx_lock across
sk_stream_wait_memory(), which can sleep for an undetermined time (until
the peer reads):
tls_device_sendmsg()
mutex_lock(&tls_ctx->tx_lock);
lock_sock(sk);
tls_push_data()
sk_stream_wait_memory() <- releases sk lock, keeps tx_lock
release_sock(sk);
mutex_unlock(&tls_ctx->tx_lock);
So waiting for tx_lock with plain mutex_lock() can leave the process in
D state for a long time. The lock_sock() after it is fine: the sleeping
sender drops the socket lock, so that wait is only for short critical
sections, never across the long sleep.
tls_sw_sendmsg() also uses mutex_lock_interruptible but
tls_device_sendmsg() still
uses plain mutex_lock() indeed, but that's another topic.
prev parent reply other threads:[~2026-09-03 9:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 7:29 [PATCH net v2] tls: fix the open record check in the max payload size setsockopt Jiayuan Chen
2026-09-03 9:06 ` Paolo Abeni
2026-09-03 9:40 ` Jiayuan Chen [this message]
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=7735a43a-98f4-4402-8bb7-790bee064f7f@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--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 \
--cc=wilfred.mallawa@wdc.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 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.