tools/testing/selftests/bpf/progs/verifier_global_ptr_args.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_global_ptr_args.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/verifier_global_ptr_args.c- Extension
.c- Size
- 8553 bytes
- Lines
- 330
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vmlinux.hbpf/bpf_helpers.hbpf/bpf_tracing.hbpf/bpf_core_read.hbpf_misc.hxdp_metadata.hbpf_kfuncs.h
Detected Declarations
struct task_struct___localstruct local_type_wont_be_acceptedfunction subprog_trusted_task_nullablefunction subprog_trusted_task_nullable_extra_layerfunction __log_levelfunction subprog_trusted_task_nonnullfunction __log_levelfunction __log_levelfunction __log_levelfunction subprog_nullable_task_flavorfunction __log_levelfunction subprog_nonnull_task_flavorfunction __log_levelfunction subprog_trusted_destroyfunction __log_levelfunction subprog_trusted_acq_relfunction __log_levelfunction subprog_untrusted_bad_tagsfunction __msgfunction subprog_untrusted_bad_typefunction __msgfunction subprog_untrustedfunction trusted_to_untrustedfunction anything_to_untrustedfunction subprog_untrusted2function __msgfunction subprog_void_untrustedfunction subprog_char_untrustedfunction subprog_enum_untrustedfunction trusted_to_untrusted_memfunction subprog_write_mem_argfunction __msgfunction anything_to_untrusted_mem
Annotated Snippet
struct task_struct___local {} __attribute__((preserve_access_index));
__weak int subprog_nullable_task_flavor(
struct task_struct___local *task __arg_trusted __arg_nullable)
{
char buf[16];
if (!task)
return 0;
return bpf_copy_from_user_task(&buf, sizeof(buf), NULL, (void *)task, 0);
}
SEC("?uprobe.s")
__success __log_level(2)
__msg("Validating subprog_nullable_task_flavor() func#1...")
__msg(": R1=trusted_ptr_or_null_task_struct(")
int flavor_ptr_nullable(void *ctx)
{
struct task_struct___local *t = (void *)bpf_get_current_task_btf();
return subprog_nullable_task_flavor(t);
}
__weak int subprog_nonnull_task_flavor(struct task_struct___local *task __arg_trusted)
{
char buf[16];
return bpf_copy_from_user_task(&buf, sizeof(buf), NULL, (void *)task, 0);
}
SEC("?uprobe.s")
__success __log_level(2)
__msg("Validating subprog_nonnull_task_flavor() func#1...")
__msg(": R1=trusted_ptr_task_struct(")
int flavor_ptr_nonnull(void *ctx)
{
struct task_struct *t = bpf_get_current_task_btf();
return subprog_nonnull_task_flavor((void *)t);
}
__weak int subprog_trusted_destroy(struct task_struct *task __arg_trusted)
{
bpf_task_release(task); /* should be rejected */
return 0;
}
SEC("?tp_btf/task_newtask")
__failure __log_level(2)
__msg("release kfunc bpf_task_release expects referenced PTR_TO_BTF_ID passed to R1")
int BPF_PROG(trusted_destroy_fail, struct task_struct *task, u64 clone_flags)
{
return subprog_trusted_destroy(task);
}
__weak int subprog_trusted_acq_rel(struct task_struct *task __arg_trusted)
{
struct task_struct *owned;
owned = bpf_task_acquire(task);
if (!owned)
return 0;
bpf_task_release(owned); /* this one is OK, we acquired it locally */
return 0;
}
SEC("?tp_btf/task_newtask")
__success __log_level(2)
int BPF_PROG(trusted_acq_rel, struct task_struct *task, u64 clone_flags)
{
return subprog_trusted_acq_rel(task);
}
__weak int subprog_untrusted_bad_tags(struct task_struct *task __arg_untrusted __arg_nullable)
{
return task->pid;
}
SEC("tp_btf/sys_enter")
__failure
__msg("arg#0 untrusted cannot be combined with any other tags")
int untrusted_bad_tags(void *ctx)
{
return subprog_untrusted_bad_tags(0);
}
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`, `bpf/bpf_core_read.h`, `bpf_misc.h`, `xdp_metadata.h`, `bpf_kfuncs.h`.
- Detected declarations: `struct task_struct___local`, `struct local_type_wont_be_accepted`, `function subprog_trusted_task_nullable`, `function subprog_trusted_task_nullable_extra_layer`, `function __log_level`, `function subprog_trusted_task_nonnull`, `function __log_level`, `function __log_level`, `function __log_level`, `function subprog_nullable_task_flavor`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.