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:   Thu, 3 Jan 2019 12:52:28 -0800
From:   Stanislav Fomichev <sdf@...gle.com>
To:     Jakub Kicinski <jakub.kicinski@...ronome.com>
Cc:     netdev@...r.kernel.org, davem@...emloft.net,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Quentin Monnet <quentin.monnet@...ronome.com>
Subject: Re: [PATCH bpf 1/2] bpftool: support queues and stacks in update command

On Thu, Jan 3, 2019 at 11:43 AM Jakub Kicinski
<jakub.kicinski@...ronome.com> wrote:
>
> On Thu,  3 Jan 2019 10:33:05 -0800, Stanislav Fomichev wrote:
> > Bpftool expects both key and value for 'update' operations. For some
> > map types, key should not be specified. Support updating those map types.
> >
> > Before:
> > bpftool map create /sys/fs/bpf/q type queue value 4 entries 10 name q
> > bpftool map update pinned /sys/fs/bpf/q value 0 1 2 3
> > Error: did not find key
> >
> > After:
> > bpftool map create /sys/fs/bpf/q type queue value 4 entries 10 name q
> > bpftool map update pinned /sys/fs/bpf/q value 0 1 2 3
> >
> > Signed-off-by: Stanislav Fomichev <sdf@...gle.com>
>
> I guess it doesn't hurt to fix update/lookup, but I'd prefer to see new
> separate subcommands to be honest :(
>
> bpftool map push/pop/peek
>
> Could you add those as well?  I think most users will be more familiar
> with the helpers than the fact that the syscall reuses the old commands.
Sure, I thought about that, but decided to mirror syscall interface initially.
I can do both: support update/lookup and add new commands.

>
> > diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> > index 2037e3dc864b..30b92715248d 100644
> > --- a/tools/bpf/bpftool/map.c
> > +++ b/tools/bpf/bpftool/map.c
> > @@ -781,11 +781,11 @@ static int do_dump(int argc, char **argv)
> >
> >  static int do_update(int argc, char **argv)
> >  {
> > +     void *key = NULL, *value = NULL;
>
> nit: it seems tiny bit more readable to init these in the place you'd
>      otherwise set key to malloc (in an else clause)
Ack, will do.

>
> >       struct bpf_map_info info = {};
> >       __u32 len = sizeof(info);
> >       __u32 *value_fd = NULL;
> >       __u32 flags = BPF_ANY;
> > -     void *key, *value;
> >       int fd, err;
> >
> >       if (argc < 2)
> > @@ -795,9 +795,16 @@ static int do_update(int argc, char **argv)
> >       if (fd < 0)
> >               return -1;
> >
> > -     key = malloc(info.key_size);
> > +     if (info.key_size) {
> > +             key = malloc(info.key_size);
> > +             if (!key) {
> > +                     p_err("mem alloc failed");
> > +                     err = -1;
> > +                     goto exit_free;
> > +             }
> > +     }
> >       value = alloc_value(&info);
>
> Would you mind taking care of the value as well?  So we are ready if
> sets are ever added?
Sure, makes sense.

>
> > -     if (!key || !value) {
> > +     if (!value) {
> >               p_err("mem alloc failed");
> >               err = -1;
> >               goto exit_free;
>
> I'd consider this -next material TBH, but not strongly.
My initial thought that these two can go into bpf as 'fixes' because
they technically don't add any new features.
But I'm fine with -next as well, I'll prepare a v2 for bpf-next with
those two changes plus push/pop/peek.

Thank you for a review!

Powered by blists - more mailing lists