Skip to content

Commit 05fb3db

Browse files
rmurphy-armwilldeacon
authored andcommitted
arm64: csum: Fix handling of bad packets
Although iph is expected to point to at least 20 bytes of valid memory, ihl may be bogus, for example on reception of a corrupt packet. If it happens to be less than 5, we really don't want to run away and dereference 16GB worth of memory until it wraps back to exactly zero... Fixes: 0e455d8 ("arm64: Implement optimised IP checksum helpers") Reported-by: guodeqing <[email protected]> Signed-off-by: Robin Murphy <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 835d1c3 commit 05fb3db

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

arch/arm64/include/asm/checksum.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
2424
{
2525
__uint128_t tmp;
2626
u64 sum;
27+
int n = ihl; /* we want it signed */
2728

2829
tmp = *(const __uint128_t *)iph;
2930
iph += 16;
30-
ihl -= 4;
31+
n -= 4;
3132
tmp += ((tmp >> 64) | (tmp << 64));
3233
sum = tmp >> 64;
3334
do {
3435
sum += *(const u32 *)iph;
3536
iph += 4;
36-
} while (--ihl);
37+
} while (--n > 0);
3738

3839
sum += ((sum >> 32) | (sum << 32));
3940
return csum_fold((__force u32)(sum >> 32));

0 commit comments

Comments
 (0)