tools/testing/selftests/bpf/progs/verifier_stack_arg.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_stack_arg.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/verifier_stack_arg.c- Extension
.c- Size
- 9453 bytes
- Lines
- 448
- 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 subprog_6argsfunction subprog_7argsfunction subprog_deref_arg6function __retvalfunction __retvalfunction __msgfunction __msgfunction __log_levelfunction __msgfunction __msgfunction __msgfunction __msgfunction __retvalfunction __msgfunction __msgfunction __msgfunction dummy_test
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 1);
__type(key, long long);
__type(value, long long);
} map_hash_8b SEC(".maps");
#if (defined(__TARGET_ARCH_x86) || defined(__TARGET_ARCH_arm64)) && \
defined(__BPF_FEATURE_STACK_ARGUMENT)
__noinline __used
static int subprog_6args(int a, int b, int c, int d, int e, int f)
{
return a + b + c + d + e + f;
}
__noinline __used
static int subprog_7args(int a, int b, int c, int d, int e, int f, int g)
{
return a + b + c + d + e + f + g;
}
__noinline __used
static long subprog_deref_arg6(long a, long b, long c, long d, long e, long *f)
{
return *f;
}
SEC("tc")
__description("stack_arg: subprog with 6 args")
__success __retval(21)
__naked void stack_arg_6args(void)
{
asm volatile (
"r1 = 1;"
"r2 = 2;"
"r3 = 3;"
"r4 = 4;"
"r5 = 5;"
"*(u64 *)(r11 - 8) = 6;"
"call subprog_6args;"
"exit;"
::: __clobber_all
);
}
SEC("tc")
__description("stack_arg: two subprogs with >5 args")
__success __retval(90)
__naked void stack_arg_two_subprogs(void)
{
asm volatile (
"r1 = 1;"
"r2 = 2;"
"r3 = 3;"
"r4 = 4;"
"r5 = 5;"
"*(u64 *)(r11 - 8) = 10;"
"call subprog_6args;"
"r6 = r0;"
"r1 = 1;"
"r2 = 2;"
"r3 = 3;"
"r4 = 4;"
"r5 = 5;"
"*(u64 *)(r11 - 16) = 30;"
"*(u64 *)(r11 - 8) = 20;"
"call subprog_7args;"
"r0 += r6;"
"exit;"
::: __clobber_all
);
}
SEC("tc")
__description("stack_arg: read from uninitialized stack arg slot")
__failure
__msg("invalid read from stack arg off 8 depth 0")
__naked void stack_arg_read_uninitialized(void)
{
asm volatile (
"r0 = *(u64 *)(r11 + 8);"
"r0 = 0;"
Annotation
- Immediate include surface: `linux/bpf.h`, `bpf/bpf_helpers.h`, `bpf_misc.h`.
- Detected declarations: `function subprog_6args`, `function subprog_7args`, `function subprog_deref_arg6`, `function __retval`, `function __retval`, `function __msg`, `function __msg`, `function __log_level`, `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.