From: Jesper Dangaard Brouer <brouer@redhat.com>
To: Daniel Borkmann <daniel@iogearbox.net>
Cc: John Fastabend <john.fastabend@gmail.com>,
bpf@vger.kernel.org, netdev@vger.kernel.org,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
maze@google.com, lmb@cloudflare.com, shaun@tigera.io,
Lorenzo Bianconi <lorenzo@kernel.org>,
marek@cloudflare.com, Jakub Kicinski <kuba@kernel.org>,
eyal.birger@gmail.com, colrack@gmail.com, brouer@redhat.com
Subject: Re: [PATCH bpf-next V13 4/7] bpf: add BPF-helper for MTU checking
Date: Sat, 30 Jan 2021 14:51:19 +0100 [thread overview]
Message-ID: <20210130145119.17f876c3@carbon> (raw)
In-Reply-To: <4965401d-c461-15f6-2068-6cefb6c145ba@iogearbox.net>
On Sat, 30 Jan 2021 01:08:17 +0100
Daniel Borkmann <daniel@iogearbox.net> wrote:
> On 1/29/21 4:50 PM, John Fastabend wrote:
> > Jesper Dangaard Brouer wrote:
> >> On Thu, 28 Jan 2021 22:51:23 -0800
> >> John Fastabend <john.fastabend@gmail.com> wrote:
> >>> Jesper Dangaard Brouer wrote:
> >>>> This BPF-helper bpf_check_mtu() works for both XDP and TC-BPF programs.
> >>>>
> >>>> The SKB object is complex and the skb->len value (accessible from
> >>>> BPF-prog) also include the length of any extra GRO/GSO segments, but
> >>>> without taking into account that these GRO/GSO segments get added
> >>>> transport (L4) and network (L3) headers before being transmitted. Thus,
> >>>> this BPF-helper is created such that the BPF-programmer don't need to
> >>>> handle these details in the BPF-prog.
> >>>>
> >>>> The API is designed to help the BPF-programmer, that want to do packet
> >>>> context size changes, which involves other helpers. These other helpers
> >>>> usually does a delta size adjustment. This helper also support a delta
> >>>> size (len_diff), which allow BPF-programmer to reuse arguments needed by
> >>>> these other helpers, and perform the MTU check prior to doing any actual
> >>>> size adjustment of the packet context.
> >>>>
> >>>> It is on purpose, that we allow the len adjustment to become a negative
> >>>> result, that will pass the MTU check. This might seem weird, but it's not
> >>>> this helpers responsibility to "catch" wrong len_diff adjustments. Other
> >>>> helpers will take care of these checks, if BPF-programmer chooses to do
> >>>> actual size adjustment.
> >>
> >> The nitpick below about len adjust can become negative, is on purpose
> >> and why is described in above.
> >
> > following up on a nitpick :)
> >
> > What is the use case to allow users to push a negative len_diff with
> > abs(len_diff) > skb_diff and not throw an error. I would understand if it
> > was a pain to catch the case, but below is fairly straightforward. Of
> > course if user really tries to truncate the packet like this later it
> > will also throw an error, but still missing why we don't throw an error
> > here.
> >
> > Anyways its undefined if len_diff is truely bogus. Its not really a
> > problem I guess because garbage in (bogus len_diff) garbage out is OK I
> > think.
>
> What's the rationale to not sanity check for it? I just double checked
> the UAPI helper description comment ... at minimum this behavior would
> need to be documented there to avoid confusion.
The rationale is that the helper asks if the packet size adjustment
will exceed the MTU (on the given ifindex). It is not this helpers
responsibility to catch if the packet becomes too small. It the
responsibility of the helper function that does the size change. The
use-case for len_diff is testing prior to doing size adjustment.
The code can easily choose not to do the size adjustment. E.g. when
parsing the header, and realizing this is not a VXLAN (50 bytes) tunnel
packet, but instead a (small 42 bytes) ARP packet.
Sure, I can spin a V14 of the patchset, where I make it more clear for
the man page that this is the behavior.
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer
next prev parent reply other threads:[~2021-01-30 13:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-25 17:09 [PATCH bpf-next V13 0/7] bpf: New approach for BPF MTU handling Jesper Dangaard Brouer
2021-01-25 17:09 ` [PATCH bpf-next V13 1/7] bpf: Remove MTU check in __bpf_skb_max_len Jesper Dangaard Brouer
2021-01-25 17:09 ` [PATCH bpf-next V13 2/7] bpf: fix bpf_fib_lookup helper MTU check for SKB ctx Jesper Dangaard Brouer
2021-01-29 6:00 ` John Fastabend
2021-01-25 17:09 ` [PATCH bpf-next V13 3/7] bpf: bpf_fib_lookup return MTU value as output when looked up Jesper Dangaard Brouer
2021-01-29 6:06 ` John Fastabend
2021-01-25 17:09 ` [PATCH bpf-next V13 4/7] bpf: add BPF-helper for MTU checking Jesper Dangaard Brouer
2021-01-29 6:51 ` John Fastabend
2021-01-29 7:36 ` Jesper Dangaard Brouer
[not found] ` <60142eae7cd59_11fd208f1@john-XPS-13-9370.notmuch>
2021-01-30 0:08 ` Daniel Borkmann
2021-01-30 13:51 ` Jesper Dangaard Brouer [this message]
2021-01-25 17:09 ` [PATCH bpf-next V13 5/7] bpf: drop MTU check when doing TC-BPF redirect to ingress Jesper Dangaard Brouer
2021-01-29 6:54 ` John Fastabend
2021-01-25 17:09 ` [PATCH bpf-next V13 6/7] selftests/bpf: use bpf_check_mtu in selftest test_cls_redirect Jesper Dangaard Brouer
2021-01-29 6:55 ` John Fastabend
2021-01-25 17:09 ` [PATCH bpf-next V13 7/7] selftests/bpf: tests using bpf_check_mtu BPF-helper Jesper Dangaard Brouer
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=20210130145119.17f876c3@carbon \
--to=brouer@redhat.com \
--cc=alexei.starovoitov@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=colrack@gmail.com \
--cc=daniel@iogearbox.net \
--cc=eyal.birger@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=lmb@cloudflare.com \
--cc=lorenzo@kernel.org \
--cc=marek@cloudflare.com \
--cc=maze@google.com \
--cc=netdev@vger.kernel.org \
--cc=shaun@tigera.io \
/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;
as well as URLs for NNTP newsgroup(s).