forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag 'bpf-fixes' of git://git.kernel.org/pub/scm/linux/kernel/gi…
…t/bpf/bpf Pull bpf fixes from Daniel Borkmann: - Fix BPF verifier to force a checkpoint when the program's jump history becomes too long (Eduard Zingerman) - Add several fixes to the BPF bits iterator addressing issues like memory leaks and overflow problems (Hou Tao) - Fix an out-of-bounds write in trie_get_next_key (Byeonguk Jeong) - Fix BPF test infra's LIVE_FRAME frame update after a page has been recycled (Toke Høiland-Jørgensen) - Fix BPF verifier and undo the 40-bytes extra stack space for bpf_fastcall patterns due to various bugs (Eduard Zingerman) - Fix a BPF sockmap race condition which could trigger a NULL pointer dereference in sock_map_link_update_prog (Cong Wang) - Fix tcp_bpf_recvmsg_parser to retrieve seq_copied from tcp_sk under the socket lock (Jiayuan Chen) * tag 'bpf-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf: bpf, test_run: Fix LIVE_FRAME frame update after a page has been recycled selftests/bpf: Add three test cases for bits_iter bpf: Use __u64 to save the bits in bits iterator bpf: Check the validity of nr_words in bpf_iter_bits_new() bpf: Add bpf_mem_alloc_check_size() helper bpf: Free dynamically allocated bits in bpf_iter_bits_destroy() bpf: disallow 40-bytes extra stack for bpf_fastcall patterns selftests/bpf: Add test for trie_get_next_key() bpf: Fix out-of-bounds write in trie_get_next_key() selftests/bpf: Test with a very short loop bpf: Force checkpoint when jmp history is too long bpf: fix filed access without lock sock_map: fix a NULL pointer dereference in sock_map_link_update_prog()
- Loading branch information
Showing
13 changed files
with
269 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
tools/testing/selftests/bpf/map_tests/lpm_trie_map_get_next_key.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
|
||
#define _GNU_SOURCE | ||
#include <linux/bpf.h> | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
#include <unistd.h> | ||
#include <errno.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <pthread.h> | ||
|
||
#include <bpf/bpf.h> | ||
#include <bpf/libbpf.h> | ||
|
||
#include <test_maps.h> | ||
|
||
struct test_lpm_key { | ||
__u32 prefix; | ||
__u32 data; | ||
}; | ||
|
||
struct get_next_key_ctx { | ||
struct test_lpm_key key; | ||
bool start; | ||
bool stop; | ||
int map_fd; | ||
int loop; | ||
}; | ||
|
||
static void *get_next_key_fn(void *arg) | ||
{ | ||
struct get_next_key_ctx *ctx = arg; | ||
struct test_lpm_key next_key; | ||
int i = 0; | ||
|
||
while (!ctx->start) | ||
usleep(1); | ||
|
||
while (!ctx->stop && i++ < ctx->loop) | ||
bpf_map_get_next_key(ctx->map_fd, &ctx->key, &next_key); | ||
|
||
return NULL; | ||
} | ||
|
||
static void abort_get_next_key(struct get_next_key_ctx *ctx, pthread_t *tids, | ||
unsigned int nr) | ||
{ | ||
unsigned int i; | ||
|
||
ctx->stop = true; | ||
ctx->start = true; | ||
for (i = 0; i < nr; i++) | ||
pthread_join(tids[i], NULL); | ||
} | ||
|
||
/* This test aims to prevent regression of future. As long as the kernel does | ||
* not panic, it is considered as success. | ||
*/ | ||
void test_lpm_trie_map_get_next_key(void) | ||
{ | ||
#define MAX_NR_THREADS 8 | ||
LIBBPF_OPTS(bpf_map_create_opts, create_opts, | ||
.map_flags = BPF_F_NO_PREALLOC); | ||
struct test_lpm_key key = {}; | ||
__u32 val = 0; | ||
int map_fd; | ||
const __u32 max_prefixlen = 8 * (sizeof(key) - sizeof(key.prefix)); | ||
const __u32 max_entries = max_prefixlen + 1; | ||
unsigned int i, nr = MAX_NR_THREADS, loop = 65536; | ||
pthread_t tids[MAX_NR_THREADS]; | ||
struct get_next_key_ctx ctx; | ||
int err; | ||
|
||
map_fd = bpf_map_create(BPF_MAP_TYPE_LPM_TRIE, "lpm_trie_map", | ||
sizeof(struct test_lpm_key), sizeof(__u32), | ||
max_entries, &create_opts); | ||
CHECK(map_fd == -1, "bpf_map_create()", "error:%s\n", | ||
strerror(errno)); | ||
|
||
for (i = 0; i <= max_prefixlen; i++) { | ||
key.prefix = i; | ||
err = bpf_map_update_elem(map_fd, &key, &val, BPF_ANY); | ||
CHECK(err, "bpf_map_update_elem()", "error:%s\n", | ||
strerror(errno)); | ||
} | ||
|
||
ctx.start = false; | ||
ctx.stop = false; | ||
ctx.map_fd = map_fd; | ||
ctx.loop = loop; | ||
memcpy(&ctx.key, &key, sizeof(key)); | ||
|
||
for (i = 0; i < nr; i++) { | ||
err = pthread_create(&tids[i], NULL, get_next_key_fn, &ctx); | ||
if (err) { | ||
abort_get_next_key(&ctx, tids, i); | ||
CHECK(err, "pthread_create", "error %d\n", err); | ||
} | ||
} | ||
|
||
ctx.start = true; | ||
for (i = 0; i < nr; i++) | ||
pthread_join(tids[i], NULL); | ||
|
||
printf("%s:PASS\n", __func__); | ||
|
||
close(map_fd); | ||
} |
Oops, something went wrong.