|
@@ -2905,6 +2905,953 @@ static struct bpf_test tests[] = {
|
|
|
.result = REJECT,
|
|
|
.errstr = "invalid bpf_context access",
|
|
|
},
|
|
|
+ {
|
|
|
+ "helper access to map: full range",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 4),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, sizeof(struct test_val)),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .result = ACCEPT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to map: partial range",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 4),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 8),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .result = ACCEPT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to map: empty range",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 4),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr = "invalid access to map value, value_size=48 off=0 size=0",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to map: out-of-bound range",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 4),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, sizeof(struct test_val) + 8),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr = "invalid access to map value, value_size=48 off=0 size=56",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to map: negative range",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 4),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, -8),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr = "invalid access to map value, value_size=48 off=0 size=-8",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via const imm): full range",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 5),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1,
|
|
|
+ offsetof(struct test_val, foo)),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2,
|
|
|
+ sizeof(struct test_val) -
|
|
|
+ offsetof(struct test_val, foo)),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .result = ACCEPT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via const imm): partial range",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 5),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1,
|
|
|
+ offsetof(struct test_val, foo)),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 8),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .result = ACCEPT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via const imm): empty range",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 5),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1,
|
|
|
+ offsetof(struct test_val, foo)),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr = "R1 min value is outside of the array range",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via const imm): out-of-bound range",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 5),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1,
|
|
|
+ offsetof(struct test_val, foo)),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2,
|
|
|
+ sizeof(struct test_val) -
|
|
|
+ offsetof(struct test_val, foo) + 8),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr = "invalid access to map value, value_size=48 off=4 size=52",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via const imm): negative range (> adjustment)",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 5),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1,
|
|
|
+ offsetof(struct test_val, foo)),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, -8),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr = "invalid access to map value, value_size=48 off=4 size=-8",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via const imm): negative range (< adjustment)",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 5),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1,
|
|
|
+ offsetof(struct test_val, foo)),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, -1),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr = "R1 min value is outside of the array range",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via const reg): full range",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 6),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3,
|
|
|
+ offsetof(struct test_val, foo)),
|
|
|
+ BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2,
|
|
|
+ sizeof(struct test_val) -
|
|
|
+ offsetof(struct test_val, foo)),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .result = ACCEPT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via const reg): partial range",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 6),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3,
|
|
|
+ offsetof(struct test_val, foo)),
|
|
|
+ BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 8),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .result = ACCEPT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via const reg): empty range",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 6),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr = "R1 min value is outside of the array range",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via const reg): out-of-bound range",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 6),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3,
|
|
|
+ offsetof(struct test_val, foo)),
|
|
|
+ BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2,
|
|
|
+ sizeof(struct test_val) -
|
|
|
+ offsetof(struct test_val, foo) + 8),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr = "invalid access to map value, value_size=48 off=4 size=52",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via const reg): negative range (> adjustment)",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 6),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3,
|
|
|
+ offsetof(struct test_val, foo)),
|
|
|
+ BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, -8),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr = "invalid access to map value, value_size=48 off=4 size=-8",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via const reg): negative range (< adjustment)",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 6),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3,
|
|
|
+ offsetof(struct test_val, foo)),
|
|
|
+ BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, -1),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr = "R1 min value is outside of the array range",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via variable): full range",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 7),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_0, 0),
|
|
|
+ BPF_JMP_IMM(BPF_JGT, BPF_REG_3,
|
|
|
+ offsetof(struct test_val, foo), 4),
|
|
|
+ BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2,
|
|
|
+ sizeof(struct test_val) -
|
|
|
+ offsetof(struct test_val, foo)),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .result = ACCEPT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via variable): partial range",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 7),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_0, 0),
|
|
|
+ BPF_JMP_IMM(BPF_JGT, BPF_REG_3,
|
|
|
+ offsetof(struct test_val, foo), 4),
|
|
|
+ BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 8),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .result = ACCEPT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via variable): empty range",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 7),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_0, 0),
|
|
|
+ BPF_JMP_IMM(BPF_JGT, BPF_REG_3,
|
|
|
+ offsetof(struct test_val, foo), 4),
|
|
|
+ BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr = "R1 min value is outside of the array range",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via variable): no max check",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 6),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_0, 0),
|
|
|
+ BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr = "R1 min value is negative, either use unsigned index or do a if (index >=0) check",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to adjusted map (via variable): wrong max check",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 7),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_LDX_MEM(BPF_W, BPF_REG_3, BPF_REG_0, 0),
|
|
|
+ BPF_JMP_IMM(BPF_JGT, BPF_REG_3,
|
|
|
+ offsetof(struct test_val, foo), 4),
|
|
|
+ BPF_ALU64_REG(BPF_ADD, BPF_REG_1, BPF_REG_3),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2,
|
|
|
+ sizeof(struct test_val) -
|
|
|
+ offsetof(struct test_val, foo) + 1),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr = "invalid access to map value, value_size=48 off=4 size=45",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "map element value is preserved across register spilling",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 6),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_0, 0, 42),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -184),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, 0),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_3, BPF_REG_1, 0),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_3, 0, 42),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr_unpriv = "R0 leaks addr",
|
|
|
+ .result = ACCEPT,
|
|
|
+ .result_unpriv = REJECT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "map element value (adjusted) is preserved across register spilling",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 7),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_0,
|
|
|
+ offsetof(struct test_val, foo)),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_0, 0, 42),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -184),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_0, 0),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_3, BPF_REG_1, 0),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_3, 0, 42),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr_unpriv = "R0 pointer arithmetic prohibited",
|
|
|
+ .result = ACCEPT,
|
|
|
+ .result_unpriv = REJECT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: stack, bitwise AND + JMP, correct bounds",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -64),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -56),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -48),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -40),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -32),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -24),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -16),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -8),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 16),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
|
|
|
+ BPF_ALU64_IMM(BPF_AND, BPF_REG_2, 64),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_4, 0),
|
|
|
+ BPF_JMP_REG(BPF_JGE, BPF_REG_4, BPF_REG_2, 2),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .result = ACCEPT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: stack, bitwise AND, zero included",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 16),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
|
|
|
+ BPF_ALU64_IMM(BPF_AND, BPF_REG_2, 64),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .errstr = "invalid stack type R1 off=-64 access_size=0",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: stack, bitwise AND + JMP, wrong max",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 16),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
|
|
|
+ BPF_ALU64_IMM(BPF_AND, BPF_REG_2, 65),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_4, 0),
|
|
|
+ BPF_JMP_REG(BPF_JGE, BPF_REG_4, BPF_REG_2, 2),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .errstr = "invalid stack type R1 off=-64 access_size=65",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: stack, JMP, correct bounds",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -64),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -56),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -48),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -40),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -32),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -24),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -16),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -8),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 16),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
|
|
|
+ BPF_JMP_IMM(BPF_JGT, BPF_REG_2, 64, 4),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_4, 0),
|
|
|
+ BPF_JMP_REG(BPF_JGE, BPF_REG_4, BPF_REG_2, 2),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .result = ACCEPT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: stack, JMP (signed), correct bounds",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -64),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -56),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -48),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -40),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -32),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -24),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -16),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -8),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 16),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
|
|
|
+ BPF_JMP_IMM(BPF_JSGT, BPF_REG_2, 64, 4),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_4, 0),
|
|
|
+ BPF_JMP_REG(BPF_JSGE, BPF_REG_4, BPF_REG_2, 2),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .result = ACCEPT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: stack, JMP, bounds + offset",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 16),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
|
|
|
+ BPF_JMP_IMM(BPF_JGT, BPF_REG_2, 64, 5),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_4, 0),
|
|
|
+ BPF_JMP_REG(BPF_JGE, BPF_REG_4, BPF_REG_2, 3),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .errstr = "invalid stack type R1 off=-64 access_size=65",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: stack, JMP, wrong max",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 16),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
|
|
|
+ BPF_JMP_IMM(BPF_JGT, BPF_REG_2, 65, 4),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_4, 0),
|
|
|
+ BPF_JMP_REG(BPF_JGE, BPF_REG_4, BPF_REG_2, 2),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .errstr = "invalid stack type R1 off=-64 access_size=65",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: stack, JMP, no max check",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 16),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_4, 0),
|
|
|
+ BPF_JMP_REG(BPF_JGE, BPF_REG_4, BPF_REG_2, 2),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .errstr = "R2 unbounded memory access",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: stack, JMP, no min check",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 16),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
|
|
|
+ BPF_JMP_IMM(BPF_JGT, BPF_REG_2, 64, 3),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .errstr = "invalid stack type R1 off=-64 access_size=0",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: stack, JMP (signed), no min check",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 16),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, -128),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_1, -128),
|
|
|
+ BPF_JMP_IMM(BPF_JSGT, BPF_REG_2, 64, 3),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .errstr = "R2 min value is negative",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: map, JMP, correct bounds",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 10),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, sizeof(struct test_val)),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_2, -128),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_10, -128),
|
|
|
+ BPF_JMP_IMM(BPF_JSGT, BPF_REG_2,
|
|
|
+ sizeof(struct test_val), 4),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_4, 0),
|
|
|
+ BPF_JMP_REG(BPF_JGE, BPF_REG_4, BPF_REG_2, 2),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .result = ACCEPT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: map, JMP, wrong max",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 10),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, sizeof(struct test_val)),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_2, -128),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_10, -128),
|
|
|
+ BPF_JMP_IMM(BPF_JSGT, BPF_REG_2,
|
|
|
+ sizeof(struct test_val) + 1, 4),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_4, 0),
|
|
|
+ BPF_JMP_REG(BPF_JGE, BPF_REG_4, BPF_REG_2, 2),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr = "invalid access to map value, value_size=48 off=0 size=49",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: map adjusted, JMP, correct bounds",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 11),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 20),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, sizeof(struct test_val)),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_2, -128),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_10, -128),
|
|
|
+ BPF_JMP_IMM(BPF_JSGT, BPF_REG_2,
|
|
|
+ sizeof(struct test_val) - 20, 4),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_4, 0),
|
|
|
+ BPF_JMP_REG(BPF_JGE, BPF_REG_4, BPF_REG_2, 2),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .result = ACCEPT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: map adjusted, JMP, wrong max",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
|
|
|
+ BPF_ST_MEM(BPF_DW, BPF_REG_2, 0, 0),
|
|
|
+ BPF_LD_MAP_FD(BPF_REG_1, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
|
|
|
+ BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 11),
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 20),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, sizeof(struct test_val)),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_2, -128),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_10, -128),
|
|
|
+ BPF_JMP_IMM(BPF_JSGT, BPF_REG_2,
|
|
|
+ sizeof(struct test_val) - 19, 4),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_4, 0),
|
|
|
+ BPF_JMP_REG(BPF_JGE, BPF_REG_4, BPF_REG_2, 2),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .fixup_map2 = { 3 },
|
|
|
+ .errstr = "R1 min value is outside of the array range",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: size > 0 not allowed on NULL",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_IMM(BPF_REG_1, 0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 0),
|
|
|
+ BPF_ALU64_IMM(BPF_AND, BPF_REG_2, 64),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_4, 0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_5, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_csum_diff),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .errstr = "R1 type=imm expected=fp",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_SCHED_CLS,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: size = 0 not allowed on != NULL",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -8),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 0),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_1, BPF_REG_2, 0),
|
|
|
+ BPF_ALU64_IMM(BPF_AND, BPF_REG_2, 8),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_4, 0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_5, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_csum_diff),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .errstr = "invalid stack type R1 off=-8 access_size=0",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_SCHED_CLS,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: 8 bytes leak",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -64),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -56),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -48),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -40),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -24),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -16),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -8),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 0),
|
|
|
+ BPF_ALU64_IMM(BPF_AND, BPF_REG_2, 63),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 1),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_10, -16),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .errstr = "invalid indirect read from stack off -64+32 size 64",
|
|
|
+ .result = REJECT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "helper access to variable memory: 8 bytes no leak (init memory)",
|
|
|
+ .insns = {
|
|
|
+ BPF_MOV64_REG(BPF_REG_1, BPF_REG_10),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_0, 0),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -64),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -56),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -48),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -40),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -32),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -24),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -16),
|
|
|
+ BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_0, -8),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, -64),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_2, 0),
|
|
|
+ BPF_ALU64_IMM(BPF_AND, BPF_REG_2, 32),
|
|
|
+ BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, 32),
|
|
|
+ BPF_MOV64_IMM(BPF_REG_3, 0),
|
|
|
+ BPF_EMIT_CALL(BPF_FUNC_probe_read),
|
|
|
+ BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_10, -16),
|
|
|
+ BPF_EXIT_INSN(),
|
|
|
+ },
|
|
|
+ .result = ACCEPT,
|
|
|
+ .prog_type = BPF_PROG_TYPE_TRACEPOINT,
|
|
|
+ },
|
|
|
};
|
|
|
|
|
|
static int probe_filter_length(const struct bpf_insn *fp)
|