sctp: validate stream count in sctp_process_strreset_inreq()
Subsystems (3)
PATCH v2 1/1 sctp: validate stream count in sctp_process_strreset_inreq()
When processing a RESET_IN_REQUEST from a peer, sctp_process_strreset_inreq() derives the stream count from the parameter length but does not check whether the resulting RESET_OUT_REQUEST would exceed SCTP_MAX_CHUNK_LEN.
The OUT request header (sctp_strreset_outreq, 16 bytes) is 8 bytes larger than the IN request header (sctp_strreset_inreq, 8 bytes). Generally, the IP payload is bounded to 65535 bytes, so the stream list cannot be large enough to trigger the overflow. However, on interfaces with MTU > 65535 (e.g., loopback with IPv6 jumbograms), a stream list that fits within the incoming IN parameter can cause a __u16 overflow in sctp_make_strreset_req() when computing the OUT request size, leading to an undersized skb allocation and a kernel BUG:
net/core/skbuff.c:207 skb_panic
net/core/skbuff.c:2625 skb_put
net/sctp/sm_make_chunk.c:1535 sctp_addto_chunk net/sctp/sm_make_chunk.c:3695 sctp_make_strreset_req
net/sctp/stream.c:655 sctp_process_strreset_inreq
The local setsockopt path validates the generated reset request size. However, for an incoming-only reset, it accounts for the smaller IN request even though the peer must generate an OUT request with the same stream list. Such a request cannot be completed successfully by the peer.
Reject peer IN requests whose corresponding OUT request would exceed SCTP_MAX_CHUNK_LEN. Also tighten the local check so it does not send an IN request that would require an oversized OUT request from the peer.
---
v2: Add the OUT request length check to the send path, as suggested by Xin Long.
net/sctp/stream.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/sctp/stream.c +5 -1
@@ -308,7 +308,8 @@ int sctp_send_reset_streams(struct sctp_association *asoc, goto out; param_len += str_nums *sizeof (__u16) + -sizeof (struct sctp_strreset_inreq ); + (out ?sizeof (struct sctp_strreset_inreq ) + :sizeof (struct sctp_strreset_outreq )); } if (param_len > SCTP_MAX_CHUNK_LEN -
@@ -639,6 +640,9 @@ struct sctp_chunk *sctp_process_strreset_inreq( nums = (ntohs (param.p->length) -sizeof (*inreq)) /sizeof (__u16); str_p = inreq->list_of_streams; +if (nums *sizeof (__u16) +sizeof (struct sctp_strreset_outreq ) > +SCTP_MAX_CHUNK_LEN -sizeof (struct sctp_reconf_chunk )) + goto out;for (i =0 ; i < nums; i++) {if (ntohs (str_p[i]) >= stream->outcnt) { result =SCTP_STRRESET_ERR_WRONG_SSN ;
Signature · 1 line
2.53.0
Quoted 47 lines · On Thu, 9 Jul 2026 21:07:18 -0400 "Cen Zhang (Microsoft)" <[email protected]>…
When processing a
RESET_IN_REQUESTfrom a peer,sctp_process_strreset_inreq()derives the stream count from the parameter length but does not check whether the resultingRESET_OUT_REQUESTwould exceedSCTP_MAX_CHUNK_LEN.The OUT request header (
sctp_strreset_outreq, 16 bytes) is 8 bytes larger than the IN request header (sctp_strreset_inreq, 8 bytes). Generally, the IP payload is bounded to 65535 bytes, so the stream list cannot be large enough to trigger the overflow. However, on interfaces with MTU > 65535 (e.g., loopback with IPv6 jumbograms), a stream list that fits within the incoming IN parameter can cause a__u16overflow insctp_make_strreset_req()when computing the OUT request size, leading to an undersized skb allocation and a kernel BUG:
net/core/skbuff.c:207skb_panic
net/core/skbuff.c:2625skb_put
net/sctp/sm_make_chunk.c:1535sctp_addto_chunknet/sctp/sm_make_chunk.c:3695sctp_make_strreset_req
net/sctp/stream.c:655sctp_process_strreset_inreqThe local setsockopt path validates the generated reset request size. However, for an incoming-only reset, it accounts for the smaller IN request even though the peer must generate an OUT request with the same stream list. Such a request cannot be completed successfully by the peer.
Reject peer IN requests whose corresponding OUT request would exceed
SCTP_MAX_CHUNK_LEN. Also tighten the local check so it does not send an IN request that would require an oversized OUT request from the peer.Fixes 7f9d68ac944e ("sctp: implement sender-side procedures for SSN Reset Request Parameter")Reported-by [email protected]Suggested-by Xin Long <[email protected]>Signed-off-by Cen Zhang (Microsoft) <[email protected]>---
v2: Add the OUT request length check to the send path, as suggested by Xin Long.net/sctp/stream.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)net/sctp/stream.c +0
-0
net/sctp/stream.c int sctp_send_reset_streams(struct sctp_association *asoc, · line 312
Quoted 6 lines
net/sctp/stream.c +2
-1@@ -308,7 +308,8 @@ int sctp_send_reset_streams(struct sctp_association *asoc, goto out; param_len += str_nums *sizeof (__u16) + -sizeof (struct sctp_strreset_inreq ); + (out ?sizeof (struct sctp_strreset_inreq ) + :sizeof (struct sctp_strreset_outreq ));
Does it really make any sense to have a connection with the 32k streams that would be needed in order to send a maximal length request? (Or more likely a user requesting the same streams be reset multiple times.) So an initial check that str_nums < SOME_CONSTANT_JUST_BELOW_32K would do.
Looking at the code I'm sure the kmalloc() shouldn't be done in the 'str_nums == 0' case either.
In fact it is probably worth doing the kmalloc() earlier to avoid two scans of the array.
I even wonder if it should be possible to allocate the chunk without filling in the data and then put the values in afterwards (freeing the chunk if there is an error).
Then there is the code that reverts the state to OPEN if sctp_send_reconf() fails - nothing check that is the original state.
David
Quoted 13 lines
net/sctp/stream.c +3
-0} if (param_len > SCTP_MAX_CHUNK_LEN -@@ -639,6 +640,9 @@ struct sctp_chunk *sctp_process_strreset_inreq( nums = (ntohs (param.p->length) -sizeof (*inreq)) /sizeof (__u16); str_p = inreq->list_of_streams; +if (nums *sizeof (__u16) +sizeof (struct sctp_strreset_outreq ) > +SCTP_MAX_CHUNK_LEN -sizeof (struct sctp_reconf_chunk )) + goto out;for (i =0 ; i < nums; i++) {if (ntohs (str_p[i]) >= stream->outcnt) { result =SCTP_STRRESET_ERR_WRONG_SSN ;
Quoted 53 lines · David Laight
Quoted 49 lines · On Thu, 9 Jul 2026 21:07:18 -0400 "Cen Zhang (Microsoft)" <[email protected]>…
When processing a
RESET_IN_REQUESTfrom a peer,sctp_process_strreset_inreq()derives the stream count from the parameter length but does not check whether the resultingRESET_OUT_REQUESTwould exceedSCTP_MAX_CHUNK_LEN.The OUT request header (
sctp_strreset_outreq, 16 bytes) is 8 bytes larger than the IN request header (sctp_strreset_inreq, 8 bytes). Generally, the IP payload is bounded to 65535 bytes, so the stream list cannot be large enough to trigger the overflow. However, on interfaces with MTU > 65535 (e.g., loopback with IPv6 jumbograms), a stream list that fits within the incoming IN parameter can cause a__u16overflow insctp_make_strreset_req()when computing the OUT request size, leading to an undersized skb allocation and a kernel BUG:
net/core/skbuff.c:207skb_panic
net/core/skbuff.c:2625skb_put
net/sctp/sm_make_chunk.c:1535sctp_addto_chunknet/sctp/sm_make_chunk.c:3695sctp_make_strreset_req
net/sctp/stream.c:655sctp_process_strreset_inreqThe local setsockopt path validates the generated reset request size. However, for an incoming-only reset, it accounts for the smaller IN request even though the peer must generate an OUT request with the same stream list. Such a request cannot be completed successfully by the peer.
Reject peer IN requests whose corresponding OUT request would exceed
SCTP_MAX_CHUNK_LEN. Also tighten the local check so it does not send an IN request that would require an oversized OUT request from the peer.Fixes 7f9d68ac944e ("sctp: implement sender-side procedures for SSN Reset Request Parameter")Reported-by [email protected]Suggested-by Xin Long <[email protected]>Signed-off-by Cen Zhang (Microsoft) <[email protected]>---
v2: Add the OUT request length check to the send path, as suggested by Xin Long.net/sctp/stream.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)net/sctp/stream.c +0
-0@@ -308,7 +308,8 @@ int sctp_send_reset_streams(struct sctp_association *asoc, goto out;
Quoted 10 lines
net/sctp/stream.c int sctp_send_reset_streams(struct sctp_association *asoc, · line 312
Quoted 4 lines
net/sctp/stream.c +2
-1param_len += str_nums *sizeof (__u16) + -sizeof (struct sctp_strreset_inreq ); + (out ?sizeof (struct sctp_strreset_inreq ) + :sizeof (struct sctp_strreset_outreq ));Does it really make any sense to have a connection with the 32k streams that would be needed in order to send a maximal length request? (Or more likely a user requesting the same streams be reset multiple times.) So an initial check that
str_nums<SOME_CONSTANT_JUST_BELOW_32Kwould do.
Yes, that would be a simpler fix.
However, 32K is not a limit defined by the RFC. While 32K streams may seem excessive in practice, we cannot say that such a configuration is invalid. If an application legitimately needs more than that, it would be difficult to argue that it is not using SCTP correctly.
Quoted 11 lines
Looking at the code I'm sure the
kmalloc()shouldn't be done in the 'str_nums== 0' case either.
In fact it is probably worth doing thekmalloc()earlier to avoid two scans of the array.
I even wonder if it should be possible to allocate the chunk without filling in the data and then put the values in afterwards (freeing the chunk if there is an error).Then there is the code that reverts the state to OPEN if
sctp_send_reconf()fails - nothing check that is the original state.
That would be another issue that we can address separately. It would be great if you could follow up on this one. :-)
Quoted 8 lines
David
Quoted 5 lines
net/sctp/stream.c +0
-0} if (param_len > SCTP_MAX_CHUNK_LEN -@@ -639,6 +640,9 @@ struct sctp_chunk *sctp_process_strreset_inreq(
Quoted 9 lines
net/sctp/stream.c struct sctp_chunk *sctp_process_strreset_inreq( · line 648
Quoted 8 lines
net/sctp/stream.c +3
-0nums = (ntohs (param.p->length) -sizeof (*inreq)) /sizeof (__u16); str_p = inreq->list_of_streams; +if (nums *sizeof (__u16) +sizeof (struct sctp_strreset_outreq ) > +SCTP_MAX_CHUNK_LEN -sizeof (struct sctp_reconf_chunk )) + goto out;for (i =0 ; i < nums; i++) {if (ntohs (str_p[i]) >= stream->outcnt) { result =SCTP_STRRESET_ERR_WRONG_SSN ;
Thanks.
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 15 lines · On Thu, 9 Jul 2026 21:07:18 -0400 you wrote:
When processing a
RESET_IN_REQUESTfrom a peer,sctp_process_strreset_inreq()derives the stream count from the parameter length but does not check whether the resultingRESET_OUT_REQUESTwould exceedSCTP_MAX_CHUNK_LEN.The OUT request header (
sctp_strreset_outreq, 16 bytes) is 8 bytes larger than the IN request header (sctp_strreset_inreq, 8 bytes). Generally, the IP payload is bounded to 65535 bytes, so the stream list cannot be large enough to trigger the overflow. However, on interfaces with MTU > 65535 (e.g., loopback with IPv6 jumbograms), a stream list that fits within the incoming IN parameter can cause a__u16overflow insctp_make_strreset_req()when computing the OUT request size, leading to an undersized skb allocation and a kernel BUG:
Quoted 1 line
[...]
Here is the summary with links:
- [net,v2] sctp: validate stream count in sctp_process_strreset_inreq()
https://git.kernel.org/netdev/net/c/18ae07691d43
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html