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  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]
Date:   Thu, 21 May 2020 12:11:03 -0700
From:   John Fastabend <john.fastabend@...il.com>
To:     Andrii Nakryiko <andrii.nakryiko@...il.com>,
        John Fastabend <john.fastabend@...il.com>
Cc:     Yonghong Song <yhs@...com>, Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Lorenz Bauer <lmb@...udflare.com>, bpf <bpf@...r.kernel.org>,
        Jakub Sitnicki <jakub@...udflare.com>,
        Networking <netdev@...r.kernel.org>
Subject: Re: [bpf-next PATCH v3 5/5] bpf: selftests, test probe_* helpers from
 SCHED_CLS

Andrii Nakryiko wrote:
> On Thu, May 21, 2020 at 7:36 AM John Fastabend <john.fastabend@...il.com> wrote:
> >
> > Lets test using probe* in SCHED_CLS network programs as well just
> > to be sure these keep working. Its cheap to add the extra test
> > and provides a second context to test outside of sk_msg after
> > we generalized probe* helpers to all networking types.
> >
> > Signed-off-by: John Fastabend <john.fastabend@...il.com>
> > ---

[...]

> > +++ b/tools/testing/selftests/bpf/progs/test_skb_helpers.c
> > @@ -0,0 +1,33 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +#include "vmlinux.h"
> > +#include <bpf/bpf_helpers.h>
> > +#include <bpf/bpf_endian.h>
> > +
> > +int _version SEC("version") = 1;
> 
> version is not needed
> 
> > +
> > +#define TEST_COMM_LEN 10
> 
> doesn't matter for this test, but it's 16 everywhere, let's stay consistent
> 
> > +
> > +struct bpf_map_def SEC("maps") cgroup_map = {
> > +       .type                   = BPF_MAP_TYPE_CGROUP_ARRAY,
> > +       .key_size               = sizeof(u32),
> > +       .value_size             = sizeof(u32),
> > +       .max_entries    = 1,
> > +};
> > +
> 
> Please use new BTF syntax for maps
> 
> > +char _license[] SEC("license") = "GPL";
> > +
> > +SEC("classifier/test_skb_helpers")
> > +int test_skb_helpers(struct __sk_buff *skb)
> > +{
> > +       struct task_struct *task;
> > +       char *comm[TEST_COMM_LEN];
> 
> this is array of pointer, not array of chars
> 
> > +       __u32 tpid;
> > +       int ctask;
> > +
> > +       ctask = bpf_current_task_under_cgroup(&cgroup_map, 0);
> 
> compiler might complain that ctask is written, but not read. Let's
> assign it to some global variable?

I'll do a read here and check the value then it should be fine.

Will fold in the above comments as well.

> > +       task = (struct task_struct *)bpf_get_current_task();
> > +
> > +       bpf_probe_read_kernel(&tpid , sizeof(tpid), &task->tgid);
> > +       bpf_probe_read_kernel_str(&comm, sizeof(comm), &task->comm);
> > +       return 0;
> > +}
> >

Powered by blists - more mailing lists