tools/testing/selftests/bpf/progs/verifier_unpriv.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/verifier_unpriv.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/verifier_unpriv.c- Extension
.c- Size
- 23973 bytes
- Lines
- 980
- 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.h../../../include/linux/filter.hbpf_misc.h
Detected Declarations
function dummy_prog_42_socketfunction dummy_prog_24_socketfunction dummy_prog_loop1_socketfunction __msg_unprivfunction __retvalfunction __msgfunction __msg_unprivfunction __msg_unprivfunction __msg_unprivfunction check_that_printk_is_disallowedfunction __msg_unprivfunction __msg_unprivfunction __msg_unprivfunction __msg_unprivfunction __msgfunction __msgfunction __retvalfunction __retvalfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction different_pointers_stx_leak_sockfunction __msgfunction stx_sock_and_ctx_writefunction __msg_unprivfunction __retvalfunction __msg_unprivfunction __msg_unprivfunction __retvalfunction __msg_unprivfunction __msgfunction __msgfunction __msg_unprivfunction __msg_unprivfunction __msg_unprivfunction __msg_unprivfunction __retvalfunction __retvalfunction __retvalfunction __retvalfunction __retvalfunction __retval
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Converted from tools/testing/selftests/bpf/verifier/unpriv.c */
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include "../../../include/linux/filter.h"
#include "bpf_misc.h"
#define BPF_SK_LOOKUP(func) \
/* struct bpf_sock_tuple tuple = {} */ \
"r2 = 0;" \
"*(u32*)(r10 - 8) = r2;" \
"*(u64*)(r10 - 16) = r2;" \
"*(u64*)(r10 - 24) = r2;" \
"*(u64*)(r10 - 32) = r2;" \
"*(u64*)(r10 - 40) = r2;" \
"*(u64*)(r10 - 48) = r2;" \
/* sk = func(ctx, &tuple, sizeof tuple, 0, 0) */ \
"r2 = r10;" \
"r2 += -48;" \
"r3 = %[sizeof_bpf_sock_tuple];"\
"r4 = 0;" \
"r5 = 0;" \
"call %[" #func "];"
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 1);
__type(key, long long);
__type(value, long long);
} map_hash_8b SEC(".maps");
void dummy_prog_42_socket(void);
void dummy_prog_24_socket(void);
void dummy_prog_loop1_socket(void);
struct {
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
__uint(max_entries, 4);
__uint(key_size, sizeof(int));
__array(values, void (void));
} map_prog1_socket SEC(".maps") = {
.values = {
[0] = (void *)&dummy_prog_42_socket,
[1] = (void *)&dummy_prog_loop1_socket,
[2] = (void *)&dummy_prog_24_socket,
},
};
SEC("socket")
__auxiliary __auxiliary_unpriv
__naked void dummy_prog_42_socket(void)
{
asm volatile ("r0 = 42; exit;");
}
SEC("socket")
__auxiliary __auxiliary_unpriv
__naked void dummy_prog_24_socket(void)
{
asm volatile ("r0 = 24; exit;");
}
SEC("socket")
__auxiliary __auxiliary_unpriv
__naked void dummy_prog_loop1_socket(void)
{
asm volatile (" \
r3 = 1; \
r2 = %[map_prog1_socket] ll; \
call %[bpf_tail_call]; \
r0 = 41; \
exit; \
" :
: __imm(bpf_tail_call),
__imm_addr(map_prog1_socket)
: __clobber_all);
}
SEC("socket")
__description("unpriv: return pointer")
__success __failure_unpriv __msg_unpriv("R0 leaks addr")
__retval(POINTER_VALUE)
__naked void unpriv_return_pointer(void)
{
asm volatile (" \
r0 = r10; \
exit; \
" ::: __clobber_all);
}
Annotation
- Immediate include surface: `linux/bpf.h`, `bpf/bpf_helpers.h`, `../../../include/linux/filter.h`, `bpf_misc.h`.
- Detected declarations: `function dummy_prog_42_socket`, `function dummy_prog_24_socket`, `function dummy_prog_loop1_socket`, `function __msg_unpriv`, `function __retval`, `function __msg`, `function __msg_unpriv`, `function __msg_unpriv`, `function __msg_unpriv`, `function check_that_printk_is_disallowed`.
- 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.