tools/testing/selftests/bpf/progs/security_bpf_map.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/security_bpf_map.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/security_bpf_map.c- Extension
.c- Size
- 1397 bytes
- Lines
- 70
- 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_tracing.hbpf/bpf_helpers.h
Detected Declarations
struct mapfunction BPF_PROGfunction BPF_PROG
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
#include "vmlinux.h"
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_helpers.h>
char _license[] SEC("license") = "GPL";
#define EPERM 1 /* Operation not permitted */
/* From include/linux/mm.h. */
#define FMODE_WRITE 0x2
struct map;
struct {
__uint(type, BPF_MAP_TYPE_ARRAY);
__type(key, __u32);
__type(value, __u32);
__uint(max_entries, 1);
} prot_status_map SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, __u32);
__type(value, __u32);
__uint(max_entries, 3);
} prot_map SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, __u32);
__type(value, __u32);
__uint(max_entries, 3);
} not_prot_map SEC(".maps");
SEC("fmod_ret/security_bpf_map")
int BPF_PROG(fmod_bpf_map, struct bpf_map *map, int fmode)
{
__u32 key = 0;
__u32 *status_ptr = bpf_map_lookup_elem(&prot_status_map, &key);
if (!status_ptr || !*status_ptr)
return 0;
if (map == &prot_map) {
/* Allow read-only access */
if (fmode & FMODE_WRITE)
return -EPERM;
}
return 0;
}
/*
* This program keeps references to maps. This is needed to prevent
* optimizing them out.
*/
SEC("fentry/bpf_fentry_test1")
int BPF_PROG(fentry_dummy1, int a)
{
__u32 key = 0;
__u32 val1 = a;
__u32 val2 = a + 1;
bpf_map_update_elem(&prot_map, &key, &val1, BPF_ANY);
bpf_map_update_elem(¬_prot_map, &key, &val2, BPF_ANY);
return 0;
}
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_tracing.h`, `bpf/bpf_helpers.h`.
- Detected declarations: `struct map`, `function BPF_PROG`, `function BPF_PROG`.
- 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.