diff options
| author | Daniel Rosenberg <[email protected]> | 2023-05-06 01:31:34 +0000 |
|---|---|---|
| committer | Alexei Starovoitov <[email protected]> | 2023-05-06 23:42:58 +0000 |
| commit | 798e48fc28fa64aa4eca6e8a404fa20ac8f7c09e (patch) | |
| tree | 9a5ef4b52333e03d5360e85b6d3aa34fa9747050 /tools/testing/selftests/bpf/progs/dynptr_success.c | |
| parent | bpf: verifier: Accept dynptr mem as mem in helpers (diff) | |
| download | kernel-798e48fc28fa64aa4eca6e8a404fa20ac8f7c09e.tar.gz kernel-798e48fc28fa64aa4eca6e8a404fa20ac8f7c09e.zip | |
selftests/bpf: Accept mem from dynptr in helper funcs
This ensures that buffers retrieved from dynptr_data are allowed to be
passed in to helpers that take mem, like bpf_strncmp
Signed-off-by: Daniel Rosenberg <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/dynptr_success.c')
| -rw-r--r-- | tools/testing/selftests/bpf/progs/dynptr_success.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/dynptr_success.c b/tools/testing/selftests/bpf/progs/dynptr_success.c index d299ef3b4d1f..0c053976f8f9 100644 --- a/tools/testing/selftests/bpf/progs/dynptr_success.c +++ b/tools/testing/selftests/bpf/progs/dynptr_success.c @@ -522,3 +522,24 @@ int test_dynptr_skb_no_buff(struct __sk_buff *skb) return !!data; } + +SEC("?cgroup_skb/egress") +int test_dynptr_skb_strcmp(struct __sk_buff *skb) +{ + struct bpf_dynptr ptr; + char *data; + + if (bpf_dynptr_from_skb(skb, 0, &ptr)) { + err = 1; + return 1; + } + + /* This may return NULL. SKB may require a buffer */ + data = bpf_dynptr_slice(&ptr, 0, NULL, 10); + if (data) { + bpf_strncmp(data, 10, "foo"); + return 1; + } + + return 1; +} |
