]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
sctp: Fix undefined behavior in left shift operation
authorYu-Chun Lin <eleanor15x@gmail.com>
Tue, 18 Feb 2025 08:12:16 +0000 (16:12 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 10 Apr 2025 12:31:51 +0000 (14:31 +0200)
commitf7580f081edd9cdbaca1e31fa45bff2b2bb15cc2
tree9466f8d99243bb4f1f0724c5e9e6b5e8edb93065
parentf25a991ea1775675087dedd91cd354be0370ce30
sctp: Fix undefined behavior in left shift operation

[ Upstream commit 606572eb22c1786a3957d24307f5760bb058ca19 ]

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>
Link: https://patch.msgid.link/20250218081217.3468369-1-eleanor15x@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/sctp/stream.c