]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.19.34/selftests-bpf-skip-verifier-tests-for-unsupported-pr.patch
Linux 4.19.34
[thirdparty/kernel/stable-queue.git] / releases / 4.19.34 / selftests-bpf-skip-verifier-tests-for-unsupported-pr.patch
CommitLineData
ba172962
SL
1From a233828ccb15c264a66b6ad66283357fbf856632 Mon Sep 17 00:00:00 2001
2From: Stanislav Fomichev <sdf@google.com>
3Date: Mon, 28 Jan 2019 09:21:16 -0800
4Subject: selftests/bpf: skip verifier tests for unsupported program types
5
6[ Upstream commit 8184d44c9a577a2f1842ed6cc844bfd4a9981d8e ]
7
8Use recently introduced bpf_probe_prog_type() to skip tests in the
9test_verifier() if bpf_verify_program() fails. The skipped test is
10indicated in the output.
11
12Example:
13
14...
15679/p bpf_get_stack return R0 within range SKIP (unsupported program
16type 5)
17680/p ld_abs: invalid op 1 OK
18...
19Summary: 863 PASSED, 165 SKIPPED, 3 FAILED
20
21Signed-off-by: Stanislav Fomichev <sdf@google.com>
22Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
23Signed-off-by: Sasha Levin <sashal@kernel.org>
24---
25 tools/testing/selftests/bpf/test_verifier.c | 9 ++++++++-
26 1 file changed, 8 insertions(+), 1 deletion(-)
27
28diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
29index 9db5a7378f40..294fc18aba2a 100644
30--- a/tools/testing/selftests/bpf/test_verifier.c
31+++ b/tools/testing/selftests/bpf/test_verifier.c
32@@ -32,6 +32,7 @@
33 #include <linux/if_ether.h>
34
35 #include <bpf/bpf.h>
36+#include <bpf/libbpf.h>
37
38 #ifdef HAVE_GENHDR
39 # include "autoconf.h"
40@@ -56,6 +57,7 @@
41
42 #define UNPRIV_SYSCTL "kernel/unprivileged_bpf_disabled"
43 static bool unpriv_disabled = false;
44+static int skips;
45
46 struct bpf_test {
47 const char *descr;
48@@ -12770,6 +12772,11 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
49 fd_prog = bpf_verify_program(prog_type ? : BPF_PROG_TYPE_SOCKET_FILTER,
50 prog, prog_len, test->flags & F_LOAD_WITH_STRICT_ALIGNMENT,
51 "GPL", 0, bpf_vlog, sizeof(bpf_vlog), 1);
52+ if (fd_prog < 0 && !bpf_probe_prog_type(prog_type, 0)) {
53+ printf("SKIP (unsupported program type %d)\n", prog_type);
54+ skips++;
55+ goto close_fds;
56+ }
57
58 expected_ret = unpriv && test->result_unpriv != UNDEF ?
59 test->result_unpriv : test->result;
60@@ -12905,7 +12912,7 @@ static void get_unpriv_disabled()
61
62 static int do_test(bool unpriv, unsigned int from, unsigned int to)
63 {
64- int i, passes = 0, errors = 0, skips = 0;
65+ int i, passes = 0, errors = 0;
66
67 for (i = from; i < to; i++) {
68 struct bpf_test *test = &tests[i];
69--
702.19.1
71