Skip to content

Commit 87680ac

Browse files
author
Alexei Starovoitov
committed
Merge branch 'fix-for-check_func_arg_reg_off'
Kumar Kartikeya Dwivedi says: ==================== Fix for check_func_arg_reg_off Remove a leftover hunk in check_func_arg_reg_off that incorrectly bypasses reg->off == 0 requirement for release kfuncs and helpers. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents fb30159 + fbc5bc4 commit 87680ac

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

kernel/bpf/verifier.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7973,17 +7973,6 @@ int check_func_arg_reg_off(struct bpf_verifier_env *env,
79737973
if (arg_type_is_dynptr(arg_type) && type == PTR_TO_STACK)
79747974
return 0;
79757975

7976-
if ((type_is_ptr_alloc_obj(type) || type_is_non_owning_ref(type)) && reg->off) {
7977-
if (reg_find_field_offset(reg, reg->off, BPF_GRAPH_NODE_OR_ROOT))
7978-
return __check_ptr_off_reg(env, reg, regno, true);
7979-
7980-
verbose(env, "R%d must have zero offset when passed to release func\n",
7981-
regno);
7982-
verbose(env, "No graph node or root found at R%d type:%s off:%d\n", regno,
7983-
btf_type_name(reg->btf, reg->btf_id), reg->off);
7984-
return -EINVAL;
7985-
}
7986-
79877976
/* Doing check_ptr_off_reg check for the offset will catch this
79887977
* because fixed_off_ok is false, but checking here allows us
79897978
* to give the user a better error message.

tools/testing/selftests/bpf/progs/local_kptr_stash_fail.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,24 @@ long stash_rb_nodes(void *ctx)
6262
return 0;
6363
}
6464

65+
SEC("tc")
66+
__failure __msg("R1 must have zero offset when passed to release func")
67+
long drop_rb_node_off(void *ctx)
68+
{
69+
struct map_value *mapval;
70+
struct node_data *res;
71+
int idx = 0;
72+
73+
mapval = bpf_map_lookup_elem(&some_nodes, &idx);
74+
if (!mapval)
75+
return 1;
76+
77+
res = bpf_obj_new(typeof(*res));
78+
if (!res)
79+
return 1;
80+
/* Try releasing with graph node offset */
81+
bpf_obj_drop(&res->node);
82+
return 0;
83+
}
84+
6585
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)