tools/testing/selftests/bpf/progs/strncmp_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/strncmp_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/strncmp_test.c- Extension
.c- Size
- 1398 bytes
- Lines
- 55
- 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.
Dependency Surface
stdbool.hlinux/types.hlinux/bpf.hbpf/bpf_helpers.hbpf/bpf_tracing.h
Detected Declarations
function do_strncmpfunction strncmp_bad_not_const_str_sizefunction strncmp_bad_writable_targetfunction strncmp_bad_not_null_term_target
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (C) 2021. Huawei Technologies Co., Ltd */
#include <stdbool.h>
#include <linux/types.h>
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#define STRNCMP_STR_SZ 8
const char target[STRNCMP_STR_SZ] = "EEEEEEE";
char str[STRNCMP_STR_SZ];
int cmp_ret = 0;
int target_pid = 0;
const char no_str_target[STRNCMP_STR_SZ] = "12345678";
char writable_target[STRNCMP_STR_SZ];
unsigned int no_const_str_size = STRNCMP_STR_SZ;
char _license[] SEC("license") = "GPL";
SEC("?tp/syscalls/sys_enter_nanosleep")
int do_strncmp(void *ctx)
{
if ((bpf_get_current_pid_tgid() >> 32) != target_pid)
return 0;
cmp_ret = bpf_strncmp(str, STRNCMP_STR_SZ, target);
return 0;
}
SEC("?tp/syscalls/sys_enter_nanosleep")
int strncmp_bad_not_const_str_size(void *ctx)
{
/* The value of string size is not const, so will fail */
cmp_ret = bpf_strncmp(str, no_const_str_size, target);
return 0;
}
SEC("?tp/syscalls/sys_enter_nanosleep")
int strncmp_bad_writable_target(void *ctx)
{
/* Compared target is not read-only, so will fail */
cmp_ret = bpf_strncmp(str, STRNCMP_STR_SZ, writable_target);
return 0;
}
SEC("?tp/syscalls/sys_enter_nanosleep")
int strncmp_bad_not_null_term_target(void *ctx)
{
/* Compared target is not null-terminated, so will fail */
cmp_ret = bpf_strncmp(str, STRNCMP_STR_SZ, no_str_target);
return 0;
}
Annotation
- Immediate include surface: `stdbool.h`, `linux/types.h`, `linux/bpf.h`, `bpf/bpf_helpers.h`, `bpf/bpf_tracing.h`.
- Detected declarations: `function do_strncmp`, `function strncmp_bad_not_const_str_size`, `function strncmp_bad_writable_target`, `function strncmp_bad_not_null_term_target`.
- 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.