* [PATCH net] sctp: Fix undefined behavior in left shift operation
@ 2025-02-18 8:12 Yu-Chun Lin
2025-02-20 3:10 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Yu-Chun Lin @ 2025-02-18 8:12 UTC (permalink / raw)
To: marcelo.leitner, lucien.xin, davem, edumazet, kuba, pabeni
Cc: linux-sctp, netdev, linux-kernel, jserv, visitorckw, Yu-Chun Lin
According to the C11 standard (ISO/IEC 9899:2011, 6.5.7):
"If E1 has a signed type and E1 x 2^E2 is not representable in the result
type, the behavior is undefined."
Shifting 1 << 31 causes signed integer overflow, which leads to undefined
behavior.
Fix this by explicitly using '1U << 31' to ensure the shift operates on
an unsigned type, avoiding undefined behavior.
Signed-off-by: Yu-Chun Lin <eleanor15x@gmail.com>
---
net/sctp/stream.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/sctp/stream.c b/net/sctp/stream.c
index c241cc552e8d..bfcff6d6a438 100644
--- a/net/sctp/stream.c
+++ b/net/sctp/stream.c
@@ -735,7 +735,7 @@ struct sctp_chunk *sctp_process_strreset_tsnreq(
* value SHOULD be the smallest TSN not acknowledged by the
* receiver of the request plus 2^31.
*/
- init_tsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + (1 << 31);
+ init_tsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + (1U << 31);
sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_INITIAL,
init_tsn, GFP_ATOMIC);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] sctp: Fix undefined behavior in left shift operation
2025-02-18 8:12 [PATCH net] sctp: Fix undefined behavior in left shift operation Yu-Chun Lin
@ 2025-02-20 3:10 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-02-20 3:10 UTC (permalink / raw)
To: Yu-Chun Lin
Cc: marcelo.leitner, lucien.xin, davem, edumazet, kuba, pabeni,
linux-sctp, netdev, linux-kernel, jserv, visitorckw
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Tue, 18 Feb 2025 16:12:16 +0800 you wrote:
> According to the C11 standard (ISO/IEC 9899:2011, 6.5.7):
> "If E1 has a signed type and E1 x 2^E2 is not representable in the result
> type, the behavior is undefined."
>
> Shifting 1 << 31 causes signed integer overflow, which leads to undefined
> behavior.
>
> [...]
Here is the summary with links:
- [net] sctp: Fix undefined behavior in left shift operation
https://git.kernel.org/netdev/net/c/606572eb22c1
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-20 3:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-18 8:12 [PATCH net] sctp: Fix undefined behavior in left shift operation Yu-Chun Lin
2025-02-20 3:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox