tools/testing/selftests/bpf/progs/verifier_sock.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_sock.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/verifier_sock.c- Extension
.c- Size
- 29794 bytes
- Lines
- 1175
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vmlinux.hbpf/bpf_helpers.hbpf_misc.h
Detected Declarations
struct valfunction __msgfunction __retvalfunction __msgfunction __msgfunction __msgfunction __retvalfunction __retvalfunction __retvalfunction __retvalfunction __retvalfunction __msgfunction __retvalfunction __msgfunction __msgfunction __retvalfunction __retvalfunction __retvalfunction __msgfunction __msgfunction __msgfunction __retvalfunction __retvalfunction __msgfunction __retvalfunction __msgfunction __msgfunction __msgfunction __retvalfunction __msgfunction __retvalfunction __msgfunction __retvalfunction __msgfunction __msgfunction field_bpf_sk_release_sk_1function field_bpf_sk_release_sk_2function ctx_reuseport_array_key_flagsfunction reuseport_ctx_sockmap_key_flagsfunction reuseport_ctx_sockhash_key_flagsfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction skb_pull_data2function skb_pull_data1function __msg
Annotated Snippet
SEC("cgroup/sock_create")
__description("sk->src_port [word load]")
__failure __msg("invalid bpf_context access off=44 size=2")
__naked void sock_create_read_src_port(void)
{
asm volatile (" \
r6 = r1; \
r7 = *(u16*)(r6 + %[bpf_sock_src_port]); \
r0 = 1; \
exit; \
" :
: __imm_const(bpf_sock_src_port, offsetof(struct bpf_sock, src_port))
: __clobber_all);
}
__noinline
long skb_pull_data2(struct __sk_buff *sk, __u32 len)
{
return bpf_skb_pull_data(sk, len);
}
__noinline
long skb_pull_data1(struct __sk_buff *sk, __u32 len)
{
return skb_pull_data2(sk, len);
}
/* global function calls bpf_skb_pull_data(), which invalidates packet
* pointers established before global function call.
*/
SEC("tc")
__failure __msg("invalid mem access")
int invalidate_pkt_pointers_from_global_func(struct __sk_buff *sk)
{
int *p = (void *)(long)sk->data;
if ((void *)(p + 1) > (void *)(long)sk->data_end)
return TCX_DROP;
skb_pull_data1(sk, 0);
*p = 42; /* this is unsafe */
return TCX_PASS;
}
__noinline
long xdp_pull_data2(struct xdp_md *x, __u32 len)
{
return bpf_xdp_pull_data(x, len);
}
__noinline
long xdp_pull_data1(struct xdp_md *x, __u32 len)
{
return xdp_pull_data2(x, len);
}
/* global function calls bpf_xdp_pull_data(), which invalidates packet
* pointers established before global function call.
*/
SEC("xdp")
__failure __msg("invalid mem access")
int invalidate_xdp_pkt_pointers_from_global_func(struct xdp_md *x)
{
int *p = (void *)(long)x->data;
if ((void *)(p + 1) > (void *)(long)x->data_end)
return XDP_DROP;
xdp_pull_data1(x, 0);
*p = 42; /* this is unsafe */
return XDP_PASS;
}
/* XDP packet changing kfunc calls invalidate packet pointers */
SEC("xdp")
__failure __msg("invalid mem access")
int invalidate_xdp_pkt_pointers(struct xdp_md *x)
{
int *p = (void *)(long)x->data;
if ((void *)(p + 1) > (void *)(long)x->data_end)
return XDP_DROP;
bpf_xdp_pull_data(x, 0);
*p = 42; /* this is unsafe */
return XDP_PASS;
}
__noinline
int tail_call(struct __sk_buff *sk)
{
bpf_tail_call_static(sk, &jmp_table, 0);
return 0;
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`.
- Detected declarations: `struct val`, `function __msg`, `function __retval`, `function __msg`, `function __msg`, `function __msg`, `function __retval`, `function __retval`, `function __retval`, `function __retval`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.