lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzZrykLnBc_uqfjDbh_a=6VZnMKz5+UQWiORXkiJqNFoBg@mail.gmail.com>
Date:   Mon, 23 May 2022 20:45:13 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Stanislav Fomichev <sdf@...gle.com>
Cc:     Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Andrii Nakryiko <andrii@...nel.org>
Subject: Re: [PATCH bpf-next v7 07/11] libbpf: implement bpf_prog_query_opts

On Mon, May 23, 2022 at 7:15 PM Stanislav Fomichev <sdf@...gle.com> wrote:
>
> On Mon, May 23, 2022 at 4:22 PM Andrii Nakryiko
> <andrii.nakryiko@...il.com> wrote:
> >
> > On Wed, May 18, 2022 at 3:55 PM Stanislav Fomichev <sdf@...gle.com> wrote:
> > >
> > > Implement bpf_prog_query_opts as a more expendable version of
> > > bpf_prog_query. Expose new prog_attach_flags and attach_btf_func_id as
> > > well:
> > >
> > > * prog_attach_flags is a per-program attach_type; relevant only for
> > >   lsm cgroup program which might have different attach_flags
> > >   per attach_btf_id
> > > * attach_btf_func_id is a new field expose for prog_query which
> > >   specifies real btf function id for lsm cgroup attachments
> > >
> >
> > just thoughts aloud... Shouldn't bpf_prog_query() also return link_id
> > if the attachment was done with LINK_CREATE? And then attach flags
> > could actually be fetched through corresponding struct bpf_link_info.
> > That is, bpf_prog_query() returns a list of link_ids, and whatever
> > link-specific information can be fetched by querying individual links.
> > Seems more logical (and useful overall) to extend struct bpf_link_info
> > (you can get it more generically from bpftool, by querying fdinfo,
> > etc).
>
> Note that I haven't removed non-link-based APIs because they are easy
> to support. That might be an argument in favor of dropping them.
> Regarding the implementation: I'm not sure there is an easy way, in
> the kernel, to find all links associated with a given bpf_prog?

Nope, kernel doesn't keep track of this explicitly, in general. If you
were building a tool for something like that you'd probably use
bpf_link iterator program which we recently added. But in this case
kernel knows links that are attached to cgroups (they are in
prog_item->link if it's not NULL), so you shouldn't need any extra
information.

>
> > > Signed-off-by: Stanislav Fomichev <sdf@...gle.com>
> > > ---
> > >  tools/include/uapi/linux/bpf.h |  5 ++++
> > >  tools/lib/bpf/bpf.c            | 42 +++++++++++++++++++++++++++-------
> > >  tools/lib/bpf/bpf.h            | 15 ++++++++++++
> > >  tools/lib/bpf/libbpf.map       |  1 +
> > >  4 files changed, 55 insertions(+), 8 deletions(-)
> > >
> >
> > [...]
> >
> > >         ret = sys_bpf(BPF_PROG_QUERY, &attr, sizeof(attr));
> > >
> > > -       if (attach_flags)
> > > -               *attach_flags = attr.query.attach_flags;
> > > -       *prog_cnt = attr.query.prog_cnt;
> > > +       if (OPTS_HAS(opts, prog_cnt))
> > > +               opts->prog_cnt = attr.query.prog_cnt;
> >
> > just use OPTS_SET() instead of OPTS_HAS check
>
> Ah, definitely, for some reason I thought that these are "output"
> arguments and OPT_SET won't work for them.
>
> > > +       if (OPTS_HAS(opts, attach_flags))
> > > +               opts->attach_flags = attr.query.attach_flags;
> > >
> > >         return libbpf_err_errno(ret);
> > >  }
> > >
> >
> > [...]
> >
> > > diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
> > > index 6b36f46ab5d8..24f7a5147bf2 100644
> > > --- a/tools/lib/bpf/libbpf.map
> > > +++ b/tools/lib/bpf/libbpf.map
> > > @@ -452,6 +452,7 @@ LIBBPF_0.8.0 {
> > >                 bpf_map_delete_elem_flags;
> > >                 bpf_object__destroy_subskeleton;
> > >                 bpf_object__open_subskeleton;
> > > +               bpf_prog_query_opts;
> >
> > please put it into LIBBPF_1.0.0 section, 0.8 is closed now
>
> Definitely, will pull new changes and put them into proper place.
>
> Thank you for your review!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ