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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Tue, 8 Oct 2019 08:26:41 -0700
From:   Stanislav Fomichev <sdf@...ichev.me>
To:     Andrii Nakryiko <andrii.nakryiko@...il.com>
Cc:     Andrii Nakryiko <andriin@...com>, bpf <bpf@...r.kernel.org>,
        Networking <netdev@...r.kernel.org>,
        Alexei Starovoitov <ast@...com>,
        Daniel Borkmann <daniel@...earbox.net>,
        Stanislav Fomichev <sdf@...gle.com>,
        Kernel Team <kernel-team@...com>
Subject: Re: [PATCH bpf-next] bpftool: fix bpftool build by switching to
 bpf_object__open_file()

On 10/07, Andrii Nakryiko wrote:
> -- Andrii
> 
> On Mon, Oct 7, 2019 at 2:50 PM Andrii Nakryiko
> <andrii.nakryiko@...il.com> wrote:
> >
> > On Mon, Oct 7, 2019 at 2:46 PM Stanislav Fomichev <sdf@...ichev.me> wrote:
> > >
> > > On 10/07, Andrii Nakryiko wrote:
> > > > As part of libbpf in 5e61f2707029 ("libbpf: stop enforcing kern_version,
> > > > populate it for users") non-LIBBPF_API __bpf_object__open_xattr() API
> > > > was removed from libbpf.h header. This broke bpftool, which relied on
> > > > that function. This patch fixes the build by switching to newly added
> > > > bpf_object__open_file() which provides the same capabilities, but is
> > > > official and future-proof API.
> > > >
> > > > Fixes: 5e61f2707029 ("libbpf: stop enforcing kern_version, populate it for users")
> > > > Reported-by: Stanislav Fomichev <sdf@...gle.com>
> > > > Signed-off-by: Andrii Nakryiko <andriin@...com>
> > > > ---
> > > >  tools/bpf/bpftool/main.c |  4 ++--
> > > >  tools/bpf/bpftool/main.h |  2 +-
> > > >  tools/bpf/bpftool/prog.c | 22 ++++++++++++----------
> > > >  3 files changed, 15 insertions(+), 13 deletions(-)
> > > >
> 
> [...]
> 
> > > > --- a/tools/bpf/bpftool/prog.c
> > > > +++ b/tools/bpf/bpftool/prog.c
> > > > @@ -1092,9 +1092,7 @@ static int do_run(int argc, char **argv)
> > > >  static int load_with_options(int argc, char **argv, bool first_prog_only)
> > > >  {
> > > >       struct bpf_object_load_attr load_attr = { 0 };
> > > > -     struct bpf_object_open_attr open_attr = {
> > > > -             .prog_type = BPF_PROG_TYPE_UNSPEC,
> > > > -     };
> > > > +     enum bpf_prog_type prog_type = BPF_PROG_TYPE_UNSPEC;
> > > >       enum bpf_attach_type expected_attach_type;
> > > >       struct map_replace *map_replace = NULL;
> 
> [...]
> 
> > > >
> > > >       bpf_object__for_each_program(pos, obj) {
> > > > -             enum bpf_prog_type prog_type = open_attr.prog_type;
> > > > +             enum bpf_prog_type prog_type = prog_type;
> > > Are you sure it works that way?
> >
> > Oh, I did this pretty mechanically, didn't notice I'm shadowing. In
> > either case I'd like to avoid shadowing, so I'll rename one of them,
> > good catch!
> >
> > >
> > > $ cat tmp.c
> > > #include <stdio.h>
> > >
> > > int main()
> > > {
> > >         int x = 1;
> > >         printf("outer x=%d\n", x);
> > >
> > >         {
> > >                 int x = x;
> 
> It's amazing `int x = x;` is compiled successfully when there is no x
> in outer scope. And it's also amazing that it's doing the wrong thing
> when there is a shadowed variable in outer scope. I can't imagine the
> case where this will be a meaningful behavior...
Enjoy your daily dose of undefined behavior :-D

> > >                 printf("inner x=%d\n", x);
> > >         }
> > >
> > >         return 0;
> > > }
> > >
> > > $ gcc tmp.c && ./a.out
> > > outer x=1
> > > inner x=0
> > >
> > > Other than that:
> > > Reviewed-by: Stanislav Fomichev <sdf@...gle.com>
> > >
> > > >
> > > > -             if (open_attr.prog_type == BPF_PROG_TYPE_UNSPEC) {
> > > > +             if (prog_type == BPF_PROG_TYPE_UNSPEC) {
> > > >                       const char *sec_name = bpf_program__title(pos, false);
> > > >
> > > >                       err = libbpf_prog_type_by_name(sec_name, &prog_type,
> > > > --
> > > > 2.17.1
> > > >

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ