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: <56c22b26-6c76-44fa-a8be-e71a515a4e7a@gmail.com>
Date: Tue, 10 Sep 2024 10:40:57 +0800
From: Tao Chen <chen.dylane@...il.com>
To: Andrii Nakryiko <andrii.nakryiko@...il.com>
Cc: Alexei Starovoitov <ast@...nel.org>,
 Daniel Borkmann <daniel@...earbox.net>, Andrii Nakryiko <andrii@...nel.org>,
 Eduard Zingerman <eddyz87@...il.com>, Song Liu <song@...nel.org>,
 Hou Tao <houtao1@...wei.com>, Yonghong Song <yonghong.song@...ux.dev>,
 John Fastabend <john.fastabend@...il.com>, KP Singh <kpsingh@...nel.org>,
 Stanislav Fomichev <sdf@...ichev.me>, bpf@...r.kernel.org,
 linux-kernel@...r.kernel.org, jinke han <jinkehan@...iglobal.com>
Subject: Re: [v2 PATCH bpf-next 2/2] bpf/selftests: Check errno when percpu
 map value size exceeds

在 2024/9/10 04:16, Andrii Nakryiko 写道:
> On Mon, Sep 9, 2024 at 12:14 AM Tao Chen <chen.dylane@...il.com> wrote:
>>
>> This test case checks the errno message when percpu map value size
>> exceeds PCPU_MIN_UNIT_SIZE.
>>
>> root@...ian:~# ./test_progs -t map_init
>>   #160/1   map_init/pcpu_map_init:OK
>>   #160/2   map_init/pcpu_lru_map_init:OK
>>   #160/3   map_init/pcpu map value size:OK
>>   #160     map_init:OK
>> Summary: 1/3 PASSED, 0 SKIPPED, 0 FAILED
>>
>> Signed-off-by: Tao Chen <chen.dylane@...il.com>
>> Signed-off-by: jinke han <jinkehan@...iglobal.com>
>> ---
>>   .../selftests/bpf/prog_tests/map_init.c       | 32 +++++++++++++++++++
>>   .../selftests/bpf/progs/test_map_init.c       |  6 ++++
>>   2 files changed, 38 insertions(+)
>>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/map_init.c b/tools/testing/selftests/bpf/prog_tests/map_init.c
>> index 14a31109dd0e..7f1a6fa3679f 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/map_init.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/map_init.c
>> @@ -6,6 +6,7 @@
>>
>>   #define TEST_VALUE 0x1234
>>   #define FILL_VALUE 0xdeadbeef
>> +#define PCPU_MIN_UNIT_SIZE 32768
>>
>>   static int nr_cpus;
>>   static int duration;
>> @@ -118,6 +119,35 @@ static int check_values_one_cpu(pcpu_map_value_t *value, map_value_t expected)
>>
>>          return 0;
>>   }
>> +/*
>> + * percpu map value size is bound by PCPU_MIN_UNIT_SIZE
>> + * check the errno when the value exceed PCPU_MIN_UNIT_SIZE
>> + */
>> +static void test_pcpu_map_value_size(void)
>> +{
>> +       struct test_map_init *skel;
>> +       int err;
>> +       int value_sz = PCPU_MIN_UNIT_SIZE + 1;
>> +       enum bpf_map_type map_types[] = { BPF_MAP_TYPE_PERCPU_ARRAY,
>> +                                         BPF_MAP_TYPE_PERCPU_HASH,
>> +                                         BPF_MAP_TYPE_LRU_PERCPU_HASH };
>> +       for (int i = 0; i < ARRAY_SIZE(map_types); i++) {
>> +               skel = test_map_init__open();
>> +               if (!ASSERT_OK_PTR(skel, "skel_open"))
>> +                       return;
>> +               err = bpf_map__set_type(skel->maps.hashmap2, map_types[i]);
>> +               if (!ASSERT_OK(err, "bpf_map__set_type"))
>> +                       goto error;
>> +               err = bpf_map__set_value_size(skel->maps.hashmap2, value_sz);
>> +               if (!ASSERT_OK(err, "bpf_map__set_value_size"))
>> +                       goto error;
>> +
>> +               err = test_map_init__load(skel);
>> +               ASSERT_EQ(err, -E2BIG, "skel_load");
> 
> This is quite an overkill to test map creation. It will be much more
> straightforward to just use low-level bpf_map_create() API, can you
> please make use of that instead?
> 
> pw-bot: cr
> 

Ok, i will use the bpf_map_create API in v3.

>> +error:
>> +               test_map_init__destroy(skel);
>> +       }
>> +}
>>
>>   /* Add key=1 elem with values set for all CPUs
>>    * Delete elem key=1
>> @@ -211,4 +241,6 @@ void test_map_init(void)
>>                  test_pcpu_map_init();
>>          if (test__start_subtest("pcpu_lru_map_init"))
>>                  test_pcpu_lru_map_init();
>> +       if (test__start_subtest("pcpu map value size"))
>> +               test_pcpu_map_value_size();
>>   }
>> diff --git a/tools/testing/selftests/bpf/progs/test_map_init.c b/tools/testing/selftests/bpf/progs/test_map_init.c
>> index c89d28ead673..7a772cbf0570 100644
>> --- a/tools/testing/selftests/bpf/progs/test_map_init.c
>> +++ b/tools/testing/selftests/bpf/progs/test_map_init.c
>> @@ -15,6 +15,12 @@ struct {
>>          __type(value, __u64);
>>   } hashmap1 SEC(".maps");
>>
>> +struct {
>> +       __uint(type, BPF_MAP_TYPE_HASH);
>> +       __uint(max_entries, 1);
>> +       __type(key, __u32);
>> +       __type(value, __u64);
>> +} hashmap2 SEC(".maps");
>>
>>   SEC("tp/syscalls/sys_enter_getpgid")
>>   int sysenter_getpgid(const void *ctx)
>> --
>> 2.25.1
>>


-- 
Best Regards
Dylane Chen

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ