From: bot+bpf-ci@kernel.org
To: xukuohai@huaweicloud.com,bpf@vger.kernel.org,linux-kernel@vger.kernel.org
Cc: ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com,yonghong.song@linux.dev,jolsa@kernel.org,kpsingh@kernel.org,a.s.protopopov@gmail.com,ameryhung@gmail.com,eyal.birger@gmail.com,rongtao@cestc.cn,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,clm@meta.com,ihor.solodrai@linux.dev
Subject: Re: [RFC PATCH bpf-next 09/12] bpf: Add kernel support to load SDT observer program
Date: Sat, 27 Jun 2026 15:22:47 +0000 (UTC) [thread overview]
Message-ID: <659952bc287b99a3e86866cd561bbf69c8675704f5e3435e8308c6fac2df060b@mail.kernel.org> (raw)
In-Reply-To: <e5e991c7573600676c0de49b7b794e1f2b6d956a.1782571533.git.xukuohai@huawei.com>
[-- Attachment #1: Type: text/plain, Size: 4948 bytes --]
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index dc881e5ad411..8b2c73bb6c2a 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -2454,6 +2454,7 @@ static void __bpf_prog_put_noref(struct bpf_prog *prog, bool deferred)
> kvfree(prog->aux->linfo);
> kfree(prog->aux->kfunc_tab);
> kfree(prog->aux->ctx_arg_info);
> + kfree(prog->aux->sdt_probe);
> if (prog->aux->attach_btf)
> btf_put(prog->aux->attach_btf);
[ ... ]
> @@ -3082,33 +3085,75 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, struct bpf_log_at
> btf_get(attach_btf);
> }
>
> + /*
> + * find the probe site in the target program at load time of the
> + * observer program, so the verifier can check the observer's context
> + * arguments from the probe's FUNC_PROTO.
> + */
> + if (attr->expected_attach_type == BPF_TRACE_SDT) {
> + struct bpf_insn_array_value sdt_val;
> + struct bpf_sdt_probe_info *sdt_probe;
> + unsigned long probe_ip;
> +
> + if (!bpf_jit_supports_sdt_probe()) {
> + err = -EOPNOTSUPP;
> + goto put_token;
> + }
> + if (!attr->sdt.target_prog_fd) {
> + err = -EINVAL;
> + goto put_token;
> + }
> + dst_prog = bpf_prog_get(attr->sdt.target_prog_fd);
> + if (IS_ERR(dst_prog)) {
> + err = PTR_ERR(dst_prog);
> + dst_prog = NULL;
> + goto put_token;
> + }
> + err = bpf_insn_array_get_sdt_probe_by_name(dst_prog, attr->sdt.name,
> + &sdt_val, &probe_ip);
> + if (err)
> + goto put_sdt;
> + sdt_probe = kzalloc_obj(struct bpf_sdt_probe_info, GFP_USER);
> + if (!sdt_probe) {
> + err = -ENOMEM;
> + goto put_sdt;
> + }
> + sdt_probe->val = sdt_val;
> + sdt_probe->probe_ip = probe_ip;
> + prog_sdt_probe = sdt_probe;
> + attach_btf_id = sdt_val.btf_id;
> + }
> +
> +
> if (bpf_prog_load_check_attach(type, attr->expected_attach_type,
> - attach_btf, attr->attach_btf_id,
> + attach_btf,
> + prog_sdt_probe ? attach_btf_id : attr->attach_btf_id,
> dst_prog, multi_func)) {
> - if (dst_prog)
> - bpf_prog_put(dst_prog);
> - if (attach_btf)
> - btf_put(attach_btf);
> err = -EINVAL;
> - goto put_token;
> + goto put_sdt;
> }
>
> /* plain bpf_prog allocation */
> prog = bpf_prog_alloc(bpf_prog_size(attr->insn_cnt), GFP_USER);
> if (!prog) {
> - if (dst_prog)
> - bpf_prog_put(dst_prog);
> - if (attach_btf)
> - btf_put(attach_btf);
> err = -EINVAL;
> - goto put_token;
> + goto put_sdt;
> }
>
> prog->expected_attach_type = attr->expected_attach_type;
> prog->sleepable = !!(attr->prog_flags & BPF_F_SLEEPABLE);
> prog->aux->attach_btf = attach_btf;
> - prog->aux->attach_btf_id = multi_func ? bpf_multi_func_btf_id[0] : attr->attach_btf_id;
> + if (prog_sdt_probe)
> + prog->aux->attach_btf_id = attach_btf_id;
> + else
> + prog->aux->attach_btf_id =
> + multi_func ? bpf_multi_func_btf_id[0] : attr->attach_btf_id;
> prog->aux->dst_prog = dst_prog;
> + prog->aux->sdt_probe = prog_sdt_probe;
> + /* ownership of dst_prog/attach_btf/prog_sdt_probe moved to prog->aux */
> + dst_prog = NULL;
> + attach_btf = NULL;
> + prog_sdt_probe = NULL;
After this ownership transfer, prog_sdt_probe is NULL. Several error paths
below this point (copy_from_bpfptr failures, license checks, signature
verification, dev_bound initialization, find_prog_type, bpf_obj_name_cpy,
security_bpf_prog_load) all jump to the free_prog label.
Does the free_prog path correctly free prog->aux->sdt_probe?
Looking at the error paths:
kernel/bpf/syscall.c:bpf_prog_load() {
err = copy_from_bpfptr(...);
if (err)
goto free_prog;
...
err = bpf_prog_verify_signature(prog);
if (err < 0)
goto free_prog;
...
err = bpf_prog_dev_bound_init(prog, attr);
if (err)
goto free_prog;
...
}
> @@ -3242,6 +3287,12 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, struct bpf_log_at
> if (prog->aux->attach_btf)
> btf_put(prog->aux->attach_btf);
> bpf_prog_free(prog);
The free_prog label calls bpf_prog_free(), which in turn calls
bpf_prog_free_deferred(). That function frees used_maps, used_btfs,
kfunc tables, and the JIT image, but not aux->sdt_probe. The only place
that frees aux->sdt_probe is __bpf_prog_put_noref(), which is reached
through the normal bpf_prog_put() teardown (the free_used_maps label),
not through this error path.
> +put_sdt:
> + kfree(prog_sdt_probe);
This kfree handles the local prog_sdt_probe, which is NULL after the
ownership transfer above. It won't free the allocation now owned by
prog->aux->sdt_probe.
Can prog->aux->sdt_probe leak when a BPF_TRACE_SDT load succeeds past
the probe resolution but fails before bpf_check() completes?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/28292842584
next prev parent reply other threads:[~2026-06-27 15:22 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-27 22:51 [RFC PATCH bpf-next 00/12] bpf: Introduce static-defined tracing probe for BPF Xu Kuohai
2026-06-27 20:51 ` [syzbot ci] " syzbot ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 01/12] libbpf: Prepare bpf SDT probe section for the linker Xu Kuohai
2026-06-27 22:51 ` [RFC PATCH bpf-next 02/12] libbpf: Introduce bpf SDT probe macros Xu Kuohai
2026-06-27 22:51 ` [RFC PATCH bpf-next 03/12] libbpf: Add bpf_sdt_notes section parser Xu Kuohai
2026-06-27 22:51 ` [RFC PATCH bpf-next 04/12] bpf: Create insn_array map for bpf SDT probe Xu Kuohai
2026-06-27 15:34 ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 05/12] bpf: Collect SDT probe BTF IDs from BTF decl tags Xu Kuohai
2026-06-27 15:34 ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 06/12] bpf: Add type check for SDT probe site Xu Kuohai
2026-06-27 15:22 ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 07/12] bpf: Record probe name in SDT map Xu Kuohai
2026-06-27 22:51 ` [RFC PATCH bpf-next 08/12] libbpf: Add libbpf support to load SDT observer program Xu Kuohai
2026-06-27 22:51 ` [RFC PATCH bpf-next 09/12] bpf: Add kernel " Xu Kuohai
2026-06-27 15:22 ` bot+bpf-ci [this message]
2026-06-27 22:51 ` [RFC PATCH bpf-next 10/12] bpf: Support attach and detach for " Xu Kuohai
2026-06-27 22:51 ` [RFC PATCH bpf-next 11/12] bpf, x86: Add JIT support SDT for probe Xu Kuohai
2026-06-27 15:22 ` bot+bpf-ci
2026-06-27 22:51 ` [RFC PATCH bpf-next 12/12] selftests/bpf: Add tests for bpf SDT probe Xu Kuohai
2026-06-29 2:14 ` [RFC PATCH bpf-next 00/12] bpf: Introduce static-defined tracing probe for BPF Leon Hwang
2026-06-29 3:27 ` Xu Kuohai
2026-06-29 5:26 ` Leon Hwang
2026-06-29 7:51 ` Xu Kuohai
2026-06-29 10:55 ` Leon Hwang
2026-06-29 11:32 ` Xu Kuohai
2026-06-29 13:53 ` Leon Hwang
2026-06-30 1:19 ` Xu Kuohai
2026-06-30 2:14 ` Leon Hwang
2026-06-30 2:29 ` Xu Kuohai
2026-06-30 22:07 ` Alexei Starovoitov
2026-07-01 2:18 ` Xu Kuohai
2026-07-01 4:17 ` Anton Protopopov
2026-07-01 6:11 ` Xu Kuohai
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=659952bc287b99a3e86866cd561bbf69c8675704f5e3435e8308c6fac2df060b@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=a.s.protopopov@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=eyal.birger@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=memxor@gmail.com \
--cc=rongtao@cestc.cn \
--cc=xukuohai@huaweicloud.com \
--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®