Skip to content

Commit b1a7288

Browse files
committed
bpf, selftests: Add test case trying to taint map value pointer
Add a test case which tries to taint map value pointer arithmetic into a unknown scalar with subsequent export through the map. Before fix: # ./test_verifier 1186 torvalds#1186/u map access: trying to leak tained dst reg FAIL Unexpected success to load! verification time 24 usec stack depth 8 processed 15 insns (limit 1000000) max_states_per_insn 0 total_states 1 peak_states 1 mark_read 1 torvalds#1186/p map access: trying to leak tained dst reg FAIL Unexpected success to load! verification time 8 usec stack depth 8 processed 15 insns (limit 1000000) max_states_per_insn 0 total_states 1 peak_states 1 mark_read 1 Summary: 0 PASSED, 0 SKIPPED, 2 FAILED After fix: # ./test_verifier 1186 torvalds#1186/u map access: trying to leak tained dst reg OK torvalds#1186/p map access: trying to leak tained dst reg OK Summary: 2 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: John Fastabend <[email protected]> Acked-by: Alexei Starovoitov <[email protected]>
1 parent e572ff8 commit b1a7288

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tools/testing/selftests/bpf/verifier/value_ptr_arith.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,29 @@
10771077
.errstr = "R0 invalid mem access 'inv'",
10781078
.errstr_unpriv = "R0 pointer -= pointer prohibited",
10791079
},
1080+
{
1081+
"map access: trying to leak tained dst reg",
1082+
.insns = {
1083+
BPF_MOV64_IMM(BPF_REG_0, 0),
1084+
BPF_ST_MEM(BPF_DW, BPF_REG_10, -8, 0),
1085+
BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
1086+
BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -8),
1087+
BPF_LD_MAP_FD(BPF_REG_1, 0),
1088+
BPF_RAW_INSN(BPF_JMP | BPF_CALL, 0, 0, 0, BPF_FUNC_map_lookup_elem),
1089+
BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1),
1090+
BPF_EXIT_INSN(),
1091+
BPF_MOV64_REG(BPF_REG_2, BPF_REG_0),
1092+
BPF_MOV32_IMM(BPF_REG_1, 0xFFFFFFFF),
1093+
BPF_MOV32_REG(BPF_REG_1, BPF_REG_1),
1094+
BPF_ALU64_REG(BPF_SUB, BPF_REG_2, BPF_REG_1),
1095+
BPF_STX_MEM(BPF_DW, BPF_REG_0, BPF_REG_2, 0),
1096+
BPF_MOV64_IMM(BPF_REG_0, 0),
1097+
BPF_EXIT_INSN(),
1098+
},
1099+
.fixup_map_array_48b = { 4 },
1100+
.result = REJECT,
1101+
.errstr = "math between map_value pointer and 4294967295 is not allowed",
1102+
},
10801103
{
10811104
"32bit pkt_ptr -= scalar",
10821105
.insns = {

0 commit comments

Comments
 (0)