From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: netdev@vger.kernel.org
Subject: Re: [PATCH net] tcp: limit tcp_tso_rtt_log to a valid shift count
Date: Thu, 22 Oct 2026 20:50:57 +0800 [thread overview]
Message-ID: <f97b13ca-90b2-4bac-91bb-70c9d26095f9@linux.dev> (raw)
In-Reply-To: <tencent_53CDCF8AA0022B75CF72A294CB9993D2FF07@qq.com>
On 10/22/26 8:27 PM, Yingjie Wang wrote:
> tcp_tso_autosize() right-shifts the u32 returned by tcp_min_rtt() by
> sysctl_tcp_tso_rtt_log. The sysctl uses proc_dou8vec_minmax() without
> an upper bound, so it accepts values through 255. Values above 31 make
> the shift undefined.
>
> A process with CAP_NET_ADMIN in the target network namespace can set the
> per-netns sysctl. With CONFIG_UBSAN_SHIFT=y, setting it to 32 and sending
> TCP data over loopback triggers:
>
> UBSAN: shift-out-of-bounds in net/ipv4/tcp_output.c:2264:30
> shift exponent 32 is too large for 32-bit type 'unsigned int'
> Call Trace:
> __ubsan_handle_shift_out_of_bounds
> tcp_tso_segs
> tcp_write_xmit
> __tcp_push_pending_frames
> tcp_push
> tcp_sendmsg_locked
>
> Limit the sysctl to 31, the largest valid shift count for a u32, and
> document the accepted range. Writes of larger values now fail with
> -EINVAL.
>
> On a UBSAN/KASAN build of the net tree, values 0 and 31 remained
> accepted, values 32 and 255 returned -EINVAL, and TCP traffic with the
> valid boundary values produced no sanitizer diagnostics.
>
> Fixes: 65466904b015 ("tcp: adjust TSO packet sizes based on min_rtt")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yingjie Wang <1075151112@qq.com>
> ---
> Documentation/networking/ip-sysctl.rst | 2 ++
> net/ipv4/sysctl_net_ipv4.c | 2 ++
> 2 files changed, 4 insertions(+)
>
> diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
> index 8edd2eb2a..66a54c510 100644
> --- a/Documentation/networking/ip-sysctl.rst
> +++ b/Documentation/networking/ip-sysctl.rst
> @@ -1128,6 +1128,8 @@ tcp_tso_rtt_log - INTEGER
>
> If you want to use the old autosizing, set this sysctl to 0.
>
> + Possible values are [0, 31], inclusive.
> +
> Default: 9 (2^9 = 512 usec)
>
> tcp_pacing_ss_ratio - INTEGER
> diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
> index e3760daa3..e95431140 100644
> --- a/net/ipv4/sysctl_net_ipv4.c
> +++ b/net/ipv4/sysctl_net_ipv4.c
> @@ -26,6 +26,7 @@ static int ip_local_port_range_max[] = { 65535, 65535 };
> static int tcp_adv_win_scale_min = -31;
> static int tcp_adv_win_scale_max = 31;
> static int tcp_app_win_max = 31;
> +static int tcp_tso_rtt_log_max = 31;
> static int tcp_min_snd_mss_min = TCP_MIN_SND_MSS;
> static int tcp_min_snd_mss_max = 65535;
> static int tcp_rto_max_max = TCP_RTO_MAX_SEC * MSEC_PER_SEC;
> @@ -778,6 +779,7 @@ static const struct ctl_table ipv4_net_table[] = {
> .maxlen = sizeof(u8),
> .mode = 0644,
> .proc_handler = proc_dou8vec_minmax,
> + .extra2 = &tcp_tso_rtt_log_max,
> },
> {
> .procname = "ip_early_demux",
Wait a minute, is my tree too old, or did you land tcp_tso_rtt_log_max
in the wrong place?
It looks like you are adding it to the ip_dynaddr entry. tcp_tso_rtt_log?
{
.procname = "ip_dynaddr",
.data = &init_net.ipv4.sysctl_ip_dynaddr,
.maxlen = sizeof(u8),
.mode = 0644,
.proc_handler = proc_dou8vec_minmax,
},
{
.procname = "ip_early_demux",
.data = &init_net.ipv4.sysctl_ip_early_demux,
.maxlen = sizeof(u8),
.mode = 0644,
.proc_handler = proc_dou8vec_minmax,
},
> base-commit: f4377bf85887f57b59abb5479f7660a81ffe4449
next prev parent reply other threads:[~2026-10-22 12:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 12:27 [PATCH net] tcp: limit tcp_tso_rtt_log to a valid shift count Yingjie Wang
2026-10-22 12:33 ` netdev-bot+sinfo
2026-10-22 12:34 ` Eric Dumazet
2026-10-22 12:50 ` Jiayuan Chen [this message]
2026-10-22 14:50 ` Neal Cardwell
2026-10-25 15:02 ` netdev-bot+sashiko
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=f97b13ca-90b2-4bac-91bb-70c9d26095f9@linux.dev \
--to=jiayuan.chen@linux.dev \
--cc=netdev@vger.kernel.org \
/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.