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] [day] [month] [year] [list]
Message-ID: <CAADnVQLOqSwm7Ve9g-XJ3HWY3=uBMy05wbDmRZdJvf0=gJkb2w@mail.gmail.com>
Date: Fri, 4 Oct 2024 16:53:56 -0700
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Namhyung Kim <namhyung@...nel.org>
Cc: Alexei Starovoitov <ast@...nel.org>, Daniel Borkmann <daniel@...earbox.net>, 
	Andrii Nakryiko <andrii@...nel.org>, Martin KaFai Lau <martin.lau@...ux.dev>, 
	Eduard Zingerman <eddyz87@...il.com>, Song Liu <song@...nel.org>, 
	Yonghong Song <yonghong.song@...ux.dev>, John Fastabend <john.fastabend@...il.com>, 
	KP Singh <kpsingh@...nel.org>, Stanislav Fomichev <sdf@...ichev.me>, Hao Luo <haoluo@...gle.com>, 
	Jiri Olsa <jolsa@...nel.org>, LKML <linux-kernel@...r.kernel.org>, 
	bpf <bpf@...r.kernel.org>, Andrew Morton <akpm@...ux-foundation.org>, 
	Christoph Lameter <cl@...ux.com>, Pekka Enberg <penberg@...nel.org>, David Rientjes <rientjes@...gle.com>, 
	Joonsoo Kim <iamjoonsoo.kim@....com>, Vlastimil Babka <vbabka@...e.cz>, 
	Roman Gushchin <roman.gushchin@...ux.dev>, Hyeonggon Yoo <42.hyeyoo@...il.com>, 
	linux-mm <linux-mm@...ck.org>, Arnaldo Carvalho de Melo <acme@...nel.org>
Subject: Re: [PATCH v3 bpf-next 3/3] selftests/bpf: Add a test for kmem_cache_iter

On Tue, Oct 1, 2024 at 11:55 PM Namhyung Kim <namhyung@...nel.org> wrote:
>
> +++ b/tools/testing/selftests/bpf/progs/kmem_cache_iter.c
> @@ -0,0 +1,66 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2024 Google */
> +
> +#include "bpf_iter.h"
> +#include <bpf/bpf_helpers.h>
> +#include <bpf/bpf_tracing.h>
> +
> +char _license[] SEC("license") = "GPL";
> +
> +#define SLAB_NAME_MAX  256
> +
> +struct {
> +       __uint(type, BPF_MAP_TYPE_HASH);
> +       __uint(key_size, sizeof(void *));
> +       __uint(value_size, SLAB_NAME_MAX);
> +       __uint(max_entries, 1024);
> +} slab_hash SEC(".maps");
> +
> +extern struct kmem_cache *bpf_get_kmem_cache(__u64 addr) __ksym;
> +
> +/* result, will be checked by userspace */
> +int found;
> +
> +SEC("iter/kmem_cache")
> +int slab_info_collector(struct bpf_iter__kmem_cache *ctx)
> +{
> +       struct seq_file *seq = ctx->meta->seq;
> +       struct kmem_cache *s = ctx->s;
> +
> +       if (s) {
> +               char name[SLAB_NAME_MAX];
> +
> +               /*
> +                * To make sure if the slab_iter implements the seq interface
> +                * properly and it's also useful for debugging.
> +                */
> +               BPF_SEQ_PRINTF(seq, "%s: %u\n", s->name, s->object_size);
> +
> +               bpf_probe_read_kernel_str(name, sizeof(name), s->name);
> +               bpf_map_update_elem(&slab_hash, &s, name, BPF_NOEXIST);
> +       }
> +
> +       return 0;
> +}
> +
> +SEC("raw_tp/bpf_test_finish")
> +int BPF_PROG(check_task_struct)
> +{
> +       __u64 curr = bpf_get_current_task();
> +       struct kmem_cache *s;
> +       char *name;
> +
> +       s = bpf_get_kmem_cache(curr);
> +       if (s == NULL) {
> +               found = -1;
> +               return 0;
> +       }
> +
> +       name = bpf_map_lookup_elem(&slab_hash, &s);
> +       if (name && !bpf_strncmp(name, 11, "task_struct"))
> +               found = 1;
> +       else
> +               found = -2;
> +
> +       return 0;
> +}

The test is a bit too simple.

Could you add a more comprehensive test that also demonstrates
the power of such a slab iterator?

Like progs/bpf_iter_task_vmas.c provides output equivalent to
cat proc/pid/maps

and progs/bpf_iter_tcp6.c dumps equivalent output to
cat /proc/net/tcp6

Would be great to have a selftest that is equivalent to
cat /proc/slabinfo
(or at least close enough)

That will give more confidence that the interface works as intended.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ