tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c- Extension
.c- Size
- 49723 bytes
- Lines
- 1723
- 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
linux/bpf.hbpf/bpf_helpers.hbpf_misc.h
Detected Declarations
function __msgfunction __msgfunction __retvalfunction __msgfunction __msgfunction __retvalfunction __msgfunction __retvalfunction __msgfunction __msgfunction __retvalfunction __retvalfunction __retvalfunction __msgfunction __msgfunction __retvalfunction __retvalfunction __retvalfunction __msgfunction __msgfunction __retvalfunction __msgfunction __retvalfunction __msgfunction __msgfunction __retvalfunction __retvalfunction __retvalfunction __msgfunction __msgfunction __retvalfunction __msgfunction __retvalfunction __msgfunction __msgfunction __retvalfunction __msgfunction __retvalfunction __msgfunction __msgfunction __retvalfunction __retvalfunction __retvalfunction __msgfunction __msgfunction __retvalfunction __msgfunction __retval
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Converted from tools/testing/selftests/bpf/verifier/xdp_direct_packet_access.c */
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"
SEC("xdp")
__description("XDP pkt read, pkt_end mangling, bad access 1")
__failure __msg("R3 pointer arithmetic on pkt_end")
__naked void end_mangling_bad_access_1(void)
{
asm volatile (" \
r2 = *(u32*)(r1 + %[xdp_md_data]); \
r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
r1 = r2; \
r1 += 8; \
r3 += 8; \
if r1 > r3 goto l0_%=; \
r0 = *(u64*)(r1 - 8); \
l0_%=: r0 = 0; \
exit; \
" :
: __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
__imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
: __clobber_all);
}
SEC("xdp")
__description("XDP pkt read, pkt_end mangling, bad access 2")
__failure __msg("R3 pointer arithmetic on pkt_end")
__naked void end_mangling_bad_access_2(void)
{
asm volatile (" \
r2 = *(u32*)(r1 + %[xdp_md_data]); \
r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
r1 = r2; \
r1 += 8; \
r3 -= 8; \
if r1 > r3 goto l0_%=; \
r0 = *(u64*)(r1 - 8); \
l0_%=: r0 = 0; \
exit; \
" :
: __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
__imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
: __clobber_all);
}
SEC("xdp")
__description("XDP pkt read, pkt_data' > pkt_end, corner case, good access")
__success __retval(0) __flag(BPF_F_ANY_ALIGNMENT)
__naked void end_corner_case_good_access_1(void)
{
asm volatile (" \
r2 = *(u32*)(r1 + %[xdp_md_data]); \
r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
r1 = r2; \
r1 += 8; \
if r1 > r3 goto l0_%=; \
r0 = *(u64*)(r1 - 8); \
l0_%=: r0 = 0; \
exit; \
" :
: __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
__imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
: __clobber_all);
}
SEC("xdp")
__description("XDP pkt read, pkt_data' > pkt_end, bad access 1")
__failure __msg("R1 {{min|max}} value is outside of the allowed memory range")
__flag(BPF_F_ANY_ALIGNMENT)
__naked void pkt_end_bad_access_1_1(void)
{
asm volatile (" \
r2 = *(u32*)(r1 + %[xdp_md_data]); \
r3 = *(u32*)(r1 + %[xdp_md_data_end]); \
r1 = r2; \
r1 += 8; \
if r1 > r3 goto l0_%=; \
r0 = *(u64*)(r1 - 4); \
l0_%=: r0 = 0; \
exit; \
" :
: __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
__imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end))
: __clobber_all);
}
Annotation
- Immediate include surface: `linux/bpf.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`.
- Detected declarations: `function __msg`, `function __msg`, `function __retval`, `function __msg`, `function __msg`, `function __retval`, `function __msg`, `function __retval`, `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.