From: Kuan-Wei Chiu <visitorckw@gmail.com>
To: bot+bpf-ci@kernel.org
Cc: corbet@lwn.net, geert@linux-m68k.org, ast@kernel.org,
daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com,
memxor@gmail.com, gerg@linux-m68k.org, skhan@linuxfoundation.org,
rdunlap@infradead.org, martin.lau@linux.dev, song@kernel.org,
yonghong.song@linux.dev, jolsa@kernel.org, emil@etsalapatis.com,
ihor.solodrai@linux.dev, marscheng@google.com,
eleanor15x@gmail.com, jserv@ccns.ncku.edu.tw,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-m68k@lists.linux-m68k.org, bpf@vger.kernel.org,
daniel@thingy.jp, martin.lau@kernel.org, mason@kernel.org
Subject: Re: [PATCH v10] m68k, bpf: Add initial BPF JIT compiler support
Date: Tue, 17 Nov 2026 19:15:16 +0800 [thread overview]
Message-ID: <avw3REBe9uzZG2HQ@google.com> (raw)
In-Reply-To: <146c493fb3b8d5f5171ad146cdc23e4f2693e1e142ad11ca67db5eae60cd4abb@mail.kernel.org>
On Tue, Nov 17, 2026 at 10:36:39AM +0000, bot+bpf-ci@kernel.org wrote:
> > m68k, bpf: Add initial BPF JIT compiler support
>
> TL;DR: bpf_int_jit_compile() has no check for an already-JITed prog, so
> jit_subprogs()'s second pass may leak the first executable image, e.g. with an
> exception_callback tag, letting a CAP_BPF user exhaust JIT memory.
>
> > diff --git a/arch/m68k/net/bpf_jit_comp.c b/arch/m68k/net/bpf_jit_comp.c
> > --- /dev/null
> > +++ b/arch/m68k/net/bpf_jit_comp.c
>
> [ ... ]
>
> > +struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)
> > +{
> > + struct bpf_binary_header *header;
> > + struct jit_ctx ctx;
> > + unsigned int image_size;
> > + u8 *image_ptr;
> > +
> > + if (!prog->jit_requested)
> > + return prog;
> > +
>
> [ ... ]
>
> > + header = bpf_jit_binary_alloc(image_size, &image_ptr, 2, jit_fill_hole);
> > + if (!header)
> > + goto out_off;
>
> [ ... ]
>
> > + prog->bpf_func = (void *)ctx.target;
> > + prog->jited = 1;
> > + prog->jited_len = image_size;
> > + goto out_off;
>
> If jit_subprogs() calls bpf_int_jit_compile() a second time on a func[i]
> that is already JITed, doesn't this allocate a new header and overwrite
> prog->bpf_func, leaving the first image unfreed?
>
> jit_subprogs() in kernel/bpf/fixups.c calls bpf_int_jit_compile() twice
> for every subprog, once in the first loop and again in the extra pass:
>
> old_bpf_func = func[i]->bpf_func;
> tmp = bpf_int_jit_compile(env, func[i]);
> if (tmp != func[i] || func[i]->bpf_func != old_bpf_func) {
> verbose(env, "JIT doesn't support bpf-to-bpf calls\n");
> err = -ENOTSUPP;
> goto out_free;
> }
>
> On the second call only prog->jit_requested is checked, which is still
> set, so both passes run again. bpf_jit_binary_alloc() returns a new
> header and prog->bpf_func is overwritten. The out_free path then calls
> bpf_jit_free(func[i]), which frees only the header that
> bpf_jit_binary_hdr(func[i]) finds, i.e. the new one. The first image
> and its bpf_jit_charge_modmem() charge are never released.
>
> Rejecting BPF_PSEUDO_CALL in emit_call() and BPF_PSEUDO_FUNC in
> build_insn() doesn't cover every path to the extra pass. A program whose
> main function has an "exception_callback:" BTF decl tag gets a second
> subprog via bpf_find_exception_callback_insn_off() -> add_subprog() in
> kernel/bpf/verifier.c. The main program doesn't need to call that
> subprog or use bpf_throw(). Both functions JIT successfully in the first
> loop since they contain no calls, and the extra pass then leaks func[0]'s
> first image on every load. A CAP_BPF user (needed for BTF) loading such
> programs repeatedly could leak executable memory without bound and keep
> growing bpf_jit_current.
>
> The JITs that support bpf-to-bpf calls (x86, arm64, riscv, powerpc,
> loongarch, parisc, arc) detect the extra pass via prog->jited or jit_data
> and reuse the image. Would an early return when prog->jited is already
> set work here? jit_subprogs() would then see the same bpf_func and
> finish, and that seems safe because any real call or callback has already
> made the first pass fail.
Since this initial JIT doesn't support subprogs anyway, I'll just
reject prog->is_func upfront in bpf_int_jit_compile() in v11.
Regards,
Kuan-Wei
prev parent reply other threads:[~2026-11-17 11:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 9:51 Kuan-Wei Chiu
2026-11-17 10:36 ` bot+bpf-ci
2026-11-17 11:15 ` Kuan-Wei Chiu [this message]
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=avw3REBe9uzZG2HQ@google.com \
--to=visitorckw@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=daniel@iogearbox.net \
--cc=daniel@thingy.jp \
--cc=eddyz87@gmail.com \
--cc=eleanor15x@gmail.com \
--cc=emil@etsalapatis.com \
--cc=geert@linux-m68k.org \
--cc=gerg@linux-m68k.org \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=jserv@ccns.ncku.edu.tw \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=marscheng@google.com \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mason@kernel.org \
--cc=memxor@gmail.com \
--cc=rdunlap@infradead.org \
--cc=skhan@linuxfoundation.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/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
all inboxes | Powered by JetHome®