selftest: bpf: Correct mssind comparison in test_tcp_custom_syncookie.c.
Subsystems (3)
PATCH 1/1 selftest: bpf: Correct mssind comparison in test_tcp_custom_syncookie.c.
Smatch reported a possible off-by-one in tcp_validate_cookie().
However, it's false positive because the possible range of mssind is limited from 0 to 3 by the preceding calculation.
mssind = (cookie & (3 << 6)) >> 6;
There's no real issue, but let's make Smatch happy to suppress the same reports.
--- tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c +2 -2
@@ -487,12 +487,12 @@ static int tcp_validate_cookie(struct tcp_syncookie *ctx) mssind = (cookie & (3 <<6 )) >>6 ;if (ctx->ipv4) { -if (mssind >ARRAY_SIZE (msstab4)) +if (mssind >=ARRAY_SIZE (msstab4)) goto err; ctx->attrs.mss = msstab4[mssind]; }else { -if (mssind >ARRAY_SIZE (msstab6)) +if (mssind >=ARRAY_SIZE (msstab6)) goto err; ctx->attrs.mss = msstab6[mssind];
Signature · 1 line
2.30.2
Martin KaFai Lau
reviewerQuoted 22 lines · Kuniyuki Iwashima
Smatch reported a possible off-by-one in
tcp_validate_cookie().However, it's false positive because the possible range of mssind is limited from 0 to 3 by the preceding calculation.
mssind = (cookie & (3 << 6)) >> 6;There's no real issue, but let's make Smatch happy to suppress the same reports.
Reported-by Dan Carpenter <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>--- tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c +0
-0
tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c static int tcp_validate_cookie(struct tcp_syncookie *ctx) · line 488
Quoted 2 lines
tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c +0
-0@@ -487,12 +487,12 @@ static int tcp_validate_cookie(struct tcp_syncookie *ctx) mssind = (cookie & (3 <<6 )) >>6 ;
This should have bound the mssind.
tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c static int tcp_validate_cookie(struct tcp_syncookie *ctx) · line 490
Quoted 3 lines
tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c +1
-1if (ctx->ipv4) { -if (mssind >ARRAY_SIZE (msstab4)) +if (mssind >=ARRAY_SIZE (msstab4))
Does the verifier complain without this if check?
Quoted 9 lines
tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c +1
-1goto err; ctx->attrs.mss = msstab4[mssind]; }else { -if (mssind >ARRAY_SIZE (msstab6)) +if (mssind >=ARRAY_SIZE (msstab6)) goto err; ctx->attrs.mss = msstab6[mssind];
From: Martin KaFai Lau <[email protected]>
Date: Tue, 20 Aug 2024 17:11:48 -0700
Quoted 28 lines · Kuniyuki Iwashima
Quoted 22 lines
Smatch reported a possible off-by-one in
tcp_validate_cookie().However, it's false positive because the possible range of mssind is limited from 0 to 3 by the preceding calculation.
mssind = (cookie & (3 << 6)) >> 6;There's no real issue, but let's make Smatch happy to suppress the same reports.
Reported-by Dan Carpenter <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>--- tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c +0
-0tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c static int tcp_validate_cookie(struct tcp_syncookie *ctx) · line 488
Quoted 2 lines
tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c +0
-0@@ -487,12 +487,12 @@ static int tcp_validate_cookie(struct tcp_syncookie *ctx) mssind = (cookie & (3 <<6 )) >>6 ;This should have bound the mssind.
Quoted 5 lines
tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c static int tcp_validate_cookie(struct tcp_syncookie *ctx) · line 490
Quoted 3 lines
tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c +1
-1if (ctx->ipv4) { -if (mssind >ARRAY_SIZE (msstab4)) +if (mssind >=ARRAY_SIZE (msstab4))Does the verifier complain without this if check?
It didn't :)
I'll remove the checks in v2.
Thanks!