diff options
author | Daniel Borkmann <daniel@iogearbox.net> | 2018-07-19 12:18:36 -0400 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2018-07-19 19:08:06 -0400 |
commit | fa47a16b04ad896ea9c10d4fa0caf47dcf47cd00 (patch) | |
tree | edddd22c72b270f167cd13371e29b95c97f661a3 | |
parent | b9c1e60e7bf4e64ac1b4f4d6d593f0bb57886973 (diff) |
bpf: test case to check whether src/dst regs got mangled by xadd
We currently do not have such a test case in test_verifier selftests
but it's important to test under bpf_jit_enable=1 to make sure JIT
implementations do not mistakenly mess with src/dst reg for xadd/{w,dw}.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r-- | tools/testing/selftests/bpf/test_verifier.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index f5f7bcc96046..41106d9d5cc7 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c | |||
@@ -12005,6 +12005,46 @@ static struct bpf_test tests[] = { | |||
12005 | .prog_type = BPF_PROG_TYPE_XDP, | 12005 | .prog_type = BPF_PROG_TYPE_XDP, |
12006 | }, | 12006 | }, |
12007 | { | 12007 | { |
12008 | "xadd/w check whether src/dst got mangled, 1", | ||
12009 | .insns = { | ||
12010 | BPF_MOV64_IMM(BPF_REG_0, 1), | ||
12011 | BPF_MOV64_REG(BPF_REG_6, BPF_REG_0), | ||
12012 | BPF_MOV64_REG(BPF_REG_7, BPF_REG_10), | ||
12013 | BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -8), | ||
12014 | BPF_STX_XADD(BPF_DW, BPF_REG_10, BPF_REG_0, -8), | ||
12015 | BPF_STX_XADD(BPF_DW, BPF_REG_10, BPF_REG_0, -8), | ||
12016 | BPF_JMP_REG(BPF_JNE, BPF_REG_6, BPF_REG_0, 3), | ||
12017 | BPF_JMP_REG(BPF_JNE, BPF_REG_7, BPF_REG_10, 2), | ||
12018 | BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_10, -8), | ||
12019 | BPF_EXIT_INSN(), | ||
12020 | BPF_MOV64_IMM(BPF_REG_0, 42), | ||
12021 | BPF_EXIT_INSN(), | ||
12022 | }, | ||
12023 | .result = ACCEPT, | ||
12024 | .prog_type = BPF_PROG_TYPE_SCHED_CLS, | ||
12025 | .retval = 3, | ||
12026 | }, | ||
12027 | { | ||
12028 | "xadd/w check whether src/dst got mangled, 2", | ||
12029 | .insns = { | ||
12030 | BPF_MOV64_IMM(BPF_REG_0, 1), | ||
12031 | BPF_MOV64_REG(BPF_REG_6, BPF_REG_0), | ||
12032 | BPF_MOV64_REG(BPF_REG_7, BPF_REG_10), | ||
12033 | BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_0, -8), | ||
12034 | BPF_STX_XADD(BPF_W, BPF_REG_10, BPF_REG_0, -8), | ||
12035 | BPF_STX_XADD(BPF_W, BPF_REG_10, BPF_REG_0, -8), | ||
12036 | BPF_JMP_REG(BPF_JNE, BPF_REG_6, BPF_REG_0, 3), | ||
12037 | BPF_JMP_REG(BPF_JNE, BPF_REG_7, BPF_REG_10, 2), | ||
12038 | BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_10, -8), | ||
12039 | BPF_EXIT_INSN(), | ||
12040 | BPF_MOV64_IMM(BPF_REG_0, 42), | ||
12041 | BPF_EXIT_INSN(), | ||
12042 | }, | ||
12043 | .result = ACCEPT, | ||
12044 | .prog_type = BPF_PROG_TYPE_SCHED_CLS, | ||
12045 | .retval = 3, | ||
12046 | }, | ||
12047 | { | ||
12008 | "bpf_get_stack return R0 within range", | 12048 | "bpf_get_stack return R0 within range", |
12009 | .insns = { | 12049 | .insns = { |
12010 | BPF_MOV64_REG(BPF_REG_6, BPF_REG_1), | 12050 | BPF_MOV64_REG(BPF_REG_6, BPF_REG_1), |