From: Florian Westphal <fw@strlen.de>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Florian Westphal <fw@strlen.de>,
bpf@vger.kernel.org, netdev@vger.kernel.org,
netfilter-devel@vger.kernel.org, dxu@dxuuu.xyz, qde@naccy.de
Subject: Re: [PATCH bpf-next v4 7/7] selftests/bpf: add missing netfilter return value and ctx access tests
Date: Fri, 21 Apr 2023 17:52:46 +0200 [thread overview]
Message-ID: <20230421155246.GD12121@breakpoint.cc> (raw)
In-Reply-To: <20230420201655.77kkgi3dh7fesoll@MacBook-Pro-6.local>
Alexei Starovoitov <alexei.starovoitov@gmail.com> wrote:
> On Thu, Apr 20, 2023 at 02:44:55PM +0200, Florian Westphal wrote:
> > +
> > +SEC("netfilter")
> > +__description("netfilter valid context access")
> > +__success __failure_unpriv
> > +__retval(1)
> > +__naked void with_invalid_ctx_access_test5(void)
> > +{
> > + asm volatile (" \
> > + r2 = *(u64*)(r1 + %[__bpf_nf_ctx_state]); \
> > + r1 = *(u64*)(r1 + %[__bpf_nf_ctx_skb]); \
> > + r0 = 1; \
> > + exit; \
> > +" :
> > + : __imm_const(__bpf_nf_ctx_state, offsetof(struct bpf_nf_ctx, state)),
> > + __imm_const(__bpf_nf_ctx_skb, offsetof(struct bpf_nf_ctx, skb))
> > + : __clobber_all);
>
> Could you write this one in C instead?
>
> Also check that skb and state are dereferenceable after that.
My bad. Added this and that:
SEC("netfilter")
__description("netfilter valid context read and invalid write")
__failure __msg("only read is supported")
int with_invalid_ctx_access_test5(struct bpf_nf_ctx *ctx)
{
struct nf_hook_state *state = (void *)ctx->state;
state->sk = NULL;
return 1;
}
SEC("netfilter")
__description("netfilter test prog with skb and state read access")
__success __failure_unpriv
__retval(0)
int with_valid_ctx_access_test6(struct bpf_nf_ctx *ctx)
{
const struct nf_hook_state *state = ctx->state;
struct sk_buff *skb = ctx->skb;
const struct iphdr *iph;
const struct tcphdr *th;
u8 buffer_iph[20] = {};
u8 buffer_th[40] = {};
struct bpf_dynptr ptr;
uint8_t ihl;
if (skb->len <= 20 || bpf_dynptr_from_skb(skb, 0, &ptr))
return 1;
iph = bpf_dynptr_slice(&ptr, 0, buffer_iph, sizeof(buffer_iph));
if (!iph)
return 1;
if (state->pf != 2)
return 1;
ihl = iph->ihl << 2;
th = bpf_dynptr_slice(&ptr, ihl, buffer_th, sizeof(buffer_th));
if (!th)
return 1;
return th->dest == bpf_htons(22) ? 1 : 0;
}
"Worksforme". Is there anything else thats missing?
If not I'll send v5 on Monday.
> Since they should be seen as trusted ptr_to_btf_id skb->len and state->sk should work.
> You cannot craft this test case in asm, since it needs CO-RE.
>
> Also see that BPF CI is not happy:
> https://github.com/kernel-patches/bpf/actions/runs/4757642030/jobs/8455500277
> Error: #112 libbpf_probe_prog_types
> Error: #112/32 libbpf_probe_prog_types/BPF_PROG_TYPE_NETFILTER
> Error: #113 libbpf_str
> Error: #113/4 libbpf_str/bpf_prog_type_str
prog_type_name[] lacks "netfilter" entry, and a missing 'case
PROG_NETFILTER', v5 should pass this now.
next prev parent reply other threads:[~2023-04-21 15:52 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-20 12:44 [PATCH bpf-next v4 0/7] bpf: add netfilter program type Florian Westphal
2023-04-20 12:44 ` [PATCH bpf-next v4 1/7] bpf: add bpf_link support for BPF_NETFILTER programs Florian Westphal
2023-04-20 12:44 ` [PATCH bpf-next v4 2/7] bpf: minimal support for programs hooked into netfilter framework Florian Westphal
2023-04-20 12:44 ` [PATCH bpf-next v4 3/7] netfilter: nfnetlink hook: dump bpf prog id Florian Westphal
2023-04-20 12:44 ` [PATCH bpf-next v4 4/7] netfilter: disallow bpf hook attachment at same priority Florian Westphal
2023-04-20 12:44 ` [PATCH bpf-next v4 5/7] tools: bpftool: print netfilter link info Florian Westphal
2023-04-20 12:44 ` [PATCH bpf-next v4 6/7] bpf: add test_run support for netfilter program type Florian Westphal
2023-04-20 12:44 ` [PATCH bpf-next v4 7/7] selftests/bpf: add missing netfilter return value and ctx access tests Florian Westphal
2023-04-20 20:16 ` Alexei Starovoitov
2023-04-21 15:52 ` Florian Westphal [this message]
2023-04-21 16:09 ` Alexei Starovoitov
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=20230421155246.GD12121@breakpoint.cc \
--to=fw@strlen.de \
--cc=alexei.starovoitov@gmail.com \
--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 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).