diff options
author | Udip Pant <udippant@fb.com> | 2020-08-25 16:20:03 -0700 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2020-08-26 12:47:56 -0700 |
commit | 1410620cf20e7e23cce17983e9a81af659b28583 (patch) | |
tree | 9c85e9701630619b177f54108794bed961bd1b93 /tools/testing/selftests/bpf/progs/freplace_cls_redirect.c | |
parent | 50d19736aff497a4c25ec7e36375195bfd8570cd (diff) | |
download | linux-stable-1410620cf20e7e23cce17983e9a81af659b28583.tar.gz linux-stable-1410620cf20e7e23cce17983e9a81af659b28583.tar.bz2 linux-stable-1410620cf20e7e23cce17983e9a81af659b28583.zip |
selftests/bpf: Test for map update access from within EXT programs
This adds further tests to ensure access permissions and restrictions
are applied properly for some map types such as sock-map.
It also adds another negative tests to assert static functions cannot be
replaced. In the 'unreliable' mode it still fails with error 'tracing progs
cannot use bpf_spin_lock yet' with the change in the verifier
Signed-off-by: Udip Pant <udippant@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200825232003.2877030-5-udippant@fb.com
Diffstat (limited to 'tools/testing/selftests/bpf/progs/freplace_cls_redirect.c')
-rw-r--r-- | tools/testing/selftests/bpf/progs/freplace_cls_redirect.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/freplace_cls_redirect.c b/tools/testing/selftests/bpf/progs/freplace_cls_redirect.c new file mode 100644 index 000000000000..68a5a9db928a --- /dev/null +++ b/tools/testing/selftests/bpf/progs/freplace_cls_redirect.c @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2020 Facebook + +#include <linux/stddef.h> +#include <linux/bpf.h> +#include <linux/pkt_cls.h> +#include <bpf/bpf_endian.h> +#include <bpf/bpf_helpers.h> + +struct bpf_map_def SEC("maps") sock_map = { + .type = BPF_MAP_TYPE_SOCKMAP, + .key_size = sizeof(int), + .value_size = sizeof(int), + .max_entries = 2, +}; + +SEC("freplace/cls_redirect") +int freplace_cls_redirect_test(struct __sk_buff *skb) +{ + int ret = 0; + const int zero = 0; + struct bpf_sock *sk; + + sk = bpf_map_lookup_elem(&sock_map, &zero); + if (!sk) + return TC_ACT_SHOT; + + ret = bpf_map_update_elem(&sock_map, &zero, sk, 0); + bpf_sk_release(sk); + + return ret == 0 ? TC_ACT_OK : TC_ACT_SHOT; +} + +char _license[] SEC("license") = "GPL"; |