From: Leon Hwang <leon.hwang@linux.dev>
To: Junseo Lim <zirajs7@gmail.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>
Cc: John Fastabend <john.fastabend@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
bpf@vger.kernel.org, Sechang Lim <rhkrqnwk98@gmail.com>,
"Paul E. McKenney" <paulmck@kernel.org>
Subject: Re: [PATCH bpf] bpf: fix UAF of trampoline progs before image release
Date: Mon, 17 Aug 2026 12:54:23 +0800 [thread overview]
Message-ID: <d5dc645b-3efe-4875-93ec-4c89ee323de8@linux.dev> (raw)
In-Reply-To: <20260815071927.147049-1-zirajs7@gmail.com>
On 15/8/26 15:19, Junseo Lim wrote:
[...]
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index 7719f6528445..bacb6bc2e27b 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -1376,6 +1376,11 @@ struct bpf_tramp_image {
> struct rcu_head rcu;
> struct work_struct work;
> };
> +#ifdef CONFIG_PREEMPTION
> + /* Programs called from this image must outlive deferred image freeing. */
> + struct bpf_prog *progs[BPF_MAX_TRAMP_LINKS];
> + int nr_progs;
> +#endif
> };
>
> struct bpf_trampoline {
> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
> index 1a721fc4bef5..ff6b331c965b 100644
> --- a/kernel/bpf/trampoline.c
> +++ b/kernel/bpf/trampoline.c
> @@ -531,6 +531,13 @@ bpf_trampoline_get_progs(const struct bpf_trampoline *tr, int *total, bool *ip_a
>
> static void bpf_tramp_image_free(struct bpf_tramp_image *im)
> {
> +#ifdef CONFIG_PREEMPTION
> + int i;
> +
> + for (i = 0; i < im->nr_progs; i++)
> + bpf_prog_put(im->progs[i]);
> +#endif
Looks better to factor out a helper for it, e.g.
bpf_tramp_image_put_progs().
> +
> bpf_image_ksym_del(&im->ksym);
> arch_free_bpf_trampoline(im->image, im->size);
> bpf_jit_uncharge_modmem(im->size);
> @@ -678,6 +685,9 @@ static int bpf_trampoline_update(struct bpf_trampoline *tr, bool lock_direct_mut
> u32 orig_flags = tr->flags;
> bool ip_arg = false;
> int err, total, size;
> +#ifdef CONFIG_PREEMPTION
> + int i, kind;
> +#endif
>
> tnodes = bpf_trampoline_get_progs(tr, &total, &ip_arg);
> if (IS_ERR(tnodes))
> @@ -740,6 +750,16 @@ static int bpf_trampoline_update(struct bpf_trampoline *tr, bool lock_direct_mut
> goto out;
> }
>
> +#ifdef CONFIG_PREEMPTION
> + for (kind = 0; kind < BPF_TRAMP_MAX; kind++)
> + for (i = 0; i < tnodes[kind].nr_nodes; i++) {
> + struct bpf_prog *prog = tnodes[kind].nodes[i]->link->prog;
> +
> + bpf_prog_inc(prog);
> + im->progs[im->nr_progs++] = prog;
> + }
> +#endif
Ditto.
Thanks,
Leon
> +
> err = arch_prepare_bpf_trampoline(im, im->image, im->image + size,
> &tr->func.model, tr->flags, tnodes,
> tr->func.addr);
prev parent reply other threads:[~2026-08-17 4:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-15 7:19 [PATCH bpf] bpf: fix UAF of trampoline progs before image release Junseo Lim
2026-08-15 8:03 ` bot+bpf-ci
2026-08-17 4:54 ` Leon Hwang [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=d5dc645b-3efe-4875-93ec-4c89ee323de8@linux.dev \
--to=leon.hwang@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=paulmck@kernel.org \
--cc=rhkrqnwk98@gmail.com \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
--cc=zirajs7@gmail.com \
/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