[bpf,2/4] selftests: bpf: ignore RST packets for reuseport tests
diff mbox series

Message ID 20200123165934.9584-3-lmb@cloudflare.com
State New
Headers show
Series
  • [bpf,1/4] selftests: bpf: use a temporary file in test_sockmap
Related show

Commit Message

Lorenz Bauer Jan. 23, 2020, 4:59 p.m. UTC
The reuseport tests currently suffer from a race condition: RST
packets count towards DROP_ERR_SKB_DATA, since they don't contain
a valid struct cmd. Tests will spuriously fail depending on whether
check_results is called before or after the RST is processed.

Exit the BPF program early if FIN is set.

Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
---
 .../selftests/bpf/progs/test_select_reuseport_kern.c        | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Martin KaFai Lau Jan. 23, 2020, 5:16 p.m. UTC | #1
On Thu, Jan 23, 2020 at 04:59:31PM +0000, Lorenz Bauer wrote:
> The reuseport tests currently suffer from a race condition: RST
> packets count towards DROP_ERR_SKB_DATA, since they don't contain
> a valid struct cmd. Tests will spuriously fail depending on whether
> check_results is called before or after the RST is processed.
> 
> Exit the BPF program early if FIN is set.
Make sense.
Is it a RST or FIN?  The earlier commit message said RST.
Lorenz Bauer Jan. 23, 2020, 5:18 p.m. UTC | #2
On Thu, 23 Jan 2020 at 17:16, Martin Lau <kafai@fb.com> wrote:
>
> On Thu, Jan 23, 2020 at 04:59:31PM +0000, Lorenz Bauer wrote:
> > The reuseport tests currently suffer from a race condition: RST
> > packets count towards DROP_ERR_SKB_DATA, since they don't contain
> > a valid struct cmd. Tests will spuriously fail depending on whether
> > check_results is called before or after the RST is processed.
> >
> > Exit the BPF program early if FIN is set.
> Make sense.
> Is it a RST or FIN?  The earlier commit message said RST.

FIN, sorry. I'll update in a follow up.
Martin KaFai Lau Jan. 23, 2020, 9:53 p.m. UTC | #3
On Thu, Jan 23, 2020 at 04:59:31PM +0000, Lorenz Bauer wrote:
> The reuseport tests currently suffer from a race condition: RST
> packets count towards DROP_ERR_SKB_DATA, since they don't contain
> a valid struct cmd. Tests will spuriously fail depending on whether
> check_results is called before or after the RST is processed.
> 
> Exit the BPF program early if FIN is set.
btw, it needs a Fixes tag.

Patch 4 and Patch 1 also need a Fixes tag.
Lorenz Bauer Jan. 24, 2020, 9 a.m. UTC | #4
On Thu, 23 Jan 2020 at 21:54, Martin Lau <kafai@fb.com> wrote:
>
> btw, it needs a Fixes tag.
>
> Patch 4 and Patch 1 also need a Fixes tag.

This makes me wonder, should these go via bpf or bpf-next? Do I have
to split the series then?
Daniel Borkmann Jan. 24, 2020, 9:32 a.m. UTC | #5
On 1/24/20 10:00 AM, Lorenz Bauer wrote:
> On Thu, 23 Jan 2020 at 21:54, Martin Lau <kafai@fb.com> wrote:
>>
>> btw, it needs a Fixes tag.
>>
>> Patch 4 and Patch 1 also need a Fixes tag.
> 
> This makes me wonder, should these go via bpf or bpf-next? Do I have
> to split the series then?

Lets do all of these for bpf-next since timing is very close before v5.5 release.
If needed, we can later have them picked up for 5.5 stable.

Thanks,
Daniel
John Fastabend Jan. 24, 2020, 7:45 p.m. UTC | #6
Lorenz Bauer wrote:
> The reuseport tests currently suffer from a race condition: RST
> packets count towards DROP_ERR_SKB_DATA, since they don't contain
> a valid struct cmd. Tests will spuriously fail depending on whether
> check_results is called before or after the RST is processed.
> 
> Exit the BPF program early if FIN is set.
> 
> Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
> ---
>  .../selftests/bpf/progs/test_select_reuseport_kern.c        | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c b/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c
> index d69a1f2bbbfd..26e77dcc7e91 100644
> --- a/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c
> +++ b/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c
> @@ -113,6 +113,12 @@ int _select_by_skb_data(struct sk_reuseport_md *reuse_md)
>  		data_check.skb_ports[0] = th->source;
>  		data_check.skb_ports[1] = th->dest;
>  
> +		if (th->fin)
> +			/* The connection is being torn down at the end of a
> +			 * test. It can't contain a cmd, so return early.
> +			 */
> +			return SK_PASS;
> +
>  		if ((th->doff << 2) + sizeof(*cmd) > data_check.len)
>  			GOTO_DONE(DROP_ERR_SKB_DATA);
>  		if (bpf_skb_load_bytes(reuse_md, th->doff << 2, &cmd_copy,
> -- 
> 2.20.1
> 

Acked-by: John Fastabend <john.fastabend@gmail.com>

Patch
diff mbox series

diff --git a/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c b/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c
index d69a1f2bbbfd..26e77dcc7e91 100644
--- a/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c
+++ b/tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c
@@ -113,6 +113,12 @@  int _select_by_skb_data(struct sk_reuseport_md *reuse_md)
 		data_check.skb_ports[0] = th->source;
 		data_check.skb_ports[1] = th->dest;
 
+		if (th->fin)
+			/* The connection is being torn down at the end of a
+			 * test. It can't contain a cmd, so return early.
+			 */
+			return SK_PASS;
+
 		if ((th->doff << 2) + sizeof(*cmd) > data_check.len)
 			GOTO_DONE(DROP_ERR_SKB_DATA);
 		if (bpf_skb_load_bytes(reuse_md, th->doff << 2, &cmd_copy,