tools/testing/selftests/bpf/progs/uptr_failure.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/uptr_failure.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/uptr_failure.c- Extension
.c- Size
- 2017 bytes
- Lines
- 106
- 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
vmlinux.hbpf/bpf_helpers.hbpf_experimental.hbpf_misc.huptr_test_common.h
Detected Declarations
function __msgfunction __msgfunction __msgfunction __msgfunction __msg
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include "bpf_experimental.h"
#include "bpf_misc.h"
#include "uptr_test_common.h"
struct {
__uint(type, BPF_MAP_TYPE_TASK_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, struct value_type);
} datamap SEC(".maps");
SEC("?syscall")
__failure __msg("store to uptr disallowed")
int uptr_write(const void *ctx)
{
struct task_struct *task;
struct value_type *v;
task = bpf_get_current_task_btf();
v = bpf_task_storage_get(&datamap, task, 0,
BPF_LOCAL_STORAGE_GET_F_CREATE);
if (!v)
return 0;
v->udata = NULL;
return 0;
}
SEC("?syscall")
__failure __msg("store to uptr disallowed")
int uptr_write_nested(const void *ctx)
{
struct task_struct *task;
struct value_type *v;
task = bpf_get_current_task_btf();
v = bpf_task_storage_get(&datamap, task, 0,
BPF_LOCAL_STORAGE_GET_F_CREATE);
if (!v)
return 0;
v->nested.udata = NULL;
return 0;
}
SEC("?syscall")
__failure __msg("R1 invalid mem access 'mem_or_null'")
int uptr_no_null_check(const void *ctx)
{
struct task_struct *task;
struct value_type *v;
task = bpf_get_current_task_btf();
v = bpf_task_storage_get(&datamap, task, 0,
BPF_LOCAL_STORAGE_GET_F_CREATE);
if (!v)
return 0;
v->udata->result = 0;
return 0;
}
SEC("?syscall")
__failure __msg("doesn't point to kptr")
int uptr_kptr_xchg(const void *ctx)
{
struct task_struct *task;
struct value_type *v;
task = bpf_get_current_task_btf();
v = bpf_task_storage_get(&datamap, task, 0,
BPF_LOCAL_STORAGE_GET_F_CREATE);
if (!v)
return 0;
bpf_kptr_xchg(&v->udata, NULL);
return 0;
}
SEC("?syscall")
__failure __msg("invalid mem access 'scalar'")
int uptr_obj_new(const void *ctx)
{
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_helpers.h`, `bpf_experimental.h`, `bpf_misc.h`, `uptr_test_common.h`.
- Detected declarations: `function __msg`, `function __msg`, `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.