Skip to content

Commit 8de8d97

Browse files
committed
selftests/bpf: tests for __arg_untrusted void * global func params
Check usage of __arg_untrusted parameters of primitive type: - passing of {trusted, untrusted, map value, scalar value, values with variable offset} to untrusted `void *` or `char *` is ok; - varifier represents such parameters as rdonly_untrusted_mem(sz=0). Signed-off-by: Eduard Zingerman <[email protected]>
1 parent 4ed136d commit 8de8d97

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,45 @@ int untrusted_to_trusted(void *ctx)
245245
return subprog_untrusted2(bpf_get_current_task_btf());
246246
}
247247

248+
__weak int subprog_void_untrusted(void *p __arg_untrusted)
249+
{
250+
return *(int *)p;
251+
}
252+
253+
__weak int subprog_char_untrusted(char *p __arg_untrusted)
254+
{
255+
return *(int *)p;
256+
}
257+
258+
SEC("tp_btf/sys_enter")
259+
__success
260+
__log_level(2)
261+
__msg("r1 = {{.*}}; {{.*}}R1_w=trusted_ptr_task_struct()")
262+
__msg("Func#1 ('subprog_void_untrusted') is global and assumed valid.")
263+
__msg("Validating subprog_void_untrusted() func#1...")
264+
__msg(": R1=rdonly_untrusted_mem(sz=0)")
265+
int trusted_to_untrusted_mem(void *ctx)
266+
{
267+
return subprog_void_untrusted(bpf_get_current_task_btf());
268+
}
269+
270+
SEC("tp_btf/sys_enter")
271+
__success
272+
int anything_to_untrusted_mem(void *ctx)
273+
{
274+
/* untrusted to untrusted mem */
275+
subprog_void_untrusted(bpf_core_cast(0, struct task_struct));
276+
/* map value to untrusted mem */
277+
subprog_void_untrusted(mem);
278+
/* scalar to untrusted mem */
279+
subprog_void_untrusted(0);
280+
/* variable offset to untrusted mem (map) */
281+
subprog_void_untrusted((void *)mem + off);
282+
/* variable offset to untrusted mem (trusted) */
283+
subprog_void_untrusted(bpf_get_current_task_btf() + off);
284+
/* variable offset to untrusted char (map) */
285+
subprog_char_untrusted(mem + off);
286+
return 0;
287+
}
288+
248289
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)