public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Kuniyuki Iwashima <kuniyu@amazon.com>,
	Kuniyuki Iwashima <kuni1840@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Mykola Lysenko <mykolal@fb.com>,
	bpf@vger.kernel.org, Dan Carpenter <dan.carpenter@linaro.org>
Subject: Re: [PATCH v1 bpf-next] selftest: bpf: Correct mssind comparison in test_tcp_custom_syncookie.c.
Date: Tue, 20 Aug 2024 17:11:48 -0700	[thread overview]
Message-ID: <823a9e15-ec42-4c6c-a0e9-56ec63b8936b@linux.dev> (raw)
In-Reply-To: <20240819194247.27491-1-kuniyu@amazon.com>

On 8/19/24 12:42 PM, Kuniyuki Iwashima wrote:
> 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 <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/bpf/6ae12487-d3f1-488b-9514-af0dac96608f@stanley.mountain/
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> ---
>   tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c b/tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c
> index 44ee0d037f95..36b842133033 100644
> --- a/tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c
> +++ b/tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c
> @@ -487,12 +487,12 @@ static int tcp_validate_cookie(struct tcp_syncookie *ctx)
>   
>   	mssind = (cookie & (3 << 6)) >> 6;

This should have bound the mssind.

>   	if (ctx->ipv4) {
> -		if (mssind > ARRAY_SIZE(msstab4))
> +		if (mssind >= ARRAY_SIZE(msstab4))

Does the verifier complain without this if check?

>   			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];


  reply	other threads:[~2024-08-21  0:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-19 19:42 [PATCH v1 bpf-next] selftest: bpf: Correct mssind comparison in test_tcp_custom_syncookie.c Kuniyuki Iwashima
2024-08-21  0:11 ` Martin KaFai Lau [this message]
2024-08-21  1:28   ` Kuniyuki Iwashima

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=823a9e15-ec42-4c6c-a0e9-56ec63b8936b@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=dan.carpenter@linaro.org \
    --cc=daniel@iogearbox.net \
    --cc=kuni1840@gmail.com \
    --cc=kuniyu@amazon.com \
    --cc=mykolal@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox