From: Wilfred Mallawa <wilfred.opensource@gmail.com>
To: Sabrina Dubroca <sd@queasysnail.net>, kuba@kernel.org
Cc: davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
horms@kernel.org, corbet@lwn.net, john.fastabend@gmail.com,
netdev@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, alistair.francis@wdc.com,
dlemoal@kernel.org
Subject: Re: [PATCH v3] net/tls: support maximum record size limit
Date: Thu, 18 Sep 2025 11:42:23 +1000 [thread overview]
Message-ID: <c7104a0d58c674bb1fec1a6093be6085ad0be0e0.camel@gmail.com> (raw)
In-Reply-To: <aLllqGpa2gLVNRbw@krikkit>
On Thu, 2025-09-04 at 12:10 +0200, Sabrina Dubroca wrote:
> 2025-09-03, 11:47:57 +1000, Wilfred Mallawa wrote:
> > +static int do_tls_setsockopt_tx_record_size(struct sock *sk,
> > sockptr_t optval,
> > + unsigned int optlen)
> > +{
> > + struct tls_context *ctx = tls_get_ctx(sk);
> > + u16 value;
> > +
> > + if (sockptr_is_null(optval) || optlen != sizeof(value))
> > + return -EINVAL;
> > +
> > + if (copy_from_sockptr(&value, optval, sizeof(value)))
> > + return -EFAULT;
> > +
> > + if (ctx->prot_info.version == TLS_1_2_VERSION &&
> > + value > TLS_MAX_PAYLOAD_SIZE)
> > + return -EINVAL;
> > +
> > + if (ctx->prot_info.version == TLS_1_3_VERSION &&
> > + value > TLS_MAX_PAYLOAD_SIZE + 1)
> > + return -EINVAL;
>
> The RFC is not very explicit about this, but I think this +1 for
> TLS1.3 is to allow an actual payload of TLS_MAX_PAYLOAD_SIZE and save
> 1B of room for the content_type that gets appended.
>
> This value is the length of the plaintext of a protected record.
> The
> value includes the content type and padding added in TLS 1.3 (that
> is, the complete length of TLSInnerPlaintext).
>
> AFAIU we don't actually want to stuff TLS_MAX_PAYLOAD_SIZE+1 bytes of
> payload into a record.
>
> If we set tx_record_size_limit to TLS_MAX_PAYLOAD_SIZE+1, we'll end
> up
> sending a record with a plaintext of TLS_MAX_PAYLOAD_SIZE+2 bytes
> (TLS_MAX_PAYLOAD_SIZE+1 of payload, then 1B of content_type), and a
> "normal" implementation will reject the record since it's too big
> (ktls does that in net/tls/tls_sw.c:tls_rx_msg_size).
>
> So we should subtract 1 from the userspace-provided value for 1.3,
> and
> then add it back in getsockopt/tls_get_info.
Yeah good point. I will fix this up
>
> Or maybe userspace should provide the desired payload limit, instead
> of the raw record_size_limit it got from the extension (ie, do -1
> when
> needed before calling the setsockopt). Then we should rename this
> "tx_payload_size_limit" (and adjust the docs) to make it clear it's
> not the raw record_size_limit.
>
> The "tx_payload_size_limit" approach is maybe a little bit simpler
> (not having to add/subtract 1 in a few places - I think userspace
> would only have to do it in one place).
>
>
> Wilfred, Jakub, what do you think?
I'm in favour of keeping the RFC definition, as this would mean
userspace only has to worry about passing up the value received from
the record size limit extension.
For V4, I'll add a note in the docs regarding the TLS 1.3 ContentType,
and fixup tx_record_size_limit to account for ContentType.
Regards,
Wilfred
>
>
> > + ctx->tx_record_size_limit = value;
> > +
> > + return 0;
> > +}
prev parent reply other threads:[~2025-09-18 1:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-03 1:47 [PATCH v3] net/tls: support maximum record size limit Wilfred Mallawa
2025-09-03 10:14 ` Sabrina Dubroca
2025-09-04 9:54 ` Sabrina Dubroca
2025-09-18 0:52 ` Wilfred Mallawa
2025-09-03 22:51 ` Jakub Kicinski
2025-09-04 23:41 ` Wilfred Mallawa
2025-09-04 10:10 ` Sabrina Dubroca
2025-09-04 13:33 ` Jakub Kicinski
2025-09-18 1:42 ` Wilfred Mallawa [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=c7104a0d58c674bb1fec1a6093be6085ad0be0e0.camel@gmail.com \
--to=wilfred.opensource@gmail.com \
--cc=alistair.francis@wdc.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=dlemoal@kernel.org \
--cc=edumazet@google.com \
--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=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sd@queasysnail.net \
/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;
as well as URLs for NNTP newsgroup(s).