treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / tools / testing / selftests / bpf / verifier / div_overflow.c
blobacab4f00819f331a6bd58e24d373e88a97b6dce5
1 /* Just make sure that JITs used udiv/umod as otherwise we get
2 * an exception from INT_MIN/-1 overflow similarly as with div
3 * by zero.
4 */
6 "DIV32 overflow, check 1",
7 .insns = {
8 BPF_MOV32_IMM(BPF_REG_1, -1),
9 BPF_MOV32_IMM(BPF_REG_0, INT_MIN),
10 BPF_ALU32_REG(BPF_DIV, BPF_REG_0, BPF_REG_1),
11 BPF_EXIT_INSN(),
13 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
14 .result = ACCEPT,
15 .retval = 0,
18 "DIV32 overflow, check 2",
19 .insns = {
20 BPF_MOV32_IMM(BPF_REG_0, INT_MIN),
21 BPF_ALU32_IMM(BPF_DIV, BPF_REG_0, -1),
22 BPF_EXIT_INSN(),
24 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
25 .result = ACCEPT,
26 .retval = 0,
29 "DIV64 overflow, check 1",
30 .insns = {
31 BPF_MOV64_IMM(BPF_REG_1, -1),
32 BPF_LD_IMM64(BPF_REG_2, LLONG_MIN),
33 BPF_ALU64_REG(BPF_DIV, BPF_REG_2, BPF_REG_1),
34 BPF_MOV32_IMM(BPF_REG_0, 0),
35 BPF_JMP_REG(BPF_JEQ, BPF_REG_0, BPF_REG_2, 1),
36 BPF_MOV32_IMM(BPF_REG_0, 1),
37 BPF_EXIT_INSN(),
39 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
40 .result = ACCEPT,
41 .retval = 0,
44 "DIV64 overflow, check 2",
45 .insns = {
46 BPF_LD_IMM64(BPF_REG_1, LLONG_MIN),
47 BPF_ALU64_IMM(BPF_DIV, BPF_REG_1, -1),
48 BPF_MOV32_IMM(BPF_REG_0, 0),
49 BPF_JMP_REG(BPF_JEQ, BPF_REG_0, BPF_REG_1, 1),
50 BPF_MOV32_IMM(BPF_REG_0, 1),
51 BPF_EXIT_INSN(),
53 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
54 .result = ACCEPT,
55 .retval = 0,
58 "MOD32 overflow, check 1",
59 .insns = {
60 BPF_MOV32_IMM(BPF_REG_1, -1),
61 BPF_MOV32_IMM(BPF_REG_0, INT_MIN),
62 BPF_ALU32_REG(BPF_MOD, BPF_REG_0, BPF_REG_1),
63 BPF_EXIT_INSN(),
65 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
66 .result = ACCEPT,
67 .retval = INT_MIN,
70 "MOD32 overflow, check 2",
71 .insns = {
72 BPF_MOV32_IMM(BPF_REG_0, INT_MIN),
73 BPF_ALU32_IMM(BPF_MOD, BPF_REG_0, -1),
74 BPF_EXIT_INSN(),
76 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
77 .result = ACCEPT,
78 .retval = INT_MIN,
81 "MOD64 overflow, check 1",
82 .insns = {
83 BPF_MOV64_IMM(BPF_REG_1, -1),
84 BPF_LD_IMM64(BPF_REG_2, LLONG_MIN),
85 BPF_MOV64_REG(BPF_REG_3, BPF_REG_2),
86 BPF_ALU64_REG(BPF_MOD, BPF_REG_2, BPF_REG_1),
87 BPF_MOV32_IMM(BPF_REG_0, 0),
88 BPF_JMP_REG(BPF_JNE, BPF_REG_3, BPF_REG_2, 1),
89 BPF_MOV32_IMM(BPF_REG_0, 1),
90 BPF_EXIT_INSN(),
92 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
93 .result = ACCEPT,
94 .retval = 1,
97 "MOD64 overflow, check 2",
98 .insns = {
99 BPF_LD_IMM64(BPF_REG_2, LLONG_MIN),
100 BPF_MOV64_REG(BPF_REG_3, BPF_REG_2),
101 BPF_ALU64_IMM(BPF_MOD, BPF_REG_2, -1),
102 BPF_MOV32_IMM(BPF_REG_0, 0),
103 BPF_JMP_REG(BPF_JNE, BPF_REG_3, BPF_REG_2, 1),
104 BPF_MOV32_IMM(BPF_REG_0, 1),
105 BPF_EXIT_INSN(),
107 .prog_type = BPF_PROG_TYPE_SCHED_CLS,
108 .result = ACCEPT,
109 .retval = 1,