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] [day] [month] [year] [list]
Date:   Thu, 22 Jul 2021 17:06:24 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Alan Maguire <alan.maguire@...cle.com>
Cc:     Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Andrii Nakryiko <andrii@...nel.org>, Martin Lau <kafai@...com>,
        Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
        john fastabend <john.fastabend@...il.com>,
        KP Singh <kpsingh@...nel.org>,
        Bill Wendling <morbo@...gle.com>, bpf <bpf@...r.kernel.org>,
        Networking <netdev@...r.kernel.org>
Subject: Re: [PATCH bpf-next] selftests/bpf: add multidimensional array
 BTF-based data dump test

On Thu, Jul 22, 2021 at 3:06 PM Alan Maguire <alan.maguire@...cle.com> wrote:
>
> There are currently no multidimensional array tests for
> BTF-based data dumping.  In BTF, a multidimensional array is
> represented as an array with an element type of array.  However,
> pahole and llvm collapse multidimensional arrays into a
> one-dimensional array [1].  Accordingly, the test uses the BTF
> add interfaces to create a multidimensional char [2][4] array,
> and tests type-based display matches expectations.
>
> [1] See Documentation/bpf/btf.rst Section 2.2.3
>
> Suggested-by: Andrii Nakryiko <andrii@...nel.org>
> Signed-off-by: Alan Maguire <alan.maguire@...cle.com>
> ---
>  tools/testing/selftests/bpf/prog_tests/btf_dump.c | 39 +++++++++++++++++++++++
>  1 file changed, 39 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c b/tools/testing/selftests/bpf/prog_tests/btf_dump.c
> index 52ccf0c..70d26cf 100644
> --- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c
> +++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c
> @@ -681,6 +681,45 @@ static void test_btf_dump_struct_data(struct btf *btf, struct btf_dump *d,
>  "}",
>                            { .cb = { 0, 0, 1, 0, 0},});
>
> +       /* multidimensional array; because pahole and llvm collapse arrays

Are you sure about llvm collapsing multi-dimensional arrays?... There
is entire progs/btf_dump_test_case_multidim.c testing
multi-dimensional array ;)

> +        * with multiple dimensions into a single dimension, we add a
> +        * multidimensional array explicitly.
> +        */
> +       type_id = btf__find_by_name(btf, "char");
> +       if (ASSERT_GT(type_id, 0, "find char")) {
> +               __s32 index_id, array1_id, array2_id;
> +               char strs[2][4] = { "one", "two" };

oh, it's a way too happy case :) can you try { "a", "", "abc", "ab" } as well?

> +
> +               index_id = btf__find_by_name(btf, "int");
> +               ASSERT_GT(index_id, 0, "find int");
> +
> +               array2_id = btf__add_array(btf, index_id, type_id, 4);
> +               ASSERT_GT(array2_id, 0, "add multidim 2");
> +
> +               array1_id = btf__add_array(btf, index_id, array2_id, 2);
> +               ASSERT_GT(array1_id, 0, "add multidim 1");
> +
> +               str[0] = '\0';
> +               ret = btf_dump__dump_type_data(d, array1_id, &strs, sizeof(strs), &opts);
> +               ASSERT_GT(ret, 0, "dump multidimensional array");
> +
> +               ASSERT_STREQ(str,
> +"(char[2][4])[\n"
> +"      [\n"
> +"              'o',\n"
> +"              'n',\n"
> +"              'e',\n"
> +"      ],\n"
> +"      [\n"
> +"              't',\n"
> +"              'w',\n"
> +"              'o',\n"
> +"      ],\n"
> +"]",

maybe use compact output for such tests, it won't lose much in terms
of readability and will be way more compact


> +                            "multidimensional char array matches");
> +       }
> +
> +
>         /* struct with bitfields */
>         TEST_BTF_DUMP_DATA_C(btf, d, "struct", str, struct bpf_insn, BTF_F_COMPACT,
>                 {.code = (__u8)1,.dst_reg = (__u8)0x2,.src_reg = (__u8)0x3,.off = (__s16)4,.imm = (__s32)5,});
> --
> 1.8.3.1
>

Powered by blists - more mailing lists