[PATCH] LoongArch: csum: Fix OoB access in IP checksum code for negative lengths

WangYuli posted 1 patch 10 months, 1 week ago
arch/loongarch/lib/csum.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] LoongArch: csum: Fix OoB access in IP checksum code for negative lengths
Posted by WangYuli 10 months, 1 week ago
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>
---
 arch/loongarch/lib/csum.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/loongarch/lib/csum.c b/arch/loongarch/lib/csum.c
index a5e84b403c3b..df309ae4045d 100644
--- a/arch/loongarch/lib/csum.c
+++ b/arch/loongarch/lib/csum.c
@@ -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;
-- 
2.47.2
Re: [PATCH] LoongArch: csum: Fix OoB access in IP checksum code for negative lengths
Posted by Huacai Chen 10 months, 1 week ago
Applied, thanks.

Huacai

On Mon, Feb 10, 2025 at 7:46 PM WangYuli <wangyuli@uniontech.com> wrote:
>
> 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>
> ---
>  arch/loongarch/lib/csum.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/lib/csum.c b/arch/loongarch/lib/csum.c
> index a5e84b403c3b..df309ae4045d 100644
> --- a/arch/loongarch/lib/csum.c
> +++ b/arch/loongarch/lib/csum.c
> @@ -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;
> --
> 2.47.2
>