tools/testing/selftests/bpf/progs/verifier_linked_scalars.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_linked_scalars.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/verifier_linked_scalars.c- Extension
.c- Size
- 17452 bytes
- Lines
- 714
- 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.hlimits.hbpf/bpf_helpers.hbpf_misc.h
Detected Declarations
function __msgfunction sync_linked_regsfunction scalars_negfunction scalars_neg_subfunction scalars_neg_alu32_addfunction scalars_neg_alu32_subfunction scalars_posfunction scalars_sub_neg_immfunction __msgfunction sync_linked_regsfunction scalars_sync_delta_overflow_large_rangefunction offsetfunction __msgfunction incorrectlyfunction sync_linked_regsfunction sync_linked_regsfunction regsafefunction alu32_negative_offsetfunction dummy_callsfunction __flagfunction sync_linked_regsfunction __msgfunction assign_scalar_id_before_movfunction __msgfunction regsafe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <linux/bpf.h>
#include <limits.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"
SEC("socket")
__description("scalars: find linked scalars")
__failure
__msg("math between fp pointer and 2147483647 is not allowed")
__naked void scalars(void)
{
asm volatile (" \
r0 = 0; \
r1 = 0x80000001 ll; \
r1 /= 1; \
r2 = r1; \
r4 = r1; \
w2 += 0x7FFFFFFF; \
w4 += 0; \
if r2 == 0 goto l0_%=; \
exit; \
l0_%=: \
r4 >>= 63; \
r3 = 1; \
r3 -= r4; \
r3 *= 0x7FFFFFFF; \
r3 += r10; \
*(u8*)(r3 - 1) = r0; \
exit; \
" ::: __clobber_all);
}
/*
* Test that sync_linked_regs() preserves register IDs.
*
* The sync_linked_regs() function copies bounds from known_reg to linked
* registers. When doing so, it must preserve each register's original id
* to allow subsequent syncs from the same source to work correctly.
*
*/
SEC("socket")
__success
__naked void sync_linked_regs_preserves_id(void)
{
asm volatile (" \
call %[bpf_get_prandom_u32]; \
r0 &= 0xff; /* r0 in [0, 255] */ \
r1 = r0; /* r0, r1 linked with id 1 */ \
r1 += 4; /* r1 has id=1 and off=4 in [4, 259] */ \
if r1 < 10 goto l0_%=; \
/* r1 in [10, 259], r0 synced to [6, 255] */ \
r2 = r0; /* r2 has id=1 and in [6, 255] */ \
if r1 < 14 goto l0_%=; \
/* r1 in [14, 259], r0 synced to [10, 255] */ \
if r0 >= 10 goto l0_%=; \
/* Never executed */ \
r0 /= 0; \
l0_%=: \
r0 = 0; \
exit; \
" :
: __imm(bpf_get_prandom_u32)
: __clobber_all);
}
SEC("socket")
__success
__naked void scalars_neg(void)
{
asm volatile (" \
call %[bpf_get_prandom_u32]; \
r0 &= 0xff; \
r1 = r0; \
r1 += -4; \
if r1 s< 0 goto l0_%=; \
if r0 != 0 goto l0_%=; \
r0 /= 0; \
l0_%=: \
r0 = 0; \
exit; \
" :
: __imm(bpf_get_prandom_u32)
: __clobber_all);
}
/* Same test but using BPF_SUB instead of BPF_ADD with negative immediate */
SEC("socket")
__success
Annotation
- Immediate include surface: `linux/bpf.h`, `limits.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`.
- Detected declarations: `function __msg`, `function sync_linked_regs`, `function scalars_neg`, `function scalars_neg_sub`, `function scalars_neg_alu32_add`, `function scalars_neg_alu32_sub`, `function scalars_pos`, `function scalars_sub_neg_imm`, `function __msg`, `function sync_linked_regs`.
- 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.