Skip to content

Commit 89087c4

Browse files
committed
bpf: Fix values type used in test_maps
Maps of per-cpu type have their value element size adjusted to 8 if it is specified smaller during various map operations. This makes test_maps as a 32-bit binary fail, in fact the kernel writes past the end of the value's array on the user's stack. To be quite honest, I think the kernel should reject creation of a per-cpu map that doesn't have a value size of at least 8 if that's what the kernel is going to silently adjust to later. If the user passed something smaller, it is a sizeof() calcualtion based upon the type they will actually use (just like in this testcase code) in later calls to the map operations. Fixes: df570f5 ("samples/bpf: unit test for BPF_MAP_TYPE_PERCPU_ARRAY") Signed-off-by: David S. Miller <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Acked-by: Alexei Starovoitov <[email protected]>
1 parent 557c44b commit 89087c4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/testing/selftests/bpf/test_maps.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static void test_arraymap_percpu(int task, void *data)
282282
{
283283
unsigned int nr_cpus = bpf_num_possible_cpus();
284284
int key, next_key, fd, i;
285-
long values[nr_cpus];
285+
long long values[nr_cpus];
286286

287287
fd = bpf_create_map(BPF_MAP_TYPE_PERCPU_ARRAY, sizeof(key),
288288
sizeof(values[0]), 2, 0);
@@ -340,7 +340,7 @@ static void test_arraymap_percpu_many_keys(void)
340340
* allocator more than anything else
341341
*/
342342
unsigned int nr_keys = 2000;
343-
long values[nr_cpus];
343+
long long values[nr_cpus];
344344
int key, fd, i;
345345

346346
fd = bpf_create_map(BPF_MAP_TYPE_PERCPU_ARRAY, sizeof(key),

0 commit comments

Comments
 (0)