Skip to contentSkip to conversation

selftest: bpf: Remove mssind boundary check in test_tcp_custom_syncookie.c.

PATCH Applied Kuniyuki Iwashima 3 participants 3 messages Aug 21, 2024 – Aug 22, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selftest: bpf: Remove mssind boundary check 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;

Now, the verifier does not complain without the boundary check. Let's remove the checks.

---
 .../selftests/bpf/progs/test_tcp_custom_syncookie.c   | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c +2 -9
index 44ee0d037f95..eb5cca1fce16 100644
@@ -486,17 +486,10 @@ static int tcp_validate_cookie(struct tcp_syncookie *ctx)
 		goto err;
 
 	mssind = (cookie & (3 << 6)) >> 6;
-	if (ctx->ipv4) {
-		if (mssind > ARRAY_SIZE(msstab4))
-			goto err;
-
+	if (ctx->ipv4)
 		ctx->attrs.mss = msstab4[mssind];
-	} else {
-		if (mssind > ARRAY_SIZE(msstab6))
-			goto err;
-
+	else
 		ctx->attrs.mss = msstab6[mssind];
-	}
 
 	ctx->attrs.snd_wscale = cookie & BPF_SYNCOOKIE_WSCALE_MASK;
 	ctx->attrs.rcv_wscale = ctx->attrs.snd_wscale;
Signature · 1 line
2.30.2
reviewer Acked-by on v2 1/1
#1 lore raw
Quoted 5 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.

Quoted 8 lines
   mssind = (cookie & (3 << 6)) >> 6;

Now, the verifier does not complain without the boundary check. Let's remove the checks.

reviewer Applied
#2 lore raw
Quoted 9 lines · Yonghong Song
Quoted 7 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;

Quoted 7 lines
Quoted 6 lines

Now, the verifier does not complain without the boundary check. Let's remove the checks.

Applied to bpf-next/net. Thanks.