tools/testing/selftests/bpf/progs/verifier_ctx.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_ctx.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/verifier_ctx.c- Extension
.c- Size
- 20874 bytes
- Lines
- 863
- 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
vmlinux.hbpf/bpf_helpers.hbpf_misc.h../test_kmods/bpf_testmod_kfunc.h
Detected Declarations
function __msgfunction __msgfunction __retvalfunction __msgfunction __msgfunction ctx_pointer_to_helper_3function or_null_check_1_ctxfunction or_null_check_2_nullfunction __msgfunction __msgfunction null_check_5_null_connectfunction null_check_6_null_bindfunction null_check_7_ctx_bindfunction __msgfunction syscall_ctx_fixed_off_writefunction syscall_ctx_fixed_off_readfunction syscall_ctx_unaligned_fixed_off_readfunction syscall_ctx_unaligned_fixed_off_writefunction syscall_ctx_var_off_readfunction syscall_ctx_var_off_writefunction syscall_ctx_unaligned_var_off_readfunction syscall_ctx_unaligned_var_off_writefunction __msgfunction __msgfunction __msgfunction __msgfunction syscall_ctx_helper_fixed_off_readfunction syscall_ctx_helper_fixed_off_writefunction syscall_ctx_helper_unaligned_fixed_off_readfunction syscall_ctx_helper_unaligned_fixed_off_writefunction syscall_ctx_helper_var_off_readfunction syscall_ctx_helper_var_off_writefunction syscall_ctx_helper_unaligned_var_off_readfunction syscall_ctx_helper_unaligned_var_off_writefunction __msgfunction __msgfunction __msgfunction __msgfunction syscall_ctx_helper_zero_sized_readfunction syscall_ctx_helper_zero_sized_writefunction syscall_ctx_kfunc_fixed_offfunction syscall_ctx_kfunc_var_offfunction syscall_ctx_kfunc_unaligned_fixed_offfunction syscall_ctx_kfunc_unaligned_var_offfunction __msgfunction __msgfunction syscall_ctx_kfunc_zero_sized
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Converted from tools/testing/selftests/bpf/verifier/ctx.c */
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"
#include "../test_kmods/bpf_testmod_kfunc.h"
static const char ctx_strncmp_target[] = "ctx";
static const char ctx_snprintf_fmt[] = "";
SEC("tc")
__description("context stores via BPF_ATOMIC")
__failure __msg("BPF_ATOMIC stores into R1 ctx is not allowed")
__naked void context_stores_via_bpf_atomic(void)
{
asm volatile (" \
r0 = 0; \
lock *(u32 *)(r1 + %[__sk_buff_mark]) += w0; \
exit; \
" :
: __imm_const(__sk_buff_mark, offsetof(struct __sk_buff, mark))
: __clobber_all);
}
SEC("tc")
__description("arithmetic ops make PTR_TO_CTX unusable")
__failure __msg("dereference of modified ctx ptr")
__naked void make_ptr_to_ctx_unusable(void)
{
asm volatile (" \
r1 += %[__imm_0]; \
r0 = *(u32*)(r1 + %[__sk_buff_mark]); \
exit; \
" :
: __imm_const(__imm_0,
offsetof(struct __sk_buff, data) - offsetof(struct __sk_buff, mark)),
__imm_const(__sk_buff_mark, offsetof(struct __sk_buff, mark))
: __clobber_all);
}
SEC("tc")
__description("pass unmodified ctx pointer to helper")
__success __retval(0)
__naked void unmodified_ctx_pointer_to_helper(void)
{
asm volatile (" \
r2 = 0; \
call %[bpf_csum_update]; \
r0 = 0; \
exit; \
" :
: __imm(bpf_csum_update)
: __clobber_all);
}
SEC("tc")
__description("pass modified ctx pointer to helper, 1")
__failure __msg("negative offset ctx ptr R1 off=-612 disallowed")
__naked void ctx_pointer_to_helper_1(void)
{
asm volatile (" \
r1 += -612; \
r2 = 0; \
call %[bpf_csum_update]; \
r0 = 0; \
exit; \
" :
: __imm(bpf_csum_update)
: __clobber_all);
}
SEC("socket")
__description("pass modified ctx pointer to helper, 2")
__failure __msg("negative offset ctx ptr R1 off=-612 disallowed")
__naked void ctx_pointer_to_helper_2(void)
{
asm volatile (" \
r1 += -612; \
call %[bpf_get_socket_cookie]; \
r0 = 0; \
exit; \
" :
: __imm(bpf_get_socket_cookie)
: __clobber_all);
}
SEC("tc")
__description("pass modified ctx pointer to helper, 3")
__failure __msg("variable ctx access var_off=(0x0; 0x4)")
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`, `../test_kmods/bpf_testmod_kfunc.h`.
- Detected declarations: `function __msg`, `function __msg`, `function __retval`, `function __msg`, `function __msg`, `function ctx_pointer_to_helper_3`, `function or_null_check_1_ctx`, `function or_null_check_2_null`, `function __msg`, `function __msg`.
- 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.