[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4Bza6gVd84ANwTyKZq8jnSBvALTppZUaZC802SKr5pO5QbQ@mail.gmail.com>
Date: Tue, 4 Nov 2025 15:27:46 -0800
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: bot+bpf-ci@...nel.org
Cc: ameryhung@...il.com, bpf@...r.kernel.org, netdev@...r.kernel.org,
alexei.starovoitov@...il.com, andrii@...nel.org, daniel@...earbox.net,
tj@...nel.org, martin.lau@...nel.org, kernel-team@...a.com, ast@...nel.org,
eddyz87@...il.com, yonghong.song@...ux.dev, clm@...a.com,
ihor.solodrai@...ux.dev
Subject: Re: [PATCH bpf-next v5 4/7] libbpf: Add support for associating BPF
program with struct_ops
On Tue, Nov 4, 2025 at 9:54 AM <bot+bpf-ci@...nel.org> wrote:
>
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index fbe74686c..260e1feaa 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
>
> [ ... ]
>
> > @@ -13891,6 +13891,36 @@ 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;
> > +
> > + 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 be NULL here? If bpf_program__fd() returns -EINVAL because prog
libbpf APIs generally do not tolerate passing NULL for bpf_program or
bpf_map pointers. This is fine, this shouldn't happen with valid usage
of an API (and we don't guard against this).
> was NULL, this dereferences prog->name without a NULL check. Looking at
> bpf_program__set_attach_target() just above, it checks "if (!prog)"
> before any dereferences.
>
> > + return -EINVAL;
> > + }
> > +
> > + if (prog->type == BPF_PROG_TYPE_STRUCT_OPS) {
> ^^^^^^^^^^
>
> Same issue - prog->type is dereferenced without verifying prog is not
> NULL.
>
> > + pr_warn("prog '%s': can't associate struct_ops program\n", prog->name);
> > + return -EINVAL;
> > + }
> > +
> > + if (map->fd < 0) {
> ^^^^^^
>
> Can map be NULL? There's no NULL check before dereferencing map->fd.
> Other map APIs like bpf_map__fd() and bpf_map__name() check for NULL
> before use.
>
> > + pr_warn("map '%s': can't associate BPF map without FD (was it created?)\n", map->name);
> > + 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/19077679684
Powered by blists - more mailing lists