From: John Fastabend <john.fastabend@gmail.com>
To: Maxim Mikityanskiy <maximmi@nvidia.com>,
John Fastabend <john.fastabend@gmail.com>
Cc: bpf@vger.kernel.org, "Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
netdev@vger.kernel.org, "Tariq Toukan" <tariqt@nvidia.com>,
"Martin KaFai Lau" <kafai@fb.com>,
"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>,
"KP Singh" <kpsingh@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
"Jakub Kicinski" <kuba@kernel.org>,
"Petar Penkov" <ppenkov@google.com>,
"Lorenz Bauer" <lmb@cloudflare.com>,
"Eric Dumazet" <edumazet@google.com>,
"Hideaki YOSHIFUJI" <yoshfuji@linux-ipv6.org>,
"David Ahern" <dsahern@kernel.org>,
"Shuah Khan" <shuah@kernel.org>,
"Jesper Dangaard Brouer" <hawk@kernel.org>,
"Nathan Chancellor" <nathan@kernel.org>,
"Nick Desaulniers" <ndesaulniers@google.com>,
"Joe Stringer" <joe@cilium.io>,
"Florent Revest" <revest@chromium.org>,
linux-kselftest@vger.kernel.org,
"Toke Høiland-Jørgensen" <toke@toke.dk>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Florian Westphal" <fw@strlen.de>
Subject: Re: [PATCH bpf-next v2 2/3] bpf: Add helpers to issue and check SYN cookies in XDP
Date: Thu, 03 Feb 2022 18:29:55 -0800 [thread overview]
Message-ID: <61fc8fa39a5e6_1d27c20836@john.notmuch> (raw)
In-Reply-To: <8f5fecac-ce6e-adc8-305b-a2ee76328bce@nvidia.com>
Maxim Mikityanskiy wrote:
> On 2022-01-25 09:54, John Fastabend wrote:
> > Maxim Mikityanskiy wrote:
> >> The new helpers bpf_tcp_raw_{gen,check}_syncookie allow an XDP program
> >> to generate SYN cookies in response to TCP SYN packets and to check
> >> those cookies upon receiving the first ACK packet (the final packet of
> >> the TCP handshake).
> >>
> >> Unlike bpf_tcp_{gen,check}_syncookie these new helpers don't need a
> >> listening socket on the local machine, which allows to use them together
> >> with synproxy to accelerate SYN cookie generation.
> >>
> >> Signed-off-by: Maxim Mikityanskiy <maximmi@nvidia.com>
> >> Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
> >> ---
> >
> > [...]
> >
> >> +
> >> +BPF_CALL_4(bpf_tcp_raw_check_syncookie, void *, iph, u32, iph_len,
> >> + struct tcphdr *, th, u32, th_len)
> >> +{
[...]
>> >
> > Did you consider just exposing __cookie_v4_check() and __cookie_v6_check()?
>
> No, I didn't, I just implemented it consistently with
> bpf_tcp_check_syncookie, but let's consider it.
>
> I can't just pass a pointer from BPF without passing the size, so I
> would need some wrappers around __cookie_v{4,6}_check anyway. The checks
> for th_len and iph_len would have to stay in the helpers. The check for
> TCP flags (ACK, !RST, !SYN) could be either in the helper or in BPF. The
> switch would obviously be gone.
For consideration... those duplicate checks in the runtime that we
already could know from verifier side are bothering me.
We could have some new mem types, PTR_TO_IPV4, PTR_TO_IPv6, and PTR_TO_TCP.
Then we simplify the helper signatures to just,
bpf_tcp_raw_check_syncookie_v4(iph, tcph);
bpf_tcp_raw_check_syncookie_v6(iph, tcph);
And the verifier "knows" what a v4/v6 header is and does the mem
check at verification time instead of run time.
Then the code becomes very straightforward,
BPF_CALL_2(bpf_tcp_raw_check_syncookie_v4, void *, iph, void *, th)
{
u16 mss = tcp_parse_mss_option(th, 0) ?: TCP_MSS_DEFAULT;
return __cookie_v4_init_sequence(iph, th, &mss);
}
We don't need length checks because we are guaranteed by conmpiler
to have valid lengths, assume code is smart enough to understand
syn, ack, rst because any real program likely already knows this.
And v4/v6 is likely also known by real program already.
If we push a bit more on this mss with PTR_TO_TCP and PTR_TO_IP
we can simply mark tcp_parse_mss_option and __cookie_v4_init_sequence
and let BPF side call them.
Curious what others think here.
>
> The bottom line is that it would be the same code, but without the
> switch, and repeated twice. What benefit do you see in this approach?
> From my side, I only see the ability to drop one branch at the expense
> of duplicating the code above the switch (th_len and iph_len checks).
>
> > My code at least has already run the code above before it would ever call
> > this helper so all the other bits are duplicate.
>
> Sorry, I didn't quite understand this part. What "your code" are you
> referring to?
Just the XDP parsers we have already switch early on based on v4/v6
and I imagine that most progs also know this. So yes we are arguing
about a simple switch, but instruction here and instruction there
add up over time. Also passing the size through the helper bothers
me slightly given the verifier should know the size already.
next prev parent reply other threads:[~2022-02-04 2:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 15:13 [PATCH bpf-next v2 0/3] New BPF helpers to accelerate synproxy Maxim Mikityanskiy
2022-01-24 15:13 ` [PATCH bpf-next v2 1/3] bpf: Make errors of bpf_tcp_check_syncookie distinguishable Maxim Mikityanskiy
2022-01-25 7:38 ` John Fastabend
2022-01-31 13:38 ` Maxim Mikityanskiy
2022-01-24 15:13 ` [PATCH bpf-next v2 2/3] bpf: Add helpers to issue and check SYN cookies in XDP Maxim Mikityanskiy
2022-01-25 7:54 ` John Fastabend
2022-01-31 13:38 ` Maxim Mikityanskiy
2022-01-31 21:12 ` John Fastabend
2022-01-31 21:19 ` John Fastabend
2022-02-02 11:09 ` Maxim Mikityanskiy
2022-02-04 2:50 ` John Fastabend
2022-02-04 14:08 ` Toke Høiland-Jørgensen
2022-02-21 14:26 ` Maxim Mikityanskiy
2022-02-21 15:21 ` Kumar Kartikeya Dwivedi
2022-02-24 14:29 ` Maxim Mikityanskiy
2022-02-04 2:29 ` John Fastabend [this message]
2022-01-24 15:13 ` [PATCH bpf-next v2 3/3] bpf: Add selftests for raw syncookie helpers Maxim Mikityanskiy
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=61fc8fa39a5e6_1d27c20836@john.notmuch \
--to=john.fastabend@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=fw@strlen.de \
--cc=hawk@kernel.org \
--cc=joe@cilium.io \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=lmb@cloudflare.com \
--cc=maximmi@nvidia.com \
--cc=memxor@gmail.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=netdev@vger.kernel.org \
--cc=ppenkov@google.com \
--cc=revest@chromium.org \
--cc=shuah@kernel.org \
--cc=songliubraving@fb.com \
--cc=tariqt@nvidia.com \
--cc=toke@toke.dk \
--cc=yhs@fb.com \
--cc=yoshfuji@linux-ipv6.org \
/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