tools/testing/selftests/bpf/prog_tests/signed_loader.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/signed_loader.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/signed_loader.c- Extension
.c- Size
- 33152 bytes
- Lines
- 1136
- 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
test_progs.hsys/syscall.hsys/mman.hsys/wait.hsys/stat.hfcntl.hlimits.hlinux/keyctl.hlinux/bpf.hbpf/libbpf_internal.hbpf/skel_internal.htest_signed_loader.skel.htest_signed_loader_map.skel.htest_signed_loader_data.skel.htest_signed_loader_lsm.skel.h
Detected Declarations
struct gen_loader_fixturefunction load_loaderfunction run_gen_loaderfunction offsetofendfunction close_loader_ctx_fdsfunction run_setupfunction sign_buffunction check_sig_match_shapefunction gen_loader_fixture_initfunction gen_loader_fixture_finifunction metadata_check_shapefunction metadata_matchfunction metadata_sha_mismatchfunction metadata_not_exclusivefunction metadata_hash_not_computedfunction signature_enforcedfunction signature_too_largefunction signature_bad_keyringfunction metadata_ctx_max_entries_ignoredfunction globalfunction signature_authenticates_insnsfunction make_excl_mapfunction hash_requires_frozenfunction no_update_after_freezefunction freeze_writable_mmapfunction no_writable_mmap_frozenfunction map_hash_matches_libbpffunction map_hash_multi_elementfunction map_hash_bad_sizefunction map_hash_unsupported_typefunction setup_meta_mapfunction lsm_signature_verdictfunction test_signed_loader
Annotated Snippet
struct gen_loader_fixture {
struct test_signed_loader *skel;
struct gen_loader_opts gopts;
unsigned char *blob;
void *ctx;
__u32 data_sz;
__u32 ctx_sz;
int nr_maps;
int nr_progs;
__u8 excl[SHA256_DIGEST_LENGTH];
};
static int gen_loader_fixture_init(struct gen_loader_fixture *f)
{
LIBBPF_OPTS(gen_loader_opts, gopts, .gen_hash = true);
int nr_maps = 0, nr_progs = 0;
struct bpf_program *p;
struct bpf_map *m;
memset(f, 0, sizeof(*f));
f->skel = test_signed_loader__open();
if (!ASSERT_OK_PTR(f->skel, "skel_open"))
return -1;
if (!ASSERT_OK(bpf_object__gen_loader(f->skel->obj, &gopts), "gen_loader"))
return -1;
if (!ASSERT_OK(bpf_object__load(f->skel->obj), "gen_load"))
return -1;
f->gopts = gopts;
bpf_object__for_each_program(p, f->skel->obj)
nr_progs++;
bpf_object__for_each_map(m, f->skel->obj)
nr_maps++;
f->nr_maps = nr_maps;
f->nr_progs = nr_progs;
f->ctx_sz = sizeof(struct bpf_loader_ctx) +
nr_maps * sizeof(struct bpf_map_desc) +
nr_progs * sizeof(struct bpf_prog_desc);
f->ctx = calloc(1, f->ctx_sz);
if (!ASSERT_OK_PTR(f->ctx, "ctx_alloc"))
return -1;
((struct bpf_loader_ctx *)f->ctx)->sz = f->ctx_sz;
f->data_sz = gopts.data_sz;
f->blob = malloc(f->data_sz);
if (!ASSERT_OK_PTR(f->blob, "blob_alloc"))
return -1;
memcpy(f->blob, gopts.data, f->data_sz);
/* excl_prog_hash = SHA256(loader insns) == the loader's prog->digest. */
libbpf_sha256(gopts.insns, gopts.insns_sz, f->excl);
return 0;
}
static void gen_loader_fixture_fini(struct gen_loader_fixture *f)
{
if (f->ctx)
close_loader_ctx_fds(f->ctx, f->nr_maps, f->nr_progs);
free(f->blob);
free(f->ctx);
test_signed_loader__destroy(f->skel);
}
static void metadata_check_shape(void)
{
struct gen_loader_fixture f;
if (gen_loader_fixture_init(&f) == 0)
check_sig_match_shape((const struct bpf_insn *)f.gopts.insns,
f.gopts.insns_sz / sizeof(struct bpf_insn));
gen_loader_fixture_fini(&f);
}
static void metadata_match(void)
{
struct gen_loader_fixture f;
bool ran;
int r;
if (gen_loader_fixture_init(&f) == 0) {
r = run_gen_loader(f.gopts.insns, f.gopts.insns_sz, f.blob,
f.data_sz, f.excl, sizeof(f.excl), NULL, 0,
true, f.ctx, f.ctx_sz, &ran);
ASSERT_TRUE(ran, "loader ran");
ASSERT_EQ(r, 0, "honest loader retval");
}
gen_loader_fixture_fini(&f);
}
static void metadata_sha_mismatch(void)
Annotation
- Immediate include surface: `test_progs.h`, `sys/syscall.h`, `sys/mman.h`, `sys/wait.h`, `sys/stat.h`, `fcntl.h`, `limits.h`, `linux/keyctl.h`.
- Detected declarations: `struct gen_loader_fixture`, `function load_loader`, `function run_gen_loader`, `function offsetofend`, `function close_loader_ctx_fds`, `function run_setup`, `function sign_buf`, `function check_sig_match_shape`, `function gen_loader_fixture_init`, `function gen_loader_fixture_fini`.
- 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.