Skip to content

Commit c6a771d

Browse files
committed
arm64: csum: Disable KASAN for do_csum()
do_csum() over-reads the source buffer and therefore abuses READ_ONCE_NOCHECK() to avoid tripping up KASAN. In preparation for READ_ONCE_NOCHECK() becoming a macro, and therefore losing its '__no_sanitize_address' annotation, just annotate do_csum() explicitly and fall back to normal loads. Cc: Mark Rutland <[email protected]> Cc: Robin Murphy <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 9b4fb5c commit c6a771d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

arch/arm64/lib/csum.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ static u64 accumulate(u64 sum, u64 data)
1414
return tmp + (tmp >> 64);
1515
}
1616

17-
unsigned int do_csum(const unsigned char *buff, int len)
17+
/*
18+
* We over-read the buffer and this makes KASAN unhappy. Instead, disable
19+
* instrumentation and call kasan explicitly.
20+
*/
21+
unsigned int __no_sanitize_address do_csum(const unsigned char *buff, int len)
1822
{
1923
unsigned int offset, shift, sum;
2024
const u64 *ptr;
@@ -42,7 +46,7 @@ unsigned int do_csum(const unsigned char *buff, int len)
4246
* odd/even alignment, and means we can ignore it until the very end.
4347
*/
4448
shift = offset * 8;
45-
data = READ_ONCE_NOCHECK(*ptr++);
49+
data = *ptr++;
4650
#ifdef __LITTLE_ENDIAN
4751
data = (data >> shift) << shift;
4852
#else
@@ -58,10 +62,10 @@ unsigned int do_csum(const unsigned char *buff, int len)
5862
while (unlikely(len > 64)) {
5963
__uint128_t tmp1, tmp2, tmp3, tmp4;
6064

61-
tmp1 = READ_ONCE_NOCHECK(*(__uint128_t *)ptr);
62-
tmp2 = READ_ONCE_NOCHECK(*(__uint128_t *)(ptr + 2));
63-
tmp3 = READ_ONCE_NOCHECK(*(__uint128_t *)(ptr + 4));
64-
tmp4 = READ_ONCE_NOCHECK(*(__uint128_t *)(ptr + 6));
65+
tmp1 = *(__uint128_t *)ptr;
66+
tmp2 = *(__uint128_t *)(ptr + 2);
67+
tmp3 = *(__uint128_t *)(ptr + 4);
68+
tmp4 = *(__uint128_t *)(ptr + 6);
6569

6670
len -= 64;
6771
ptr += 8;
@@ -85,7 +89,7 @@ unsigned int do_csum(const unsigned char *buff, int len)
8589
__uint128_t tmp;
8690

8791
sum64 = accumulate(sum64, data);
88-
tmp = READ_ONCE_NOCHECK(*(__uint128_t *)ptr);
92+
tmp = *(__uint128_t *)ptr;
8993

9094
len -= 16;
9195
ptr += 2;
@@ -100,7 +104,7 @@ unsigned int do_csum(const unsigned char *buff, int len)
100104
}
101105
if (len > 0) {
102106
sum64 = accumulate(sum64, data);
103-
data = READ_ONCE_NOCHECK(*ptr);
107+
data = *ptr;
104108
len -= 8;
105109
}
106110
/*

0 commit comments

Comments
 (0)