tools/testing/selftests/bpf/prog_tests/token.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/token.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/token.c- Extension
.c- Size
- 34140 bytes
- Lines
- 1278
- 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
bpf/btf.hfcntl.hsched.hsignal.hunistd.hlinux/filter.hlinux/unistd.hlinux/mount.hsys/socket.hsys/stat.hsys/syscall.hsys/un.hbpf_util.hcap_helpers.hsysctl_helpers.htest_progs.htrace_helpers.hpriv_map.skel.hpriv_prog.skel.hdummy_st_ops_success.skel.htoken_kallsyms.skel.htoken_lsm.skel.hpriv_freplace_prog.skel.h
Detected Declarations
struct bpffs_optsfunction sys_mountfunction sys_fsopenfunction sys_fspickfunction sys_fsconfigfunction sys_fsmountfunction sys_move_mountfunction drop_priv_capsfunction restore_priv_capsfunction set_delegate_maskfunction create_bpffs_fdfunction materialize_bpffs_fdfunction sendfdfunction recvfdfunction write_nointrfunction write_filefunction create_and_enter_usernsfunction childfunction wait_for_pidfunction parentfunction subtest_usernsfunction userns_map_createfunction userns_btf_loadfunction userns_prog_loadfunction userns_obj_priv_mapfunction userns_obj_priv_progfunction userns_obj_priv_freplace_setupfunction userns_obj_priv_freplace_progfunction userns_obj_priv_freplace_prog_failfunction validate_struct_ops_loadfunction userns_obj_priv_btf_failfunction userns_obj_priv_btf_successfunction userns_obj_priv_implicit_tokenfunction userns_obj_priv_implicit_token_envvarfunction kallsyms_has_bpf_funcfunction userns_obj_priv_prog_kallsymsfunction userns_bpf_token_infofunction serial_test_token
Annotated Snippet
struct bpffs_opts {
__u64 cmds;
__u64 maps;
__u64 progs;
__u64 attachs;
const char *cmds_str;
const char *maps_str;
const char *progs_str;
const char *attachs_str;
};
static int create_bpffs_fd(void)
{
int fs_fd;
/* create VFS context */
fs_fd = sys_fsopen("bpf", 0);
ASSERT_GE(fs_fd, 0, "fs_fd");
return fs_fd;
}
static int materialize_bpffs_fd(int fs_fd, struct bpffs_opts *opts)
{
int err;
/* set up token delegation mount options */
err = set_delegate_mask(fs_fd, "delegate_cmds", opts->cmds, opts->cmds_str);
if (!ASSERT_OK(err, "fs_cfg_cmds"))
return err;
err = set_delegate_mask(fs_fd, "delegate_maps", opts->maps, opts->maps_str);
if (!ASSERT_OK(err, "fs_cfg_maps"))
return err;
err = set_delegate_mask(fs_fd, "delegate_progs", opts->progs, opts->progs_str);
if (!ASSERT_OK(err, "fs_cfg_progs"))
return err;
err = set_delegate_mask(fs_fd, "delegate_attachs", opts->attachs, opts->attachs_str);
if (!ASSERT_OK(err, "fs_cfg_attachs"))
return err;
/* instantiate FS object */
err = sys_fsconfig(fs_fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0);
if (err < 0)
return -errno;
return 0;
}
/* send FD over Unix domain (AF_UNIX) socket */
static int sendfd(int sockfd, int fd)
{
struct msghdr msg = {};
struct cmsghdr *cmsg;
int fds[1] = { fd }, err;
char iobuf[1];
struct iovec io = {
.iov_base = iobuf,
.iov_len = sizeof(iobuf),
};
union {
char buf[CMSG_SPACE(sizeof(fds))];
struct cmsghdr align;
} u;
msg.msg_iov = &io;
msg.msg_iovlen = 1;
msg.msg_control = u.buf;
msg.msg_controllen = sizeof(u.buf);
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(fds));
memcpy(CMSG_DATA(cmsg), fds, sizeof(fds));
err = sendmsg(sockfd, &msg, 0);
if (err < 0)
err = -errno;
if (!ASSERT_EQ(err, 1, "sendmsg"))
return -EINVAL;
return 0;
}
/* receive FD over Unix domain (AF_UNIX) socket */
static int recvfd(int sockfd, int *fd)
{
struct msghdr msg = {};
struct cmsghdr *cmsg;
int fds[1], err;
char iobuf[1];
Annotation
- Immediate include surface: `bpf/btf.h`, `fcntl.h`, `sched.h`, `signal.h`, `unistd.h`, `linux/filter.h`, `linux/unistd.h`, `linux/mount.h`.
- Detected declarations: `struct bpffs_opts`, `function sys_mount`, `function sys_fsopen`, `function sys_fspick`, `function sys_fsconfig`, `function sys_fsmount`, `function sys_move_mount`, `function drop_priv_caps`, `function restore_priv_caps`, `function set_delegate_mask`.
- 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.