Skip to contentSkip to conversation

sctp: prevent possible shift-out-of-bounds in sctp_transport_update_rto

PATCH Applied Eric Dumazet 3 participants 7 messages Nov 6, 2025 – Nov 11, 2025

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

PATCH 1/1 sctp: prevent possible shift-out-of-bounds in sctp_transport_update_rto

syzbot reported a possible shift-out-of-bounds [1]

Blamed commit added rto_alpha_max and rto_beta_max set to 1000.

It is unclear if some sctp users are setting very large rto_alpha and/or rto_beta.

In order to prevent user regression, perform the test at run time.

Also add READ_ONCE() annotations as sysctl values can change under us.

[1]

UBSAN: shift-out-of-bounds in net/sctp/transport.c:509:41
shift exponent 64 is too large for 32-bit type 'unsigned int'
CPU: 0 UID: 0 PID: 16704 Comm: syz.2.2320 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/02/2025
Call Trace:
 <TASK>
  __dump_stack lib/dump_stack.c:94 [inline]
  dump_stack_lvl+0x16c/0x1f0 lib/dump_stack.c:120
  ubsan_epilogue lib/ubsan.c:233 [inline]
  __ubsan_handle_shift_out_of_bounds+0x27f/0x420 lib/ubsan.c:494
  sctp_transport_update_rto.cold+0x1c/0x34b net/sctp/transport.c:509
  sctp_check_transmitted+0x11c4/0x1c30 net/sctp/outqueue.c:1502
  sctp_outq_sack+0x4ef/0x1b20 net/sctp/outqueue.c:1338
  sctp_cmd_process_sack net/sctp/sm_sideeffect.c:840 [inline]
  sctp_cmd_interpreter net/sctp/sm_sideeffect.c:1372 [inline]
Fixes b58537a1f562 ("net: sctp: fix permissions for rto_alpha and rto_beta knobs")
Reported-by [email protected]
Cc Daniel Borkmann <[email protected]>
---
 net/sctp/transport.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
net/sctp/transport.c +9 -4
index 0d48c61fe6adefc1a9c56ca1b8ab00072825d9e6..0c56d9673cc137e3f1a64311e79bd41db2cb1282 100644
@@ -486,6 +486,7 @@ void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt)
 
 	if (tp->rttvar || tp->srtt) {
 		struct net *net = tp->asoc->base.net;
+		unsigned int rto_beta, rto_alpha;
 		/* 6.3.1 C3) When a new RTT measurement R' is made, set
 		 * RTTVAR <- (1 - RTO.Beta) * RTTVAR + RTO.Beta * |SRTT - R'|
 		 * SRTT <- (1 - RTO.Alpha) * SRTT + RTO.Alpha * R'
@@ -497,10 +498,14 @@ void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt)
 		 * For example, assuming the default value of RTO.Alpha of
 		 * 1/8, rto_alpha would be expressed as 3.
 		 */
-		tp->rttvar = tp->rttvar - (tp->rttvar >> net->sctp.rto_beta)
-			+ (((__u32)abs((__s64)tp->srtt - (__s64)rtt)) >> net->sctp.rto_beta);
-		tp->srtt = tp->srtt - (tp->srtt >> net->sctp.rto_alpha)
-			+ (rtt >> net->sctp.rto_alpha);
+		rto_beta = READ_ONCE(net->sctp.rto_beta);
+		if (rto_beta < 32)
+			tp->rttvar = tp->rttvar - (tp->rttvar >> rto_beta)
+				+ (((__u32)abs((__s64)tp->srtt - (__s64)rtt)) >> rto_beta);
+		rto_alpha = READ_ONCE(net->sctp.rto_alpha);
+		if (rto_alpha < 32)
+			tp->srtt = tp->srtt - (tp->srtt >> rto_alpha)
+				+ (rtt >> rto_alpha);
 	} else {
 		/* 6.3.1 C2) When the first RTT measurement R is made, set
 		 * SRTT <- R, RTTVAR <- R/2.
Signature · 1 line
2.51.2.1026.g39e6a42477-goog
maintainer
#1 lore raw
Quoted 52 lines · Eric Dumazet

syzbot reported a possible shift-out-of-bounds [1]

Blamed commit added rto_alpha_max and rto_beta_max set to 1000.

It is unclear if some sctp users are setting very large rto_alpha and/or rto_beta.

In order to prevent user regression, perform the test at run time.

Also add READ_ONCE() annotations as sysctl values can change under us.

[1]

UBSAN: shift-out-of-bounds in net/sctp/transport.c:509:41
shift exponent 64 is too large for 32-bit type 'unsigned int'
CPU: 0 UID: 0 PID: 16704 Comm: syz.2.2320 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/02/2025
Call Trace:
 <TASK>
  __dump_stack lib/dump_stack.c:94 [inline]
  dump_stack_lvl+0x16c/0x1f0 lib/dump_stack.c:120
  ubsan_epilogue lib/ubsan.c:233 [inline]
  __ubsan_handle_shift_out_of_bounds+0x27f/0x420 lib/ubsan.c:494
  sctp_transport_update_rto.cold+0x1c/0x34b net/sctp/transport.c:509
  sctp_check_transmitted+0x11c4/0x1c30 net/sctp/outqueue.c:1502
  sctp_outq_sack+0x4ef/0x1b20 net/sctp/outqueue.c:1338
  sctp_cmd_process_sack net/sctp/sm_sideeffect.c:840 [inline]
  sctp_cmd_interpreter net/sctp/sm_sideeffect.c:1372 [inline]
Fixes b58537a1f562 ("net: sctp: fix permissions for rto_alpha and rto_beta knobs")
Reported-by [email protected]
Cc Daniel Borkmann <[email protected]>
---
 net/sctp/transport.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
net/sctp/transport.c +1 -0
index 0d48c61fe6adefc1a9c56ca1b8ab00072825d9e6..0c56d9673cc137e3f1a64311e79bd41db2cb1282 100644
@@ -486,6 +486,7 @@ void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt)
 
        if (tp->rttvar || tp->srtt) {
                struct net *net = tp->asoc->base.net;
+               unsigned int rto_beta, rto_alpha;
                /* 6.3.1 C3) When a new RTT measurement R' is made, set
                 * RTTVAR <- (1 - RTO.Beta) * RTTVAR + RTO.Beta * |SRTT - R'|
                 * SRTT <- (1 - RTO.Alpha) * SRTT + RTO.Alpha * R'

net/sctp/transport.c void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt) · line 502

Quoted 9 lines
net/sctp/transport.c +2 -4
@@ -497,10 +498,14 @@ void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt)
                 * For example, assuming the default value of RTO.Alpha of
                 * 1/8, rto_alpha would be expressed as 3.
                 */
-               tp->rttvar = tp->rttvar - (tp->rttvar >> net->sctp.rto_beta)
-                       + (((__u32)abs((__s64)tp->srtt - (__s64)rtt)) >> net->sctp.rto_beta);
-               tp->srtt = tp->srtt - (tp->srtt >> net->sctp.rto_alpha)
-                       + (rtt >> net->sctp.rto_alpha);
+               rto_beta = READ_ONCE(net->sctp.rto_beta);
+               if (rto_beta < 32)

Wouldn't be better to do:

rto_beta = min(READ_ONCE(net->sctp.rto_beta), 31U); ?

so that when rto_alpha >= 32, the update will not be skipped entirely.

Quoted 12 lines
net/sctp/transport.c +6 -1
+                       tp->rttvar = tp->rttvar - (tp->rttvar >> rto_beta)
+                               + (((__u32)abs((__s64)tp->srtt - (__s64)rtt)) >> rto_beta);
+               rto_alpha = READ_ONCE(net->sctp.rto_alpha);
+               if (rto_alpha < 32)
+                       tp->srtt = tp->srtt - (tp->srtt >> rto_alpha)
+                               + (rtt >> rto_alpha);
        } else {
                /* 6.3.1 C2) When the first RTT measurement R is made, set
                 * SRTT <- R, RTTVAR <- R/2.
--

2.51.2.1026.g39e6a42477-goog

#2 lore raw
Quoted 65 lines · Xin Long
Quoted 52 lines · Eric Dumazet

syzbot reported a possible shift-out-of-bounds [1]

Blamed commit added rto_alpha_max and rto_beta_max set to 1000.

It is unclear if some sctp users are setting very large rto_alpha and/or rto_beta.

In order to prevent user regression, perform the test at run time.

Also add READ_ONCE() annotations as sysctl values can change under us.

[1]

UBSAN: shift-out-of-bounds in net/sctp/transport.c:509:41
shift exponent 64 is too large for 32-bit type 'unsigned int'
CPU: 0 UID: 0 PID: 16704 Comm: syz.2.2320 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/02/2025
Call Trace:
 <TASK>
  __dump_stack lib/dump_stack.c:94 [inline]
  dump_stack_lvl+0x16c/0x1f0 lib/dump_stack.c:120
  ubsan_epilogue lib/ubsan.c:233 [inline]
  __ubsan_handle_shift_out_of_bounds+0x27f/0x420 lib/ubsan.c:494
  sctp_transport_update_rto.cold+0x1c/0x34b net/sctp/transport.c:509
  sctp_check_transmitted+0x11c4/0x1c30 net/sctp/outqueue.c:1502
  sctp_outq_sack+0x4ef/0x1b20 net/sctp/outqueue.c:1338
  sctp_cmd_process_sack net/sctp/sm_sideeffect.c:840 [inline]
  sctp_cmd_interpreter net/sctp/sm_sideeffect.c:1372 [inline]
Fixes b58537a1f562 ("net: sctp: fix permissions for rto_alpha and rto_beta knobs")
Reported-by [email protected]
Cc Daniel Borkmann <[email protected]>
---
 net/sctp/transport.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
net/sctp/transport.c +1 -0
index 0d48c61fe6adefc1a9c56ca1b8ab00072825d9e6..0c56d9673cc137e3f1a64311e79bd41db2cb1282 100644
@@ -486,6 +486,7 @@ void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt)
 
        if (tp->rttvar || tp->srtt) {
                struct net *net = tp->asoc->base.net;
+               unsigned int rto_beta, rto_alpha;
                /* 6.3.1 C3) When a new RTT measurement R' is made, set
                 * RTTVAR <- (1 - RTO.Beta) * RTTVAR + RTO.Beta * |SRTT - R'|
                 * SRTT <- (1 - RTO.Alpha) * SRTT + RTO.Alpha * R'

net/sctp/transport.c void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt) · line 502

Quoted 9 lines
net/sctp/transport.c +2 -4
@@ -497,10 +498,14 @@ void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt)
                 * For example, assuming the default value of RTO.Alpha of
                 * 1/8, rto_alpha would be expressed as 3.
                 */
-               tp->rttvar = tp->rttvar - (tp->rttvar >> net->sctp.rto_beta)
-                       + (((__u32)abs((__s64)tp->srtt - (__s64)rtt)) >> net->sctp.rto_beta);
-               tp->srtt = tp->srtt - (tp->srtt >> net->sctp.rto_alpha)
-                       + (rtt >> net->sctp.rto_alpha);
+               rto_beta = READ_ONCE(net->sctp.rto_beta);
+               if (rto_beta < 32)

Wouldn't be better to do:

Quoted 3 lines

rto_beta = min(READ_ONCE(net->sctp.rto_beta), 31U); ?

so that when rto_alpha >= 32, the update will not be skipped entirely.

Skipping or not the update is a matter of taste really.

If someone was setting 30 or more, it was expecting tp->rttvar and tp->srtt to not change at all,

Quoted 13 lines
Quoted 13 lines
net/sctp/transport.c +6 -1
+                       tp->rttvar = tp->rttvar - (tp->rttvar >> rto_beta)
+                               + (((__u32)abs((__s64)tp->srtt - (__s64)rtt)) >> rto_beta);
+               rto_alpha = READ_ONCE(net->sctp.rto_alpha);
+               if (rto_alpha < 32)
+                       tp->srtt = tp->srtt - (tp->srtt >> rto_alpha)
+                               + (rtt >> rto_alpha);
        } else {
                /* 6.3.1 C2) When the first RTT measurement R is made, set
                 * SRTT <- R, RTTVAR <- R/2.
--

2.51.2.1026.g39e6a42477-goog

maintainer
#3 lore raw
Quoted 67 lines · Eric Dumazet
Quoted 65 lines · Xin Long
Quoted 52 lines · Eric Dumazet

syzbot reported a possible shift-out-of-bounds [1]

Blamed commit added rto_alpha_max and rto_beta_max set to 1000.

It is unclear if some sctp users are setting very large rto_alpha and/or rto_beta.

In order to prevent user regression, perform the test at run time.

Also add READ_ONCE() annotations as sysctl values can change under us.

[1]

UBSAN: shift-out-of-bounds in net/sctp/transport.c:509:41
shift exponent 64 is too large for 32-bit type 'unsigned int'
CPU: 0 UID: 0 PID: 16704 Comm: syz.2.2320 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/02/2025
Call Trace:
 <TASK>
  __dump_stack lib/dump_stack.c:94 [inline]
  dump_stack_lvl+0x16c/0x1f0 lib/dump_stack.c:120
  ubsan_epilogue lib/ubsan.c:233 [inline]
  __ubsan_handle_shift_out_of_bounds+0x27f/0x420 lib/ubsan.c:494
  sctp_transport_update_rto.cold+0x1c/0x34b net/sctp/transport.c:509
  sctp_check_transmitted+0x11c4/0x1c30 net/sctp/outqueue.c:1502
  sctp_outq_sack+0x4ef/0x1b20 net/sctp/outqueue.c:1338
  sctp_cmd_process_sack net/sctp/sm_sideeffect.c:840 [inline]
  sctp_cmd_interpreter net/sctp/sm_sideeffect.c:1372 [inline]
Fixes b58537a1f562 ("net: sctp: fix permissions for rto_alpha and rto_beta knobs")
Reported-by [email protected]
Cc Daniel Borkmann <[email protected]>
---
 net/sctp/transport.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
net/sctp/transport.c +1 -0
index 0d48c61fe6adefc1a9c56ca1b8ab00072825d9e6..0c56d9673cc137e3f1a64311e79bd41db2cb1282 100644
@@ -486,6 +486,7 @@ void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt)
 
        if (tp->rttvar || tp->srtt) {
                struct net *net = tp->asoc->base.net;
+               unsigned int rto_beta, rto_alpha;
                /* 6.3.1 C3) When a new RTT measurement R' is made, set
                 * RTTVAR <- (1 - RTO.Beta) * RTTVAR + RTO.Beta * |SRTT - R'|
                 * SRTT <- (1 - RTO.Alpha) * SRTT + RTO.Alpha * R'

net/sctp/transport.c void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt) · line 502

Quoted 9 lines
net/sctp/transport.c +2 -4
@@ -497,10 +498,14 @@ void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt)
                 * For example, assuming the default value of RTO.Alpha of
                 * 1/8, rto_alpha would be expressed as 3.
                 */
-               tp->rttvar = tp->rttvar - (tp->rttvar >> net->sctp.rto_beta)
-                       + (((__u32)abs((__s64)tp->srtt - (__s64)rtt)) >> net->sctp.rto_beta);
-               tp->srtt = tp->srtt - (tp->srtt >> net->sctp.rto_alpha)
-                       + (rtt >> net->sctp.rto_alpha);
+               rto_beta = READ_ONCE(net->sctp.rto_beta);
+               if (rto_beta < 32)

Wouldn't be better to do:

Quoted 9 lines
Quoted 3 lines

rto_beta = min(READ_ONCE(net->sctp.rto_beta), 31U); ?

so that when rto_alpha >= 32, the update will not be skipped entirely.

Skipping or not the update is a matter of taste really.

If someone was setting 30 or more, it was expecting tp->rttvar and tp->srtt to not change at all,

But you do see (u32) >> 31 can be 1, that makes the tp->rttvar/srtt change slightly.
So the 'expecting no change' is from practical experience, right?

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
net/sctp/transport.c +6 -1
+                       tp->rttvar = tp->rttvar - (tp->rttvar >> rto_beta)
+                               + (((__u32)abs((__s64)tp->srtt - (__s64)rtt)) >> rto_beta);
+               rto_alpha = READ_ONCE(net->sctp.rto_alpha);
+               if (rto_alpha < 32)
+                       tp->srtt = tp->srtt - (tp->srtt >> rto_alpha)
+                               + (rtt >> rto_alpha);
        } else {
                /* 6.3.1 C2) When the first RTT measurement R is made, set
                 * SRTT <- R, RTTVAR <- R/2.
--

2.51.2.1026.g39e6a42477-goog

#4 lore raw
Quoted 73 lines · Xin Long
Quoted 71 lines · Eric Dumazet
Quoted 68 lines · Xin Long
Quoted 52 lines · Eric Dumazet

syzbot reported a possible shift-out-of-bounds [1]

Blamed commit added rto_alpha_max and rto_beta_max set to 1000.

It is unclear if some sctp users are setting very large rto_alpha and/or rto_beta.

In order to prevent user regression, perform the test at run time.

Also add READ_ONCE() annotations as sysctl values can change under us.

[1]

UBSAN: shift-out-of-bounds in net/sctp/transport.c:509:41
shift exponent 64 is too large for 32-bit type 'unsigned int'
CPU: 0 UID: 0 PID: 16704 Comm: syz.2.2320 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/02/2025
Call Trace:
 <TASK>
  __dump_stack lib/dump_stack.c:94 [inline]
  dump_stack_lvl+0x16c/0x1f0 lib/dump_stack.c:120
  ubsan_epilogue lib/ubsan.c:233 [inline]
  __ubsan_handle_shift_out_of_bounds+0x27f/0x420 lib/ubsan.c:494
  sctp_transport_update_rto.cold+0x1c/0x34b net/sctp/transport.c:509
  sctp_check_transmitted+0x11c4/0x1c30 net/sctp/outqueue.c:1502
  sctp_outq_sack+0x4ef/0x1b20 net/sctp/outqueue.c:1338
  sctp_cmd_process_sack net/sctp/sm_sideeffect.c:840 [inline]
  sctp_cmd_interpreter net/sctp/sm_sideeffect.c:1372 [inline]
Fixes b58537a1f562 ("net: sctp: fix permissions for rto_alpha and rto_beta knobs")
Reported-by [email protected]
Cc Daniel Borkmann <[email protected]>
---
 net/sctp/transport.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
net/sctp/transport.c +1 -0
index 0d48c61fe6adefc1a9c56ca1b8ab00072825d9e6..0c56d9673cc137e3f1a64311e79bd41db2cb1282 100644
@@ -486,6 +486,7 @@ void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt)
 
        if (tp->rttvar || tp->srtt) {
                struct net *net = tp->asoc->base.net;
+               unsigned int rto_beta, rto_alpha;
                /* 6.3.1 C3) When a new RTT measurement R' is made, set
                 * RTTVAR <- (1 - RTO.Beta) * RTTVAR + RTO.Beta * |SRTT - R'|
                 * SRTT <- (1 - RTO.Alpha) * SRTT + RTO.Alpha * R'

net/sctp/transport.c void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt) · line 502

Quoted 9 lines
net/sctp/transport.c +2 -4
@@ -497,10 +498,14 @@ void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt)
                 * For example, assuming the default value of RTO.Alpha of
                 * 1/8, rto_alpha would be expressed as 3.
                 */
-               tp->rttvar = tp->rttvar - (tp->rttvar >> net->sctp.rto_beta)
-                       + (((__u32)abs((__s64)tp->srtt - (__s64)rtt)) >> net->sctp.rto_beta);
-               tp->srtt = tp->srtt - (tp->srtt >> net->sctp.rto_alpha)
-                       + (rtt >> net->sctp.rto_alpha);
+               rto_beta = READ_ONCE(net->sctp.rto_beta);
+               if (rto_beta < 32)

Wouldn't be better to do:

rto_beta = min(READ_ONCE(net->sctp.rto_beta), 31U); ?

so that when rto_alpha >= 32, the update will not be skipped entirely.

Quoted 8 lines
Quoted 5 lines

Skipping or not the update is a matter of taste really.

If someone was setting 30 or more, it was expecting tp->rttvar and tp->srtt to not change at all,

But you do see (u32) >> 31 can be 1, that makes the tp->rttvar/srtt change slightly.
So the 'expecting no change' is from practical experience, right?

EWMA31 on rtt is a NOP, unless rtt is more than 2^31

A - (A >> 31) + (RTT >> 31) -> A

Is SCTP dealing with this level of RTT ?

If yes, I would suggest switching to u64

maintainer Acked-by
#5 lore raw
Quoted 84 lines · Eric Dumazet
Quoted 73 lines · Xin Long
Quoted 71 lines · Eric Dumazet
Quoted 68 lines · Xin Long
Quoted 52 lines · Eric Dumazet

syzbot reported a possible shift-out-of-bounds [1]

Blamed commit added rto_alpha_max and rto_beta_max set to 1000.

It is unclear if some sctp users are setting very large rto_alpha and/or rto_beta.

In order to prevent user regression, perform the test at run time.

Also add READ_ONCE() annotations as sysctl values can change under us.

[1]

UBSAN: shift-out-of-bounds in net/sctp/transport.c:509:41
shift exponent 64 is too large for 32-bit type 'unsigned int'
CPU: 0 UID: 0 PID: 16704 Comm: syz.2.2320 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/02/2025
Call Trace:
 <TASK>
  __dump_stack lib/dump_stack.c:94 [inline]
  dump_stack_lvl+0x16c/0x1f0 lib/dump_stack.c:120
  ubsan_epilogue lib/ubsan.c:233 [inline]
  __ubsan_handle_shift_out_of_bounds+0x27f/0x420 lib/ubsan.c:494
  sctp_transport_update_rto.cold+0x1c/0x34b net/sctp/transport.c:509
  sctp_check_transmitted+0x11c4/0x1c30 net/sctp/outqueue.c:1502
  sctp_outq_sack+0x4ef/0x1b20 net/sctp/outqueue.c:1338
  sctp_cmd_process_sack net/sctp/sm_sideeffect.c:840 [inline]
  sctp_cmd_interpreter net/sctp/sm_sideeffect.c:1372 [inline]
Fixes b58537a1f562 ("net: sctp: fix permissions for rto_alpha and rto_beta knobs")
Reported-by [email protected]
Cc Daniel Borkmann <[email protected]>
---
 net/sctp/transport.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
net/sctp/transport.c +1 -0
index 0d48c61fe6adefc1a9c56ca1b8ab00072825d9e6..0c56d9673cc137e3f1a64311e79bd41db2cb1282 100644
@@ -486,6 +486,7 @@ void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt)
 
        if (tp->rttvar || tp->srtt) {
                struct net *net = tp->asoc->base.net;
+               unsigned int rto_beta, rto_alpha;
                /* 6.3.1 C3) When a new RTT measurement R' is made, set
                 * RTTVAR <- (1 - RTO.Beta) * RTTVAR + RTO.Beta * |SRTT - R'|
                 * SRTT <- (1 - RTO.Alpha) * SRTT + RTO.Alpha * R'

net/sctp/transport.c void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt) · line 502

Quoted 9 lines
net/sctp/transport.c +2 -4
@@ -497,10 +498,14 @@ void sctp_transport_update_rto(struct sctp_transport *tp, __u32 rtt)
                 * For example, assuming the default value of RTO.Alpha of
                 * 1/8, rto_alpha would be expressed as 3.
                 */
-               tp->rttvar = tp->rttvar - (tp->rttvar >> net->sctp.rto_beta)
-                       + (((__u32)abs((__s64)tp->srtt - (__s64)rtt)) >> net->sctp.rto_beta);
-               tp->srtt = tp->srtt - (tp->srtt >> net->sctp.rto_alpha)
-                       + (rtt >> net->sctp.rto_alpha);
+               rto_beta = READ_ONCE(net->sctp.rto_beta);
+               if (rto_beta < 32)

Wouldn't be better to do:

rto_beta = min(READ_ONCE(net->sctp.rto_beta), 31U); ?

so that when rto_alpha >= 32, the update will not be skipped entirely.

Quoted 8 lines
Quoted 5 lines

Skipping or not the update is a matter of taste really.

If someone was setting 30 or more, it was expecting tp->rttvar and tp->srtt to not change at all,

But you do see (u32) >> 31 can be 1, that makes the tp->rttvar/srtt change slightly.
So the 'expecting no change' is from practical experience, right?

Quoted 6 lines

EWMA31 on rtt is a NOP, unless rtt is more than 2^31

A - (A >> 31) + (RTT >> 31) -> A

Is SCTP dealing with this level of RTT ?

I would not think so, the connection must have broken before that :-)

THanks.

#6 lore raw
In reply to Eric Dumazet
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 8 lines · On Thu, 6 Nov 2025 11:10:54 +0000 you wrote:

syzbot reported a possible shift-out-of-bounds [1]

Blamed commit added rto_alpha_max and rto_beta_max set to 1000.

It is unclear if some sctp users are setting very large rto_alpha and/or rto_beta.

[...]

Here is the summary with links:
- [net] sctp: prevent possible shift-out-of-bounds in sctp_transport_update_rto

    https://git.kernel.org/netdev/net/c/1534ff77757e

You are awesome, thank you!

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