aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2018-10-24 16:05:43 -0400
committerAlexei Starovoitov <ast@kernel.org>2018-10-25 20:02:05 -0400
commit36641ad61db5ce9befd5eb0071abb36eaff16cfc (patch)
tree750b0afb983007773bc86776adeb0bfc9be1a43c /tools/testing
parent4a6998aff82a20a1aece86a186d8e5263f8b2315 (diff)
bpf: fix test suite to enable all unpriv program types
Given BPF_PROG_TYPE_CGROUP_SKB program types are also valid in an unprivileged setting, lets not omit these tests and potentially have issues fall through the cracks. Make this more obvious by adding a small test_as_unpriv() helper. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/selftests/bpf/test_verifier.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index 769d68a48f30..8e1a79d2792c 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -4891,6 +4891,8 @@ static struct bpf_test tests[] = {
4891 BPF_EXIT_INSN(), 4891 BPF_EXIT_INSN(),
4892 }, 4892 },
4893 .result = ACCEPT, 4893 .result = ACCEPT,
4894 .result_unpriv = REJECT,
4895 .errstr_unpriv = "R3 pointer comparison prohibited",
4894 .prog_type = BPF_PROG_TYPE_CGROUP_SKB, 4896 .prog_type = BPF_PROG_TYPE_CGROUP_SKB,
4895 }, 4897 },
4896 { 4898 {
@@ -5146,6 +5148,7 @@ static struct bpf_test tests[] = {
5146 .fixup_cgroup_storage = { 1 }, 5148 .fixup_cgroup_storage = { 1 },
5147 .result = REJECT, 5149 .result = REJECT,
5148 .errstr = "get_local_storage() doesn't support non-zero flags", 5150 .errstr = "get_local_storage() doesn't support non-zero flags",
5151 .errstr_unpriv = "R2 leaks addr into helper function",
5149 .prog_type = BPF_PROG_TYPE_CGROUP_SKB, 5152 .prog_type = BPF_PROG_TYPE_CGROUP_SKB,
5150 }, 5153 },
5151 { 5154 {
@@ -5261,6 +5264,7 @@ static struct bpf_test tests[] = {
5261 .fixup_percpu_cgroup_storage = { 1 }, 5264 .fixup_percpu_cgroup_storage = { 1 },
5262 .result = REJECT, 5265 .result = REJECT,
5263 .errstr = "get_local_storage() doesn't support non-zero flags", 5266 .errstr = "get_local_storage() doesn't support non-zero flags",
5267 .errstr_unpriv = "R2 leaks addr into helper function",
5264 .prog_type = BPF_PROG_TYPE_CGROUP_SKB, 5268 .prog_type = BPF_PROG_TYPE_CGROUP_SKB,
5265 }, 5269 },
5266 { 5270 {
@@ -14050,6 +14054,13 @@ static void get_unpriv_disabled()
14050 fclose(fd); 14054 fclose(fd);
14051} 14055}
14052 14056
14057static bool test_as_unpriv(struct bpf_test *test)
14058{
14059 return !test->prog_type ||
14060 test->prog_type == BPF_PROG_TYPE_SOCKET_FILTER ||
14061 test->prog_type == BPF_PROG_TYPE_CGROUP_SKB;
14062}
14063
14053static int do_test(bool unpriv, unsigned int from, unsigned int to) 14064static int do_test(bool unpriv, unsigned int from, unsigned int to)
14054{ 14065{
14055 int i, passes = 0, errors = 0, skips = 0; 14066 int i, passes = 0, errors = 0, skips = 0;
@@ -14060,10 +14071,10 @@ static int do_test(bool unpriv, unsigned int from, unsigned int to)
14060 /* Program types that are not supported by non-root we 14071 /* Program types that are not supported by non-root we
14061 * skip right away. 14072 * skip right away.
14062 */ 14073 */
14063 if (!test->prog_type && unpriv_disabled) { 14074 if (test_as_unpriv(test) && unpriv_disabled) {
14064 printf("#%d/u %s SKIP\n", i, test->descr); 14075 printf("#%d/u %s SKIP\n", i, test->descr);
14065 skips++; 14076 skips++;
14066 } else if (!test->prog_type) { 14077 } else if (test_as_unpriv(test)) {
14067 if (!unpriv) 14078 if (!unpriv)
14068 set_admin(false); 14079 set_admin(false);
14069 printf("#%d/u %s ", i, test->descr); 14080 printf("#%d/u %s ", i, test->descr);