tools/testing/selftests/bpf/progs/verifier_set_retval.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_set_retval.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/verifier_set_retval.c- Extension
.c- Size
- 2612 bytes
- Lines
- 108
- 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/bpf_tracing.hbpf_misc.h
Detected Declarations
function BPF_PROGfunction BPF_PROGfunction __msgfunction __msgfunction cgroup_dev_set_retval_0function cgroup_dev_set_retval_neg_maxerrnofunction __msgfunction __msgfunction __msg
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include "bpf_misc.h"
SEC("lsm_cgroup/socket_create")
__description("lsm_cgroup bpf_set_retval success")
__success
int BPF_PROG(lsm_cgroup_set_retval_zero_valid, int family, int type, int protocol, int kern)
{
bpf_set_retval(0);
return 0;
}
SEC("lsm_cgroup/socket_create")
__description("lsm_cgroup bpf_set_retval valid errno")
__success
int BPF_PROG(lsm_cgroup_set_retval_negative_valid, int family, int type, int protocol, int kern)
{
bpf_set_retval(-12);
return 0;
}
SEC("lsm_cgroup/socket_create")
__description("lsm_cgroup bpf_set_retval invalid negative value")
__failure __msg("should have been in [-4095, 0]")
int BPF_PROG(lsm_cgroup_set_retval_negative_invalid, int family, int type, int protocol, int kern)
{
bpf_set_retval(-4096);
return 0;
}
SEC("lsm_cgroup/socket_create")
__description("lsm_cgroup bpf_set_retval invalid positive value")
__failure __msg("should have been in [-4095, 0]")
int BPF_PROG(lsm_cgroup_set_retval_positive_invalid, int family, int type, int protocol, int kern)
{
bpf_set_retval(1);
return 0;
}
SEC("cgroup/dev")
__description("cgroup_device bpf_set_retval success")
__success
int cgroup_dev_set_retval_0(struct bpf_cgroup_dev_ctx *ctx)
{
bpf_set_retval(0);
return 1;
}
SEC("cgroup/dev")
__description("cgroup_device bpf_set_retval valid errno")
__success
int cgroup_dev_set_retval_neg_maxerrno(struct bpf_cgroup_dev_ctx *ctx)
{
bpf_set_retval(-4095);
return 1;
}
SEC("cgroup/dev")
__description("cgroup_device bpf_set_retval invalid positive value")
__failure __msg("should have been in [-4095, 0]")
int cgroup_dev_set_retval_1(struct bpf_cgroup_dev_ctx *ctx)
{
bpf_set_retval(1);
return 1;
}
SEC("cgroup/dev")
__description("cgroup_device bpf_set_retval invalid negative value")
__failure __msg("should have been in [-4095, 0]")
int cgroup_dev_set_retval_neg_4096(struct bpf_cgroup_dev_ctx *ctx)
{
bpf_set_retval(-4096);
return 1;
}
SEC("cgroup/dev")
__description("bpf_set_retval bounds check survives state pruning")
__failure __msg("should have been in [-4095, 0]")
__naked int cgroup_dev_set_retval_pruning_bypass(struct bpf_cgroup_dev_ctx *ctx)
{
asm volatile (
"call %[bpf_get_prandom_u32];"
"if r0 != 0 goto 1f;"
"r0 = r0;"
"r0 = r0;"
"r0 = r0;"
Annotation
- Immediate include surface: `linux/bpf.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`, `bpf_misc.h`.
- Detected declarations: `function BPF_PROG`, `function BPF_PROG`, `function __msg`, `function __msg`, `function cgroup_dev_set_retval_0`, `function cgroup_dev_set_retval_neg_maxerrno`, `function __msg`, `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.