[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <b277d408a2a94c37fb452fef7192ce1c1fcc0ef5288e9a26e3c7373db18c1f7a@mail.kernel.org>
Date: Sat, 22 Nov 2025 00:58:07 +0000 (UTC)
From: bot+bpf-ci@...nel.org
To: ameryhung@...il.com,bpf@...r.kernel.org
Cc: netdev@...r.kernel.org,alexei.starovoitov@...il.com,andrii@...nel.org,daniel@...earbox.net,tj@...nel.org,martin.lau@...nel.org,ameryhung@...il.com,kernel-team@...a.com,ast@...nel.org,andrii@...nel.org,daniel@...earbox.net,martin.lau@...nel.org,eddyz87@...il.com,yonghong.song@...ux.dev,clm@...a.com,ihor.solodrai@...ux.dev
Subject: Re: [PATCH bpf-next v7 3/6] libbpf: Add support for associating BPF program with struct_ops
> diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
> index b66f5fbfb..21b57a629 100644
> --- a/tools/lib/bpf/bpf.c
> +++ b/tools/lib/bpf/bpf.c
[ ... ]
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 706e7481b..1d5424276 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -14137,6 +14137,37 @@ int bpf_program__set_attach_target(struct bpf_program *prog,
> return 0;
> }
>
> +int bpf_program__assoc_struct_ops(struct bpf_program *prog, struct bpf_map *map,
> + struct bpf_prog_assoc_struct_ops_opts *opts)
> +{
> + int prog_fd, map_fd;
> +
> + prog_fd = bpf_program__fd(prog);
> + if (prog_fd < 0) {
> + pr_warn("prog '%s': can't associate BPF program without FD (was it loaded?)\n",
> + prog->name);
Can prog->name be accessed here when prog is NULL? The function
bpf_program__fd() returns libbpf_err(-EINVAL) when prog is NULL,
which makes prog_fd < 0 true, then prog->name is dereferenced.
Similarly for the map parameter below:
> + return -EINVAL;
> + }
> +
> + if (prog->type == BPF_PROG_TYPE_STRUCT_OPS) {
> + pr_warn("prog '%s': can't associate struct_ops program\n", prog->name);
> + return -EINVAL;
> + }
> +
> + map_fd = bpf_map__fd(map);
> + if (map_fd < 0) {
> + pr_warn("map '%s': can't associate BPF map without FD (was it created?)\n", map->name);
The function bpf_map__fd() returns libbpf_err(-EINVAL) when map is
NULL, making this condition true, then map->name is dereferenced.
The function bpf_program__set_attach_target() above checks for NULL
explicitly before accessing the prog pointer. Should this function
follow the same pattern?
> + return -EINVAL;
> + }
> +
> + if (!bpf_map__is_struct_ops(map)) {
> + pr_warn("map '%s': can't associate non-struct_ops map\n", map->name);
> + return -EINVAL;
> + }
> +
> + return bpf_prog_assoc_struct_ops(prog_fd, map_fd, opts);
> +}
[ ... ]
---
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/19586343154
Powered by blists - more mailing lists