-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently key_size of hashtab is limited to MAX_BPF_STACK. As the key of hashtab can also be a value from a per cpu map it can be larger than MAX_BPF_STACK. The use-case for this patch originates to implement allow/disallow lists for files and file paths. The maximum length of file paths is defined by PATH_MAX with 4096 chars including nul. This limit exceeds MAX_BPF_STACK. Changelog: v5: - Fix cast overflow v4: - Utilize BPF skeleton in tests - Rebase v3: - Rebase v2: - Add a test for bpf side Signed-off-by: Florian Lehner <dev@der-flo.net> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: John Fastabend <john.fastabend@gmail.com> Acked-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20201029201442.596690-1-dev@der-flo.net
- Loading branch information
Florian Lehner
authored and
Alexei Starovoitov
committed
Nov 6, 2020
1 parent
b6b466a
commit c6bde95
Showing
4 changed files
with
94 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
|
||
#include <test_progs.h> | ||
#include "test_hash_large_key.skel.h" | ||
|
||
void test_hash_large_key(void) | ||
{ | ||
int err, value = 21, duration = 0, hash_map_fd; | ||
struct test_hash_large_key *skel; | ||
|
||
struct bigelement { | ||
int a; | ||
char b[4096]; | ||
long long c; | ||
} key; | ||
bzero(&key, sizeof(key)); | ||
|
||
skel = test_hash_large_key__open_and_load(); | ||
if (CHECK(!skel, "skel_open_and_load", "skeleton open/load failed\n")) | ||
return; | ||
|
||
hash_map_fd = bpf_map__fd(skel->maps.hash_map); | ||
if (CHECK(hash_map_fd < 0, "bpf_map__fd", "failed\n")) | ||
goto cleanup; | ||
|
||
err = test_hash_large_key__attach(skel); | ||
if (CHECK(err, "attach_raw_tp", "err %d\n", err)) | ||
goto cleanup; | ||
|
||
err = bpf_map_update_elem(hash_map_fd, &key, &value, BPF_ANY); | ||
if (CHECK(err, "bpf_map_update_elem", "errno=%d\n", errno)) | ||
goto cleanup; | ||
|
||
key.c = 1; | ||
err = bpf_map_lookup_elem(hash_map_fd, &key, &value); | ||
if (CHECK(err, "bpf_map_lookup_elem", "errno=%d\n", errno)) | ||
goto cleanup; | ||
|
||
CHECK_FAIL(value != 42); | ||
|
||
cleanup: | ||
test_hash_large_key__destroy(skel); | ||
} |
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,44 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
|
||
#include <linux/bpf.h> | ||
#include <bpf/bpf_helpers.h> | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_HASH); | ||
__uint(max_entries, 2); | ||
__type(key, struct bigelement); | ||
__type(value, __u32); | ||
} hash_map SEC(".maps"); | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); | ||
__uint(max_entries, 1); | ||
__type(key, __u32); | ||
__type(value, struct bigelement); | ||
} key_map SEC(".maps"); | ||
|
||
struct bigelement { | ||
int a; | ||
char b[4096]; | ||
long long c; | ||
}; | ||
|
||
SEC("raw_tracepoint/sys_enter") | ||
int bpf_hash_large_key_test(void *ctx) | ||
{ | ||
int zero = 0, err = 1, value = 42; | ||
struct bigelement *key; | ||
|
||
key = bpf_map_lookup_elem(&key_map, &zero); | ||
if (!key) | ||
return 0; | ||
|
||
key->c = 1; | ||
if (bpf_map_update_elem(&hash_map, key, &value, BPF_ANY)) | ||
return 0; | ||
|
||
return 0; | ||
} | ||
|
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