tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/verifier_iterating_callbacks.c- Extension
.c- Size
- 15783 bytes
- Lines
- 787
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
bpf_misc.hbpf_experimental.h
Detected Declarations
struct vm_area_structstruct bpf_mapstruct buf_contextstruct num_contextstruct iter_limit_bug_ctxfunction unsafe_on_2nd_iter_cbfunction __msgfunction unsafe_on_zero_iter_cbfunction __msgfunction widening_cbfunction wideningfunction loop_detection_cbfunction __msgfunction oob_state_machinefunction for_each_map_elem_cbfunction __msgfunction ringbuf_drain_cbfunction __msgfunction find_vma_cbfunction __msgfunction iter_limit_cbfunction bpf_loop_iter_limit_okfunction __msgfunction iter_limit_level2a_cbfunction iter_limit_level2b_cbfunction iter_limit_level1_cbfunction __retvalfunction iter_limit_bug_cbfunction __msgfunction __msgfunction __retvalfunction __flagfunction __retvalfunction __retvalfunction __retvalfunction __retvalfunction __retvalfunction subprog_with_may_gotofunction __retvalfunction __retvalfunction loopfunction __retvalfunction __retvalfunction static_subprogfunction __retvalfunction __flagfunction __flagfunction __flag
Annotated Snippet
struct buf_context {
char *buf;
};
struct num_context {
__u64 i;
__u64 j;
};
__u8 choice_arr[2] = { 0, 1 };
static int unsafe_on_2nd_iter_cb(__u32 idx, struct buf_context *ctx)
{
if (idx == 0) {
ctx->buf = (char *)(0xDEAD);
return 0;
}
if (bpf_probe_read_user(ctx->buf, 8, (void *)(0xBADC0FFEE)))
return 1;
return 0;
}
SEC("?raw_tp")
__failure __msg("R1 type=scalar expected=fp")
int unsafe_on_2nd_iter(void *unused)
{
char buf[4];
struct buf_context loop_ctx = { .buf = buf };
bpf_loop(100, unsafe_on_2nd_iter_cb, &loop_ctx, 0);
return 0;
}
static int unsafe_on_zero_iter_cb(__u32 idx, struct num_context *ctx)
{
ctx->i = 0;
return 0;
}
SEC("?raw_tp")
__failure __msg("invalid access to map value, value_size=2 off=32 size=1")
int unsafe_on_zero_iter(void *unused)
{
struct num_context loop_ctx = { .i = 32 };
bpf_loop(100, unsafe_on_zero_iter_cb, &loop_ctx, 0);
return choice_arr[loop_ctx.i];
}
static int widening_cb(__u32 idx, struct num_context *ctx)
{
++ctx->i;
return 0;
}
SEC("?raw_tp")
__success
int widening(void *unused)
{
struct num_context loop_ctx = { .i = 0, .j = 1 };
bpf_loop(100, widening_cb, &loop_ctx, 0);
/* loop_ctx.j is not changed during callback iteration,
* verifier should not apply widening to it.
*/
return choice_arr[loop_ctx.j];
}
static int loop_detection_cb(__u32 idx, struct num_context *ctx)
{
for (;;) {}
return 0;
}
SEC("?raw_tp")
__failure __msg("infinite loop detected")
int loop_detection(void *unused)
{
struct num_context loop_ctx = { .i = 0 };
bpf_loop(100, loop_detection_cb, &loop_ctx, 0);
return 0;
}
static __always_inline __u64 oob_state_machine(struct num_context *ctx)
{
switch (ctx->i) {
case 0:
Annotation
- Immediate include surface: `bpf_misc.h`, `bpf_experimental.h`.
- Detected declarations: `struct vm_area_struct`, `struct bpf_map`, `struct buf_context`, `struct num_context`, `struct iter_limit_bug_ctx`, `function unsafe_on_2nd_iter_cb`, `function __msg`, `function unsafe_on_zero_iter_cb`, `function __msg`, `function widening_cb`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.