tools/testing/selftests/bpf/progs/task_kfunc_failure.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/task_kfunc_failure.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/task_kfunc_failure.c- Extension
.c- Size
- 9426 bytes
- Lines
- 381
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vmlinux.hbpf/bpf_tracing.hbpf/bpf_helpers.h../bpf_experimental.hbpf_misc.htask_kfunc_common.h
Detected Declarations
function TRACE_EVENTfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msgfunction __msg
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
#include <vmlinux.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_helpers.h>
#include "../bpf_experimental.h"
#include "bpf_misc.h"
#include "task_kfunc_common.h"
char _license[] SEC("license") = "GPL";
/* Prototype for all of the program trace events below:
*
* TRACE_EVENT(task_newtask,
* TP_PROTO(struct task_struct *p, u64 clone_flags)
*/
static struct __tasks_kfunc_map_value *insert_lookup_task(struct task_struct *task)
{
int status;
status = tasks_kfunc_map_insert(task);
if (status)
return NULL;
return tasks_kfunc_map_value_lookup(task);
}
SEC("tp_btf/task_newtask")
__failure __msg("Possibly NULL pointer passed to trusted R1")
int BPF_PROG(task_kfunc_acquire_untrusted, struct task_struct *task, u64 clone_flags)
{
struct task_struct *acquired;
struct __tasks_kfunc_map_value *v;
v = insert_lookup_task(task);
if (!v)
return 0;
/* Can't invoke bpf_task_acquire() on an untrusted pointer. */
acquired = bpf_task_acquire(v->task);
if (!acquired)
return 0;
bpf_task_release(acquired);
return 0;
}
SEC("tp_btf/task_newtask")
__failure __msg("R1 pointer type STRUCT task_struct must point")
int BPF_PROG(task_kfunc_acquire_fp, struct task_struct *task, u64 clone_flags)
{
struct task_struct *acquired, *stack_task = (struct task_struct *)&clone_flags;
/* Can't invoke bpf_task_acquire() on a random frame pointer. */
acquired = bpf_task_acquire((struct task_struct *)&stack_task);
if (!acquired)
return 0;
bpf_task_release(acquired);
return 0;
}
SEC("kretprobe/free_task")
__failure __msg("calling kernel function bpf_task_acquire is not allowed")
int BPF_PROG(task_kfunc_acquire_unsafe_kretprobe, struct task_struct *task, u64 clone_flags)
{
struct task_struct *acquired;
/* Can't call bpf_task_acquire() or bpf_task_release() in an untrusted prog. */
acquired = bpf_task_acquire(task);
if (!acquired)
return 0;
bpf_task_release(acquired);
return 0;
}
SEC("kretprobe/free_task")
__failure __msg("calling kernel function bpf_task_acquire is not allowed")
int BPF_PROG(task_kfunc_acquire_unsafe_kretprobe_rcu, struct task_struct *task, u64 clone_flags)
{
struct task_struct *acquired;
bpf_rcu_read_lock();
if (!task) {
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_tracing.h`, `bpf/bpf_helpers.h`, `../bpf_experimental.h`, `bpf_misc.h`, `task_kfunc_common.h`.
- Detected declarations: `function TRACE_EVENT`, `function __msg`, `function __msg`, `function __msg`, `function __msg`, `function __msg`, `function __msg`, `function __msg`, `function __msg`, `function __msg`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.