aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/testing/selftests/bpf/test_cgroup_storage.c
diff options
context:
space:
mode:
authorArtem Savkov <asavkov@redhat.com>2022-04-06 10:54:08 +0200
committerAndrii Nakryiko <andrii@kernel.org>2022-04-06 10:15:53 -0700
commitebaf24c589d7c714b763a80856d1a6df3ba25b84 (patch)
tree1158cf2b5a2c53d107fc12fc444c7b9d16f2486f /tools/testing/selftests/bpf/test_cgroup_storage.c
parentlibbpf: Fix spelling mistake "libaries" -> "libraries" (diff)
downloadwireguard-linux-ebaf24c589d7c714b763a80856d1a6df3ba25b84.tar.xz
wireguard-linux-ebaf24c589d7c714b763a80856d1a6df3ba25b84.zip
selftests/bpf: Use bpf_num_possible_cpus() in per-cpu map allocations
bpf_map_value_size() uses num_possible_cpus() to determine map size, but some of the tests only allocate enough memory for online cpus. This results in out-of-bound writes in userspace during bpf(BPF_MAP_LOOKUP_ELEM) syscalls in cases when number of online cpus is lower than the number of possible cpus. Fix by switching from get_nprocs_conf() to bpf_num_possible_cpus() when determining the number of processors in these tests (test_progs/netcnt and test_cgroup_storage). Signed-off-by: Artem Savkov <asavkov@redhat.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20220406085408.339336-1-asavkov@redhat.com
Diffstat (limited to 'tools/testing/selftests/bpf/test_cgroup_storage.c')
-rw-r--r--tools/testing/selftests/bpf/test_cgroup_storage.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/tools/testing/selftests/bpf/test_cgroup_storage.c b/tools/testing/selftests/bpf/test_cgroup_storage.c
index d6a1be4d8020..2ffa08198d1c 100644
--- a/tools/testing/selftests/bpf/test_cgroup_storage.c
+++ b/tools/testing/selftests/bpf/test_cgroup_storage.c
@@ -7,6 +7,7 @@
#include <sys/sysinfo.h>
#include "bpf_rlimit.h"
+#include "bpf_util.h"
#include "cgroup_helpers.h"
#include "testing_helpers.h"
@@ -44,7 +45,7 @@ int main(int argc, char **argv)
unsigned long long *percpu_value;
int cpu, nproc;
- nproc = get_nprocs_conf();
+ nproc = bpf_num_possible_cpus();
percpu_value = malloc(sizeof(*percpu_value) * nproc);
if (!percpu_value) {
printf("Not enough memory for per-cpu area (%d cpus)\n", nproc);