From: John Fastabend <john.fastabend@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
John Fastabend <john.fastabend@gmail.com>
Cc: maciej.fijalkowski@intel.com, ast@kernel.org,
daniel@iogearbox.net, andriin@fb.com, netdev@vger.kernel.org
Subject: Re: [PATCH bpf v2 3/4] bpf: track subprog poke correctly
Date: Tue, 22 Jun 2021 16:02:02 -0700 [thread overview]
Message-ID: <60d26bea8722e_1342e20834@john-XPS-13-9370.notmuch> (raw)
In-Reply-To: <20210622220037.6uwrba6tl7vofcu5@ast-mbp.dhcp.thefacebook.com>
Alexei Starovoitov wrote:
> On Wed, Jun 16, 2021 at 03:55:39PM -0700, John Fastabend wrote:
> >
> > -static void bpf_free_used_maps(struct bpf_prog_aux *aux)
> > +void bpf_free_used_maps(struct bpf_prog_aux *aux)
> > {
> > __bpf_free_used_maps(aux, aux->used_maps, aux->used_map_cnt);
> > kfree(aux->used_maps);
> > @@ -2211,8 +2211,10 @@ static void bpf_prog_free_deferred(struct work_struct *work)
> > #endif
> > if (aux->dst_trampoline)
> > bpf_trampoline_put(aux->dst_trampoline);
> > - for (i = 0; i < aux->func_cnt; i++)
> > + for (i = 0; i < aux->func_cnt; i++) {
> > + bpf_free_used_maps(aux->func[i]->aux);
> > bpf_jit_free(aux->func[i]);
> > + }
>
> The sub-progs don't have all the properties of the main prog.
> Only main prog suppose to keep maps incremented.
> After this patch the prog with 100 subprogs will artificially bump maps
> refcnt 100 times as a workaround for poke_tab access.
Yep.
> May be we can use single poke_tab in the main prog instead.
> Looks like jit_subprogs is splitting the poke_tab into individual arrays
> for each subprog, but maps are tracked by the main prog only.
> That's the root cause of the issue, right?
Correct.
> I think that split of poke_tab isn't necessary.
> bpf_int_jit_compile() can look into main prog poke_tab instead.
> Then the loop:
> for (j = 0; j < prog->aux->size_poke_tab)
> bpf_jit_add_poke_descriptor(func[i], &prog->aux->poke_tab[j]);
> can be removed (It will address the concern in patch 2 as well, right?)
> And hopefully will fix UAF too?
Looks like it to me as well. A few details to work out around
imm value and emit hooks on the jit side, but looks doable to me.
I'll give it a try tomorrow or tonight.
Thanks,
John
next prev parent reply other threads:[~2021-06-22 23:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-16 22:54 [PATCH bpf v2 0/4] BPF fixes mixed tail and bpf2bpf calls John Fastabend
2021-06-16 22:55 ` [PATCH bpf v2 1/4] bpf: Fix null ptr deref with mixed tail calls and subprogs John Fastabend
2021-06-16 22:55 ` [PATCH bpf v2 2/4] bpf: map_poke_descriptor is being called with an unstable poke_tab[] John Fastabend
2021-06-16 23:42 ` John Fastabend
2021-06-22 21:54 ` Alexei Starovoitov
2021-06-22 22:59 ` John Fastabend
2021-06-16 22:55 ` [PATCH bpf v2 3/4] bpf: track subprog poke correctly John Fastabend
2021-06-22 22:00 ` Alexei Starovoitov
2021-06-22 23:02 ` John Fastabend [this message]
2021-06-22 23:07 ` Alexei Starovoitov
2021-06-16 22:55 ` [PATCH bpf v2 4/4] bpf: selftest to verify mixing bpf2bpf calls and tailcalls with insn patch John Fastabend
2021-06-17 4:30 ` [PATCH bpf v2 0/4] BPF fixes mixed tail and bpf2bpf calls Andrii Nakryiko
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=60d26bea8722e_1342e20834@john-XPS-13-9370.notmuch \
--to=john.fastabend@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=maciej.fijalkowski@intel.com \
--cc=netdev@vger.kernel.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