From: Florian Westphal <fw@strlen.de>
To: Quentin Deslandes <qde@naccy.de>
Cc: Florian Westphal <fw@strlen.de>,
netdev@vger.kernel.org, netfilter-devel@vger.kernel.org,
bpf@vger.kernel.org, dxu@dxuuu.xyz
Subject: Re: [PATCH bpf-next 0/6] bpf: add netfilter program type
Date: Wed, 12 Apr 2023 11:45:54 +0200 [thread overview]
Message-ID: <20230412094554.GD6670@breakpoint.cc> (raw)
In-Reply-To: <7d97222a-36c1-ee77-4ad6-d8d2c6056d4c@naccy.de>
Quentin Deslandes <qde@naccy.de> wrote:
> On 05/04/2023 18:11, Florian Westphal wrote:
> > Add minimal support to hook bpf programs to netfilter hooks, e.g.
> > PREROUTING or FORWARD.
> >
> > For this the most relevant parts for registering a netfilter
> > hook via the in-kernel api are exposed to userspace via bpf_link.
> >
> > The new program type is 'tracing style', i.e. there is no context
> > access rewrite done by verifier, the function argument (struct bpf_nf_ctx)
> > isn't stable.
> > There is no support for direct packet access, dynptr api should be used
> > instead.
>
> Does this mean the verifier will reject any program accessing ctx->skb
> (e.g. ctx->skb + X)?
Do you mean access to ctx->skb->data + X? If so, yes, that won't work.
Otherwise, then no, it just means that programs might have to be recompiled
if they lack needed relocation information, but only if bpf_nf_ctx structure is
changed.
Initial version used "__sk_buff *skb", like e.g. clsact. I was told
to not do that and expose the real kernel-side structure instead and to
not bother with direct packet access (skb->data access) support.
> > #include "vmlinux.h"
> > extern int bpf_dynptr_from_skb(struct __sk_buff *skb, __u64 flags,
> > struct bpf_dynptr *ptr__uninit) __ksym;
> > extern void *bpf_dynptr_slice(const struct bpf_dynptr *ptr, uint32_t offset,
> > void *buffer, uint32_t buffer__sz) __ksym;
> > SEC("netfilter")
> > int nf_test(struct bpf_nf_ctx *ctx)
> > {
> > struct nf_hook_state *state = ctx->state;
> > struct sk_buff *skb = ctx->skb;
ctx->skb is dereferenced...
> > if (bpf_dynptr_from_skb(skb, 0, &ptr))
> > return NF_DROP;
... dynptr is created ...
> > iph = bpf_dynptr_slice(&ptr, 0, &_iph, sizeof(_iph));
> > if (!iph)
> > return NF_DROP;
> > th = bpf_dynptr_slice(&ptr, iph->ihl << 2, &_th, sizeof(_th));
ip header access.
next prev parent reply other threads:[~2023-04-12 9:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-05 16:11 [PATCH bpf-next 0/6] bpf: add netfilter program type Florian Westphal
2023-04-05 16:11 ` [PATCH bpf-next 1/6] bpf: add bpf_link support for BPF_NETFILTER programs Florian Westphal
2023-04-06 4:50 ` kernel test robot
2023-04-05 16:11 ` [PATCH bpf-next 2/6] bpf: minimal support for programs hooked into netfilter framework Florian Westphal
2023-04-05 16:11 ` [PATCH bpf-next 3/6] netfilter: nfnetlink hook: dump bpf prog id Florian Westphal
2023-04-05 16:11 ` [PATCH bpf-next 4/6] netfilter: disallow bpf hook attachment at same priority Florian Westphal
2023-04-05 16:11 ` [PATCH bpf-next 5/6] tools: bpftool: print netfilter link info Florian Westphal
2023-04-05 16:11 ` [PATCH bpf-next 6/6] bpf: add test_run support for netfilter program type Florian Westphal
2023-04-05 18:22 ` kernel test robot
2023-04-07 1:36 ` Alexei Starovoitov
2023-04-08 21:38 ` Florian Westphal
2023-04-12 8:20 ` [PATCH bpf-next 0/6] bpf: add " Quentin Deslandes
2023-04-12 9:45 ` Florian Westphal [this message]
2023-04-13 9:26 ` Quentin Deslandes
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=20230412094554.GD6670@breakpoint.cc \
--to=fw@strlen.de \
--cc=bpf@vger.kernel.org \
--cc=dxu@dxuuu.xyz \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=qde@naccy.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.