History

bpf: don't set id on after map lookup with ptr_to_map_val return

In the verifier there is no such semantics where registers with PTR_TO_MAP_VALUE type have an id assigned to them. This is only used in PTR_TO_MAP_VALUE_OR_NULL and later on nullified once the test against NULL has been pattern matched and type transformed into PTR_TO_MAP_VALUE.

Daniel Borkmann committed 8 years ago

Commit 4d31f301 parent 09625901 file · +6 −5Browse files

Unified · Split

kernel/bpf/verifier.c+6−5
@@ -2852,10 +2852,6 @@ static int check_helper_call(struct bpf_verifier_env *env, int func_id, int insn · 2851 unmodified lines
28522852 regs[BPF_REG_0].type = NOT_INIT;
28532853 } else if (fn->ret_type == RET_PTR_TO_MAP_VALUE_OR_NULL ||
28542854 fn->ret_type == RET_PTR_TO_MAP_VALUE) {
2855− if (fn->ret_type == RET_PTR_TO_MAP_VALUE)
2856− regs[BPF_REG_0].type = PTR_TO_MAP_VALUE;
2857− else
2858− regs[BPF_REG_0].type = PTR_TO_MAP_VALUE_OR_NULL;
28592855 /* There is no offset yet applied, variable or fixed */
28602856 mark_reg_known_zero(env, regs, BPF_REG_0);
28612857 /* remember map_ptr, so that check_map_access()
@@ -2868,7 +2864,12 @@ static int check_helper_call(struct bpf_verifier_env *env, int func_id, int insn · 6 unmodified lines
28682864 return -EINVAL;
28692865 }
28702866 regs[BPF_REG_0].map_ptr = meta.map_ptr;
2871− regs[BPF_REG_0].id = ++env->id_gen;
2867+ if (fn->ret_type == RET_PTR_TO_MAP_VALUE) {
2868+ regs[BPF_REG_0].type = PTR_TO_MAP_VALUE;
2869+ } else {
2870+ regs[BPF_REG_0].type = PTR_TO_MAP_VALUE_OR_NULL;
2871+ regs[BPF_REG_0].id = ++env->id_gen;
2872+ }
28722873 } else if (fn->ret_type == RET_PTR_TO_SOCKET_OR_NULL) {
28732874 int id = acquire_reference_state(env, insn_idx);
28742875 if (id < 0)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t