Skip to contentSkip to conversation

tcp: limit tcp_tso_rtt_log to a valid shift count

PATCH Applied Yingjie Wang 6 participants 6 messages Oct 23 – Oct 27

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tcp: limit tcp_tso_rtt_log to a valid shift count

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")

---
v2:
- Attach the upper bound to tcp_tso_rtt_log instead of ip_dynaddr, as pointed out by Jiayuan Chen and Neal Cardwell.
- Re-run checkpatch and boundary tests on the corrected patch.
- Do not carry Eric Dumazet's Reviewed-by tag because the code changed.

v1: https://lore.kernel.org/netdev/[email protected]/

 Documentation/networking/ip-sysctl.rst | 2 ++
 net/ipv4/sysctl_net_ipv4.c             | 2 ++
 2 files changed, 4 insertions(+)
Documentation/networking/ip-sysctl.rst +2 -0
index 8edd2eb2a..66a54c510 100644
@@ -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
net/ipv4/sysctl_net_ipv4.c +2 -0
index e3760daa3..bf193e7ec 100644
@@ -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;
@@ -1406,6 +1407,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	= "tcp_min_rtt_wlen",

base-commit: f4377bf85887f57b59abb5479f7660a81ffe4449

Signature · 1 line
2.43.0
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

Reviewed-by on v2 1/1
#2 lore raw
In reply to Yingjie Wang
Quoted 23 lines · Yingjie Wang

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.

Quoted 7 lines

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")

Thanks !

Quoted 48 lines

---
v2:
- Attach the upper bound to tcp_tso_rtt_log instead of ip_dynaddr, as pointed out by Jiayuan Chen and Neal Cardwell.
- Re-run checkpatch and boundary tests on the corrected patch.
- Do not carry Eric Dumazet's Reviewed-by tag because the code changed.

v1: https://lore.kernel.org/netdev/[email protected]/

  Documentation/networking/ip-sysctl.rst | 2 ++
  net/ipv4/sysctl_net_ipv4.c             | 2 ++
  2 files changed, 4 insertions(+)
Documentation/networking/ip-sysctl.rst +2 -0
index 8edd2eb2a..66a54c510 100644
@@ -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
net/ipv4/sysctl_net_ipv4.c +2 -0
index e3760daa3..bf193e7ec 100644
@@ -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;
@@ -1406,6 +1407,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	= "tcp_min_rtt_wlen",

base-commit: f4377bf85887f57b59abb5479f7660a81ffe4449

Reviewed-by
#3 lore raw
Quoted 30 lines · Jiayuan Chen
Quoted 27 lines · Yingjie Wang

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.

Quoted 6 lines
Quoted 3 lines
Fixes 65466904b015 ("tcp: adjust TSO packet sizes based on min_rtt")

Thanks!
neal

maintainer Reviewed-by
#4 lore raw
Quoted 32 lines · Neal Cardwell
Quoted 30 lines · Jiayuan Chen
Quoted 27 lines · Yingjie Wang

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.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Fixes 65466904b015 ("tcp: adjust TSO packet sizes based on min_rtt")
#5 lore raw
In reply to Yingjie Wang
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Fri, 23 Oct 2026 22:40:36 +0800 you 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:

[...]

Here is the summary with links:
- [net,v2] tcp: limit tcp_tso_rtt_log to a valid shift count

    https://git.kernel.org/netdev/net/c/850a7225bc61

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html