diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2017-09-04 12:22:54 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2017-09-04 12:22:54 -0400 |
commit | a6cbfa1e6d38c4b3ab0ce7e3aea4bb4e744f24b8 (patch) | |
tree | 8960e571a398b5d32e72bdb9c89ce965daa870ab /tools/testing | |
parent | f5308d1b83eba20e69df5e0926ba7257c8dd9074 (diff) | |
parent | 08d6ac9ee5fedd82040bc878705981b67a116a3f (diff) |
Merge branch 'next' into for-linus
Prepare input updates for 4.14 merge window.
Diffstat (limited to 'tools/testing')
-rw-r--r-- | tools/testing/selftests/bpf/bpf_endian.h | 41 | ||||
-rw-r--r-- | tools/testing/selftests/bpf/test_verifier.c | 66 | ||||
-rwxr-xr-x | tools/testing/selftests/ntb/ntb_test.sh | 2 |
3 files changed, 97 insertions, 12 deletions
diff --git a/tools/testing/selftests/bpf/bpf_endian.h b/tools/testing/selftests/bpf/bpf_endian.h index 19d0604f8694..487cbfb89beb 100644 --- a/tools/testing/selftests/bpf/bpf_endian.h +++ b/tools/testing/selftests/bpf/bpf_endian.h | |||
@@ -1,23 +1,42 @@ | |||
1 | #ifndef __BPF_ENDIAN__ | 1 | #ifndef __BPF_ENDIAN__ |
2 | #define __BPF_ENDIAN__ | 2 | #define __BPF_ENDIAN__ |
3 | 3 | ||
4 | #include <asm/byteorder.h> | 4 | #include <linux/swab.h> |
5 | 5 | ||
6 | #if __BYTE_ORDER == __LITTLE_ENDIAN | 6 | /* LLVM's BPF target selects the endianness of the CPU |
7 | # define __bpf_ntohs(x) __builtin_bswap16(x) | 7 | * it compiles on, or the user specifies (bpfel/bpfeb), |
8 | # define __bpf_htons(x) __builtin_bswap16(x) | 8 | * respectively. The used __BYTE_ORDER__ is defined by |
9 | #elif __BYTE_ORDER == __BIG_ENDIAN | 9 | * the compiler, we cannot rely on __BYTE_ORDER from |
10 | # define __bpf_ntohs(x) (x) | 10 | * libc headers, since it doesn't reflect the actual |
11 | # define __bpf_htons(x) (x) | 11 | * requested byte order. |
12 | * | ||
13 | * Note, LLVM's BPF target has different __builtin_bswapX() | ||
14 | * semantics. It does map to BPF_ALU | BPF_END | BPF_TO_BE | ||
15 | * in bpfel and bpfeb case, which means below, that we map | ||
16 | * to cpu_to_be16(). We could use it unconditionally in BPF | ||
17 | * case, but better not rely on it, so that this header here | ||
18 | * can be used from application and BPF program side, which | ||
19 | * use different targets. | ||
20 | */ | ||
21 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ | ||
22 | # define __bpf_ntohs(x) __builtin_bswap16(x) | ||
23 | # define __bpf_htons(x) __builtin_bswap16(x) | ||
24 | # define __bpf_constant_ntohs(x) ___constant_swab16(x) | ||
25 | # define __bpf_constant_htons(x) ___constant_swab16(x) | ||
26 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ | ||
27 | # define __bpf_ntohs(x) (x) | ||
28 | # define __bpf_htons(x) (x) | ||
29 | # define __bpf_constant_ntohs(x) (x) | ||
30 | # define __bpf_constant_htons(x) (x) | ||
12 | #else | 31 | #else |
13 | # error "Fix your __BYTE_ORDER?!" | 32 | # error "Fix your compiler's __BYTE_ORDER__?!" |
14 | #endif | 33 | #endif |
15 | 34 | ||
16 | #define bpf_htons(x) \ | 35 | #define bpf_htons(x) \ |
17 | (__builtin_constant_p(x) ? \ | 36 | (__builtin_constant_p(x) ? \ |
18 | __constant_htons(x) : __bpf_htons(x)) | 37 | __bpf_constant_htons(x) : __bpf_htons(x)) |
19 | #define bpf_ntohs(x) \ | 38 | #define bpf_ntohs(x) \ |
20 | (__builtin_constant_p(x) ? \ | 39 | (__builtin_constant_p(x) ? \ |
21 | __constant_ntohs(x) : __bpf_ntohs(x)) | 40 | __bpf_constant_ntohs(x) : __bpf_ntohs(x)) |
22 | 41 | ||
23 | #endif | 42 | #endif /* __BPF_ENDIAN__ */ |
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index cabb19b1e371..0ff8c55c0464 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c | |||
@@ -3749,6 +3749,72 @@ static struct bpf_test tests[] = { | |||
3749 | .errstr = "invalid bpf_context access", | 3749 | .errstr = "invalid bpf_context access", |
3750 | }, | 3750 | }, |
3751 | { | 3751 | { |
3752 | "leak pointer into ctx 1", | ||
3753 | .insns = { | ||
3754 | BPF_MOV64_IMM(BPF_REG_0, 0), | ||
3755 | BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, | ||
3756 | offsetof(struct __sk_buff, cb[0])), | ||
3757 | BPF_LD_MAP_FD(BPF_REG_2, 0), | ||
3758 | BPF_STX_XADD(BPF_DW, BPF_REG_1, BPF_REG_2, | ||
3759 | offsetof(struct __sk_buff, cb[0])), | ||
3760 | BPF_EXIT_INSN(), | ||
3761 | }, | ||
3762 | .fixup_map1 = { 2 }, | ||
3763 | .errstr_unpriv = "R2 leaks addr into mem", | ||
3764 | .result_unpriv = REJECT, | ||
3765 | .result = ACCEPT, | ||
3766 | }, | ||
3767 | { | ||
3768 | "leak pointer into ctx 2", | ||
3769 | .insns = { | ||
3770 | BPF_MOV64_IMM(BPF_REG_0, 0), | ||
3771 | BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, | ||
3772 | offsetof(struct __sk_buff, cb[0])), | ||
3773 | BPF_STX_XADD(BPF_DW, BPF_REG_1, BPF_REG_10, | ||
3774 | offsetof(struct __sk_buff, cb[0])), | ||
3775 | BPF_EXIT_INSN(), | ||
3776 | }, | ||
3777 | .errstr_unpriv = "R10 leaks addr into mem", | ||
3778 | .result_unpriv = REJECT, | ||
3779 | .result = ACCEPT, | ||
3780 | }, | ||
3781 | { | ||
3782 | "leak pointer into ctx 3", | ||
3783 | .insns = { | ||
3784 | BPF_MOV64_IMM(BPF_REG_0, 0), | ||
3785 | BPF_LD_MAP_FD(BPF_REG_2, 0), | ||
3786 | BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, | ||
3787 | offsetof(struct __sk_buff, cb[0])), | ||
3788 | BPF_EXIT_INSN(), | ||
3789 | }, | ||
3790 | .fixup_map1 = { 1 }, | ||
3791 | .errstr_unpriv = "R2 leaks addr into ctx", | ||
3792 | .result_unpriv = REJECT, | ||
3793 | .result = ACCEPT, | ||
3794 | }, | ||
3795 | { | ||
3796 | "leak pointer into map val", | ||
3797 | .insns = { | ||
3798 | BPF_MOV64_REG(BPF_REG_6, BPF_REG_1), | ||
3799 | BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0), | ||
3800 | BPF_MOV64_REG(BPF_REG_2, BPF_REG_10), | ||
3801 | BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8), | ||
3802 | BPF_LD_MAP_FD(BPF_REG_1, 0), | ||
3803 | BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, | ||
3804 | BPF_FUNC_map_lookup_elem), | ||
3805 | BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 3), | ||
3806 | BPF_MOV64_IMM(BPF_REG_3, 0), | ||
3807 | BPF_STX_MEM(BPF_DW, BPF_REG_0, BPF_REG_3, 0), | ||
3808 | BPF_STX_XADD(BPF_DW, BPF_REG_0, BPF_REG_6, 0), | ||
3809 | BPF_MOV64_IMM(BPF_REG_0, 0), | ||
3810 | BPF_EXIT_INSN(), | ||
3811 | }, | ||
3812 | .fixup_map1 = { 4 }, | ||
3813 | .errstr_unpriv = "R6 leaks addr into mem", | ||
3814 | .result_unpriv = REJECT, | ||
3815 | .result = ACCEPT, | ||
3816 | }, | ||
3817 | { | ||
3752 | "helper access to map: full range", | 3818 | "helper access to map: full range", |
3753 | .insns = { | 3819 | .insns = { |
3754 | BPF_MOV64_REG(BPF_REG_2, BPF_REG_10), | 3820 | BPF_MOV64_REG(BPF_REG_2, BPF_REG_10), |
diff --git a/tools/testing/selftests/ntb/ntb_test.sh b/tools/testing/selftests/ntb/ntb_test.sh index a676d3eefefb..13f5198ba0ee 100755 --- a/tools/testing/selftests/ntb/ntb_test.sh +++ b/tools/testing/selftests/ntb/ntb_test.sh | |||
@@ -305,7 +305,7 @@ function perf_test() | |||
305 | echo "Running remote perf test $WITH DMA" | 305 | echo "Running remote perf test $WITH DMA" |
306 | write_file "" $REMOTE_PERF/run | 306 | write_file "" $REMOTE_PERF/run |
307 | echo -n " " | 307 | echo -n " " |
308 | read_file $LOCAL_PERF/run | 308 | read_file $REMOTE_PERF/run |
309 | echo " Passed" | 309 | echo " Passed" |
310 | 310 | ||
311 | _modprobe -r ntb_perf | 311 | _modprobe -r ntb_perf |