]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
LoongArch: csum: Fix OoB access in IP checksum code for negative lengths
authorYuli Wang <wangyuli@uniontech.com>
Thu, 13 Feb 2025 04:02:40 +0000 (12:02 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 21 Feb 2025 13:01:17 +0000 (14:01 +0100)
[ Upstream commit 6287f1a8c16138c2ec750953e35039634018c84a ]

Commit 69e3a6aa6be2 ("LoongArch: Add checksum optimization for 64-bit
system") would cause an undefined shift and an out-of-bounds read.

Commit 8bd795fedb84 ("arm64: csum: Fix OoB access in IP checksum code
for negative lengths") fixes the same issue on ARM64.

Fixes: 69e3a6aa6be2 ("LoongArch: Add checksum optimization for 64-bit system")
Co-developed-by: Wentao Guan <guanwentao@uniontech.com>
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
Signed-off-by: Yuli Wang <wangyuli@uniontech.com>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/loongarch/lib/csum.c

index a5e84b403c3b34edfb4cf9ebfd12a88103c5d4fc..df309ae4045dee9274511478c8e11919e154b415 100644 (file)
@@ -25,7 +25,7 @@ unsigned int __no_sanitize_address do_csum(const unsigned char *buff, int len)
        const u64 *ptr;
        u64 data, sum64 = 0;
 
-       if (unlikely(len == 0))
+       if (unlikely(len <= 0))
                return 0;
 
        offset = (unsigned long)buff & 7;