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] [thread-next>] [day] [month] [year] [list]
Message-ID: <d6ff6022-56f7-de63-d3e1-8949360296ca@iogearbox.net>
Date:   Fri, 12 Jul 2019 15:57:02 +0200
From:   Daniel Borkmann <daniel@...earbox.net>
To:     Krzesimir Nowak <krzesimir@...volk.io>,
        Andrii Nakryiko <andrii.nakryiko@...il.com>
Cc:     Andrii Nakryiko <andriin@...com>, Kernel Team <kernel-team@...com>,
        Alexei Starovoitov <ast@...com>, bpf <bpf@...r.kernel.org>,
        Networking <netdev@...r.kernel.org>
Subject: Re: [PATCH bpf-next] selftests/bpf: remove logic duplication in
 test_verifier.c

On 07/12/2019 09:53 AM, Krzesimir Nowak wrote:
> On Thu, Jul 11, 2019 at 4:43 PM Andrii Nakryiko
> <andrii.nakryiko@...il.com> wrote:
>>
>> On Thu, Jul 11, 2019 at 5:13 AM Krzesimir Nowak <krzesimir@...volk.io> wrote:
>>>
>>> On Thu, Jul 11, 2019 at 3:08 AM Andrii Nakryiko <andriin@...com> wrote:
>>>>
>>>> test_verifier tests can specify single- and multi-runs tests. Internally
>>>> logic of handling them is duplicated. Get rid of it by making single run
>>>> retval specification to be a first retvals spec.
>>>>
>>>> Cc: Krzesimir Nowak <krzesimir@...volk.io>
>>>> Signed-off-by: Andrii Nakryiko <andriin@...com>
>>>
>>> Looks good, one nit below.
>>>
>>> Acked-by: Krzesimir Nowak <krzesimir@...volk.io>
>>>
>>>> ---
>>>>  tools/testing/selftests/bpf/test_verifier.c | 37 ++++++++++-----------
>>>>  1 file changed, 18 insertions(+), 19 deletions(-)
>>>>
>>>> diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
>>>> index b0773291012a..120ecdf4a7db 100644
>>>> --- a/tools/testing/selftests/bpf/test_verifier.c
>>>> +++ b/tools/testing/selftests/bpf/test_verifier.c
>>>> @@ -86,7 +86,7 @@ struct bpf_test {
>>>>         int fixup_sk_storage_map[MAX_FIXUPS];
>>>>         const char *errstr;
>>>>         const char *errstr_unpriv;
>>>> -       uint32_t retval, retval_unpriv, insn_processed;
>>>> +       uint32_t insn_processed;
>>>>         int prog_len;
>>>>         enum {
>>>>                 UNDEF,
>>>> @@ -95,16 +95,24 @@ struct bpf_test {
>>>>         } result, result_unpriv;
>>>>         enum bpf_prog_type prog_type;
>>>>         uint8_t flags;
>>>> -       __u8 data[TEST_DATA_LEN];
>>>>         void (*fill_helper)(struct bpf_test *self);
>>>>         uint8_t runs;
>>>> -       struct {
>>>> -               uint32_t retval, retval_unpriv;
>>>> -               union {
>>>> -                       __u8 data[TEST_DATA_LEN];
>>>> -                       __u64 data64[TEST_DATA_LEN / 8];
>>>> +       union {
>>>> +               struct {
>>>
>>> Maybe consider moving the struct definition outside to further the
>>> removal of the duplication?
>>
>> Can't do that because then retval/retval_unpriv/data won't be
>> accessible as a normal field of struct bpf_test. It has to be in
>> anonymous structs/unions, unfortunately.
>>
> 
> Ah, right.
> 
> Meh.
> 
> I tried something like this:
> 
> #define BPF_DATA_STRUCT \
>     struct { \
>         uint32_t retval, retval_unpriv; \
>         union { \
>             __u8 data[TEST_DATA_LEN]; \
>             __u64 data64[TEST_DATA_LEN / 8]; \
>         }; \
>     }
> 
> and then:
> 
>     union {
>         BPF_DATA_STRUCT;
>         BPF_DATA_STRUCT retvals[MAX_TEST_RUNS];
>     };
> 
> And that seems to compile at least. But question is: is this
> acceptably ugly or unacceptably ugly? :)

Both a bit ugly, but I'd have a slight preference towards the above,
perhaps a bit more readable like:

#define bpf_testdata_struct_t                                   \
        struct {                                                \
                uint32_t retval, retval_unpriv;                 \
                union {                                         \
                        __u8 data[TEST_DATA_LEN];               \
                        __u64 data64[TEST_DATA_LEN / 8];        \
                };                                              \
        }
        union {
                bpf_testdata_struct_t;
                bpf_testdata_struct_t retvals[MAX_TEST_RUNS];
        };

Thanks,
Daniel

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ