aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@fb.com>2017-10-03 01:50:23 -0400
committerDavid S. Miller <davem@davemloft.net>2017-10-04 19:05:05 -0400
commit390ee7e29fc8e6e90d3065b00afb047c4ee552f9 (patch)
tree9a5d9870bb4cf67905cb638cbe1b3063251a100f /tools
parent468e2f64d220fe2dc11caa2bcb9b3a1e50fc7321 (diff)
bpf: enforce return code for cgroup-bpf programs
with addition of tnum logic the verifier got smart enough and we can enforce return codes at program load time. For now do so for cgroup-bpf program types. Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/bpf/test_verifier.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index 290d5056c165..cc91d0159f43 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -6892,6 +6892,78 @@ static struct bpf_test tests[] = {
6892 .result = ACCEPT, 6892 .result = ACCEPT,
6893 .prog_type = BPF_PROG_TYPE_XDP, 6893 .prog_type = BPF_PROG_TYPE_XDP,
6894 }, 6894 },
6895 {
6896 "bpf_exit with invalid return code. test1",
6897 .insns = {
6898 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, 0),
6899 BPF_EXIT_INSN(),
6900 },
6901 .errstr = "R0 has value (0x0; 0xffffffff)",
6902 .result = REJECT,
6903 .prog_type = BPF_PROG_TYPE_CGROUP_SOCK,
6904 },
6905 {
6906 "bpf_exit with invalid return code. test2",
6907 .insns = {
6908 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, 0),
6909 BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 1),
6910 BPF_EXIT_INSN(),
6911 },
6912 .result = ACCEPT,
6913 .prog_type = BPF_PROG_TYPE_CGROUP_SOCK,
6914 },
6915 {
6916 "bpf_exit with invalid return code. test3",
6917 .insns = {
6918 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, 0),
6919 BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 3),
6920 BPF_EXIT_INSN(),
6921 },
6922 .errstr = "R0 has value (0x0; 0x3)",
6923 .result = REJECT,
6924 .prog_type = BPF_PROG_TYPE_CGROUP_SOCK,
6925 },
6926 {
6927 "bpf_exit with invalid return code. test4",
6928 .insns = {
6929 BPF_MOV64_IMM(BPF_REG_0, 1),
6930 BPF_EXIT_INSN(),
6931 },
6932 .result = ACCEPT,
6933 .prog_type = BPF_PROG_TYPE_CGROUP_SOCK,
6934 },
6935 {
6936 "bpf_exit with invalid return code. test5",
6937 .insns = {
6938 BPF_MOV64_IMM(BPF_REG_0, 2),
6939 BPF_EXIT_INSN(),
6940 },
6941 .errstr = "R0 has value (0x2; 0x0)",
6942 .result = REJECT,
6943 .prog_type = BPF_PROG_TYPE_CGROUP_SOCK,
6944 },
6945 {
6946 "bpf_exit with invalid return code. test6",
6947 .insns = {
6948 BPF_MOV64_REG(BPF_REG_0, BPF_REG_1),
6949 BPF_EXIT_INSN(),
6950 },
6951 .errstr = "R0 is not a known value (ctx)",
6952 .result = REJECT,
6953 .prog_type = BPF_PROG_TYPE_CGROUP_SOCK,
6954 },
6955 {
6956 "bpf_exit with invalid return code. test7",
6957 .insns = {
6958 BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, 0),
6959 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, 4),
6960 BPF_ALU64_REG(BPF_MUL, BPF_REG_0, BPF_REG_2),
6961 BPF_EXIT_INSN(),
6962 },
6963 .errstr = "R0 has unknown scalar value",
6964 .result = REJECT,
6965 .prog_type = BPF_PROG_TYPE_CGROUP_SOCK,
6966 },
6895}; 6967};
6896 6968
6897static int probe_filter_length(const struct bpf_insn *fp) 6969static int probe_filter_length(const struct bpf_insn *fp)