arm64: csum: Fix pathological zero-length calls
authorRobin Murphy <robin.murphy@arm.com>
Fri, 17 Jan 2020 15:48:39 +0000 (15:48 +0000)
committerWill Deacon <will@kernel.org>
Fri, 17 Jan 2020 16:05:50 +0000 (16:05 +0000)
In validating the checksumming results of the new routine, I sadly
neglected to test its not-checksumming results. Thus it slipped through
that the one case where @buff is already dword-aligned and @len = 0
manages to defeat the tail-masking logic and behave as if @len = 8.
For a zero length it doesn't make much sense to deference @buff anyway,
so just add an early return (which has essentially zero impact on
performance).

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/lib/csum.c

index 847eb72..1f82c66 100644 (file)
@@ -20,6 +20,9 @@ unsigned int do_csum(const unsigned char *buff, int len)
        const u64 *ptr;
        u64 data, sum64 = 0;
 
+       if (unlikely(len == 0))
+               return 0;
+
        offset = (unsigned long)buff & 7;
        /*
         * This is to all intents and purposes safe, since rounding down cannot