summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/verifier/value_ptr_arith.c
diff options
context:
space:
mode:
authorYuntao Wang <ytcoode@gmail.com>2022-03-03 08:59:21 +0800
committerDaniel Borkmann <daniel@iogearbox.net>2022-03-03 16:23:22 +0100
commit41332d6e3a430adc91e0af115b4261b0d2f116ec (patch)
treeb90fb49b6b8b7bf751e72dc0114e7b010c6cb0f3 /tools/testing/selftests/bpf/verifier/value_ptr_arith.c
parent8bbe98bdccef0bb4fe88c666c28a3d4fe51151f7 (diff)
libbpf: Add a check to ensure that page_cnt is non-zero
The page_cnt parameter is used to specify the number of memory pages allocated for each per-CPU buffer, it must be non-zero and a power of 2. Currently, the __perf_buffer__new() function attempts to validate that the page_cnt is a power of 2 but forgets checking for the case where page_cnt is zero, we can fix it by replacing 'page_cnt & (page_cnt - 1)' with 'page_cnt == 0 || (page_cnt & (page_cnt - 1))'. If so, we also don't need to add a check in perf_buffer__new_v0_6_0() to make sure that page_cnt is non-zero and the check for zero in perf_buffer__new_raw_v0_6_0() can also be removed. The code will be cleaner and more readable. Signed-off-by: Yuntao Wang <ytcoode@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20220303005921.53436-1-ytcoode@gmail.com
Diffstat (limited to 'tools/testing/selftests/bpf/verifier/value_ptr_arith.c')
0 files changed, 0 insertions, 0 deletions