Skip to content

Commit fbc5bc4

Browse files
kkdwivediAlexei Starovoitov
authored andcommitted
selftests/bpf: Add test for bpf_obj_drop with bad reg->off
Add a selftest for the fix provided in the previous commit. Without the fix, the selftest passes the verifier while it should fail. The special logic for detecting graph root or node for reg->off and bypassing reg->off == 0 guarantee for release helpers/kfuncs has been dropped. Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 6785b2e commit fbc5bc4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

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)