tools/testing/selftests/bpf/prog_tests/fs_kfuncs.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/fs_kfuncs.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/fs_kfuncs.c- Extension
.c- Size
- 8443 bytes
- Lines
- 292
- 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
stdlib.hsys/types.hsys/xattr.hlinux/fsverity.hunistd.htest_progs.htest_get_xattr.skel.htest_set_remove_xattr.skel.htest_fsverity.skel.h
Detected Declarations
function test_get_xattrfunction read_and_validate_foofunction set_foofunction validate_bar_matchfunction validate_bar_removedfunction test_set_remove_xattrfunction test_fsverityfunction test_fs_kfuncs
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
#include <stdlib.h>
#include <sys/types.h>
#include <sys/xattr.h>
#include <linux/fsverity.h>
#include <unistd.h>
#include <test_progs.h>
#include "test_get_xattr.skel.h"
#include "test_set_remove_xattr.skel.h"
#include "test_fsverity.skel.h"
static const char testfile[] = "/tmp/test_progs_fs_kfuncs";
static void test_get_xattr(const char *name, const char *value, bool allow_access)
{
struct test_get_xattr *skel = NULL;
int fd = -1, err;
int v[32];
fd = open(testfile, O_CREAT | O_RDONLY, 0644);
if (!ASSERT_GE(fd, 0, "create_file"))
return;
close(fd);
fd = -1;
err = setxattr(testfile, name, value, strlen(value) + 1, 0);
if (err && errno == EOPNOTSUPP) {
printf("%s:SKIP:local fs doesn't support xattr (%d)\n"
"To run this test, make sure /tmp filesystem supports xattr.\n",
__func__, errno);
test__skip();
goto out;
}
if (!ASSERT_OK(err, "setxattr"))
goto out;
skel = test_get_xattr__open_and_load();
if (!ASSERT_OK_PTR(skel, "test_get_xattr__open_and_load"))
goto out;
skel->bss->monitored_pid = getpid();
err = test_get_xattr__attach(skel);
if (!ASSERT_OK(err, "test_get_xattr__attach"))
goto out;
fd = open(testfile, O_RDONLY, 0644);
if (!ASSERT_GE(fd, 0, "open_file"))
goto out;
/* Trigger security_inode_getxattr */
err = getxattr(testfile, name, v, sizeof(v));
if (allow_access) {
ASSERT_EQ(err, -1, "getxattr_return");
ASSERT_EQ(errno, EINVAL, "getxattr_errno");
ASSERT_EQ(skel->bss->found_xattr_from_file, 1, "found_xattr_from_file");
ASSERT_EQ(skel->bss->found_xattr_from_dentry, 1, "found_xattr_from_dentry");
} else {
ASSERT_EQ(err, strlen(value) + 1, "getxattr_return");
ASSERT_EQ(skel->bss->found_xattr_from_file, 0, "found_xattr_from_file");
ASSERT_EQ(skel->bss->found_xattr_from_dentry, 0, "found_xattr_from_dentry");
}
out:
close(fd);
test_get_xattr__destroy(skel);
remove(testfile);
}
/* xattr value we will set to security.bpf.foo */
static const char value_foo[] = "hello";
static void read_and_validate_foo(struct test_set_remove_xattr *skel)
{
char value_out[32];
int err;
err = getxattr(testfile, skel->rodata->xattr_foo, value_out, sizeof(value_out));
ASSERT_EQ(err, sizeof(value_foo), "getxattr size foo");
ASSERT_EQ(strncmp(value_out, value_foo, sizeof(value_foo)), 0, "strncmp value_foo");
}
static void set_foo(struct test_set_remove_xattr *skel)
{
Annotation
- Immediate include surface: `stdlib.h`, `sys/types.h`, `sys/xattr.h`, `linux/fsverity.h`, `unistd.h`, `test_progs.h`, `test_get_xattr.skel.h`, `test_set_remove_xattr.skel.h`.
- Detected declarations: `function test_get_xattr`, `function read_and_validate_foo`, `function set_foo`, `function validate_bar_match`, `function validate_bar_removed`, `function test_set_remove_xattr`, `function test_fsverity`, `function test_fs_kfuncs`.
- 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.