From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Lorenz Bauer <lmb@cloudflare.com>
Cc: Petar Penkov <ppenkov.kernel@gmail.com>,
Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
davem@davemloft.net, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eric Dumazet <edumazet@google.com>,
Stanislav Fomichev <sdf@google.com>,
Petar Penkov <ppenkov@google.com>,
yhs@fb.com
Subject: Re: [bpf-next 6/6] selftests/bpf: add test for bpf_tcp_gen_syncookie
Date: Tue, 23 Jul 2019 13:46:16 -0700 [thread overview]
Message-ID: <20190723204615.a6tia3f6fipdoht2@ast-mbp> (raw)
In-Reply-To: <CACAyw9-qQ8KbQk6Q6dg0+A337ZbSpot-sHpH_tSxFaQmUfhLyQ@mail.gmail.com>
On Tue, Jul 23, 2019 at 10:37:29AM +0100, Lorenz Bauer wrote:
> On Tue, 23 Jul 2019 at 01:20, Petar Penkov <ppenkov.kernel@gmail.com> wrote:
> > +static __always_inline __s64 gen_syncookie(void *data_end, struct bpf_sock *sk,
> > + void *iph, __u32 ip_size,
> > + struct tcphdr *tcph)
> > +{
> > + __u32 thlen = tcph->doff * 4;
> > +
> > + if (tcph->syn && !tcph->ack) {
> > + // packet should only have an MSS option
> > + if (thlen != 24)
> > + return 0;
>
> Just for my own understanding: without this the verifier complains since
> thlen is not a known value, even though it is in bounds due to the check below?
the verifier understands only constant part of the packet pointer.
Without additional 'if' above the statement:
if ((void *)tcph + thlen > data_end)
will add variables length 'thlen' to pkt pointer which will become
another pkt pointer (with different id).
That pointer would need 'pkt + const_range > data_end' to have valid access.
We hit this issue in the past when folks wanted to use bpf_csum_diff() helper
with variable size.
It's possible to extend the verifier to support that but it's intrusive,
since variable part would need to passed around to a bunch of check* functions.
I think it's tricky, but doable. Looking forward to patches :)
> > +
> > + if ((void *)tcph + thlen > data_end)
> > + return 0;
> > +
> > + return bpf_tcp_gen_syncookie(sk, iph, ip_size, tcph, thlen);
> > + }
> > + return 0;
> > +}
> > +
>
> --
> Lorenz Bauer | Systems Engineer
> 6th Floor, County Hall/The Riverside Building, SE1 7PB, UK
>
> www.cloudflare.com
next prev parent reply other threads:[~2019-07-23 20:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-23 0:20 [bpf-next 0/6] Introduce a BPF helper to generate SYN cookies Petar Penkov
2019-07-23 0:20 ` [bpf-next 1/6] tcp: tcp_syn_flood_action read port from socket Petar Penkov
2019-07-23 0:20 ` [bpf-next 2/6] tcp: add skb-less helpers to retrieve SYN cookie Petar Penkov
2019-07-24 6:05 ` kbuild test robot
2019-07-24 6:19 ` kbuild test robot
2019-07-23 0:20 ` [bpf-next 3/6] bpf: add bpf_tcp_gen_syncookie helper Petar Penkov
2019-07-23 12:33 ` Toke Høiland-Jørgensen
2019-07-24 0:15 ` Petar Penkov
2019-07-23 0:20 ` [bpf-next 4/6] bpf: sync bpf.h to tools/ Petar Penkov
2019-07-23 0:20 ` [bpf-next 5/6] selftests/bpf: bpf_tcp_gen_syncookie->bpf_helpers Petar Penkov
2019-07-23 0:20 ` [bpf-next 6/6] selftests/bpf: add test for bpf_tcp_gen_syncookie Petar Penkov
2019-07-23 9:37 ` Lorenz Bauer
2019-07-23 20:46 ` Alexei Starovoitov [this message]
2019-07-23 6:30 ` [bpf-next 0/6] Introduce a BPF helper to generate SYN cookies Eric Dumazet
2019-07-23 10:27 ` Lorenz Bauer
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=20190723204615.a6tia3f6fipdoht2@ast-mbp \
--to=alexei.starovoitov@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=lmb@cloudflare.com \
--cc=netdev@vger.kernel.org \
--cc=ppenkov.kernel@gmail.com \
--cc=ppenkov@google.com \
--cc=sdf@google.com \
--cc=yhs@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