Skip to content

eBPF-based security platform

treewide: drop the shirudo_ and SHIRUDO_ prefixes from the policy names

Daniel Borkmann2898ed5cd691
diff --git a/bpf/lib/policy.h b/bpf/lib/policy.h
index 36b8c1f5..d82cc948 100644
--- a/bpf/lib/policy.h
+++ b/bpf/lib/policy.h
@@ -8,7 +8,7 @@
#ifndef SHIRUDO_BPF_POLICY_H
#define SHIRUDO_BPF_POLICY_H
-struct shirudo_task_policy {
+struct task_policy {
__u64 active;
__u64 candidate;
};
@@ -17,7 +17,7 @@ struct {
__uint(type, BPF_MAP_TYPE_TASK_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
- __type(value, struct shirudo_task_policy);
+ __type(value, struct task_policy);
} policy_map SEC(".maps");
struct {
diff --git a/bpf/seal.c b/bpf/seal.c
index 0b5e6a21..95fb203d 100644
--- a/bpf/seal.c
+++ b/bpf/seal.c
@@ -140,7 +140,7 @@ void BPF_PROG(shirudo_seal_bprm_committed_creds,
const struct linux_binprm *bprm)
{
struct task_struct *task = bpf_get_current_task_btf();
- struct shirudo_task_policy *policy;
+ struct task_policy *policy;
struct task_authority *authority;
policy = bpf_task_storage_get(&policy_map, task, NULL, 0);
@@ -162,9 +162,9 @@ int BPF_PROG(shirudo_seal_task_alloc, struct task_struct *child,
__u64 clone_flags, int ret)
{
struct task_struct *parent = bpf_get_current_task_btf();
- struct shirudo_task_policy *parent_policy;
+ struct task_policy *parent_policy;
struct task_authority *parent_authority;
- struct shirudo_task_policy *policy;
+ struct task_policy *policy;
struct task_authority *authority;
if (ret)
@@ -478,7 +478,7 @@ int BPF_PROG(shirudo_seal_socket_post_create, struct socket *sock, int family,
int type, int protocol, int kern, int ret)
{
struct task_struct *task = bpf_get_current_task_btf();
- struct shirudo_task_policy *policy;
+ struct task_policy *policy;
struct sock *sk;
__u64 active;
@@ -517,7 +517,7 @@ int BPF_PROG(shirudo_seal_bprm_creds_for_exec, struct linux_binprm *bprm,
int ret)
{
struct task_struct *task = bpf_get_current_task_btf();
- struct shirudo_task_policy *policy;
+ struct task_policy *policy;
if (ret)
return ret;
@@ -540,7 +540,7 @@ int BPF_PROG(shirudo_seal_bprm_check_security,
{
struct task_struct *task = bpf_get_current_task_btf();
struct task_authority *authority;
- struct shirudo_task_policy *policy;
+ struct task_policy *policy;
struct seal_scratch *scratch;
struct bpf_dynptr tdp;
struct inode *real_inode;
diff --git a/builtin-upatch.c b/builtin-upatch.c
index d20a7147..fa60d50c 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -1727,8 +1727,8 @@ static int __upatch_apply(const char *path, bool verify_only,
int prog_fd = -1, map_fd = -1, policy_map_fd = -1;
int socket_policy_map_fd = -1, ret;
struct loader_ctx *cx = NULL;
- __u32 retval = 0, shared_policy_map_idx = SHIRUDO_UPATCH_MAPS_MAX;
- __u32 shared_socket_policy_map_idx = SHIRUDO_UPATCH_MAPS_MAX;
+ __u32 retval = 0, shared_policy_map_idx = UPATCH_MAPS_MAX;
+ __u32 shared_socket_policy_map_idx = UPATCH_MAPS_MAX;
vlog = xmalloc(VERIFIER_LOG_MAX);
if (!vlog) {
@@ -2753,8 +2753,8 @@ static void unload_unmeasured(const char *name)
static void apply_policy_labels(const char *artifact)
{
struct upatch upatch = {};
- const struct shirudo_upatch_policy_label_header *header;
- const struct shirudo_upatch_policy_label_entry *entries;
+ const struct upatch_policy_label_header *header;
+ const struct upatch_policy_label_entry *entries;
const void *labels;
__u32 len, count;
int rc;
@@ -2769,7 +2769,7 @@ static void apply_policy_labels(const char *artifact)
count = le32toh(header->count);
entries = (const void *)((const __u8 *)labels + sizeof(*header));
for (__u32 i = 0; i < count; i++) {
- const struct shirudo_upatch_policy_label_entry *entry = &entries[i];
+ const struct upatch_policy_label_entry *entry = &entries[i];
__u64 bits = le64toh(entry->bit), current = 0;
ssize_t n;
int fd;
diff --git a/include/shirudo/upatch.h b/include/shirudo/upatch.h
index b3731501..320ab54a 100644
--- a/include/shirudo/upatch.h
+++ b/include/shirudo/upatch.h
@@ -81,24 +81,19 @@ enum upatch_section_tag {
UPATCH_SECTION_ATTACH = 0x4d475055u, /* "UPGM" le */
UPATCH_SECTION_UNLOAD = 0x444c4e55u, /* "UNLD" le */
UPATCH_SECTION_DECODERS = 0x42444344u, /* "DCDB" le */
- SHIRUDO_UPATCH_SECTION_POLICY_LABELS = 0x4c504853u, /* "SHPL" le */
- SHIRUDO_UPATCH_SECTION_POLICY_UNLABELS = 0x554c5053u, /* "SPLU" le */
+ UPATCH_SECTION_POLICY_LABELS = 0x4c504853u, /* "SHPL" le */
+ UPATCH_SECTION_POLICY_UNLABELS = 0x554c5053u, /* "SPLU" le */
};
-#define SHIRUDO_UPATCH_SECTION_NAME UPATCH_SECTION_NAME
-#define SHIRUDO_UPATCH_SECTION_ATTACH UPATCH_SECTION_ATTACH
-#define SHIRUDO_UPATCH_SECTION_UNLOAD UPATCH_SECTION_UNLOAD
-#define SHIRUDO_UPATCH_SECTION_DECODERS UPATCH_SECTION_DECODERS
+#define UPATCH_POLICY_LABELS_MAGIC 0x4c504853u /* "SHPL" le */
+#define UPATCH_POLICY_LABELS_VERSION 1u
+#define UPATCH_POLICY_UNLABELS_VERSION 1u
+#define UPATCH_MAPS_MAX 64u
+#define UPATCH_POLICY_NAME_MAX 64u
+#define UPATCH_POLICY_PATH_MAX 4096u
+#define SHIRUDO_POLICY_XATTR "security.bpf.shirudo.policy"
-#define SHIRUDO_UPATCH_POLICY_LABELS_MAGIC 0x4c504853u /* "SHPL" le */
-#define SHIRUDO_UPATCH_POLICY_LABELS_VERSION 1u
-#define SHIRUDO_UPATCH_POLICY_UNLABELS_VERSION 1u
-#define SHIRUDO_UPATCH_MAPS_MAX 64u
-#define SHIRUDO_UPATCH_POLICY_NAME_MAX 64u
-#define SHIRUDO_UPATCH_POLICY_PATH_MAX 4096u
-#define SHIRUDO_POLICY_XATTR "security.bpf.shirudo.policy"
-
-struct shirudo_upatch_policy_label_header {
+struct upatch_policy_label_header {
__u32 magic;
__u32 version;
__u32 count;
@@ -106,10 +101,10 @@ struct shirudo_upatch_policy_label_header {
__u32 socket_policy_map_idx;
};
-struct shirudo_upatch_policy_label_entry {
+struct upatch_policy_label_entry {
__u64 bit;
- char policy[SHIRUDO_UPATCH_POLICY_NAME_MAX];
- char path[SHIRUDO_UPATCH_POLICY_PATH_MAX];
+ char policy[UPATCH_POLICY_NAME_MAX];
+ char path[UPATCH_POLICY_PATH_MAX];
};
struct upatch_signed_section {
diff --git a/testing/fixtures/policy-exec-graph/policy-exec-graph.bpf.c b/testing/fixtures/policy-exec-graph/policy-exec-graph.bpf.c
index 049d98ec..01a734b9 100644
--- a/testing/fixtures/policy-exec-graph/policy-exec-graph.bpf.c
+++ b/testing/fixtures/policy-exec-graph/policy-exec-graph.bpf.c
@@ -35,7 +35,7 @@ int BPF_PROG(shirudo_test_policy_exec_graph,
struct linux_binprm *bprm, int ret)
{
struct task_struct *task = bpf_get_current_task_btf();
- struct shirudo_task_policy *policy;
+ struct task_policy *policy;
struct policy_exec_scratch *scratch;
struct bpf_dynptr value_ptr;
__u64 target;
diff --git a/testing/fixtures/policy-labels/policy-labels.bpf.c b/testing/fixtures/policy-labels/policy-labels.bpf.c
index 065ef3a5..f6508cb6 100644
--- a/testing/fixtures/policy-labels/policy-labels.bpf.c
+++ b/testing/fixtures/policy-labels/policy-labels.bpf.c
@@ -15,7 +15,7 @@ int BPF_PROG(shirudo_test_policy_labels)
SEC("lsm.s/bprm_check_security")
int BPF_PROG(shirudo_test_policy_verdict, struct linux_binprm *bprm, int ret)
{
- struct shirudo_task_policy *policy;
+ struct task_policy *policy;
if (ret)
return ret;
@@ -28,7 +28,7 @@ SEC("lsm.s/socket_connect")
int BPF_PROG(shirudo_test_socket_policy_verdict, struct socket *sock,
struct sockaddr *address, int addrlen, int ret)
{
- struct shirudo_task_policy *policy;
+ struct task_policy *policy;
struct sock *sk;
__u64 *socket_policy;
diff --git a/testing/fuzz/fuzz-beefile.c b/testing/fuzz/fuzz-beefile.c
index 4757a20e..b6bdb820 100644
--- a/testing/fuzz/fuzz-beefile.c
+++ b/testing/fuzz/fuzz-beefile.c
@@ -45,7 +45,7 @@ const char *build_locate_vmlinux(const char *override)
int build_package_load(const char *bpf_o, const char *src_path,
const char *out_upatch, const char *upatch_name,
- const struct shirudo_upatch_policy_label_entry *policies,
+ const struct upatch_policy_label_entry *policies,
__u32 nr_policies,
const char *pkey_path, const char *cert_path)
{
diff --git a/testing/helper/policy-probe.c b/testing/helper/policy-probe.c
index 82d19312..1878b692 100644
--- a/testing/helper/policy-probe.c
+++ b/testing/helper/policy-probe.c
@@ -60,7 +60,7 @@ static int check_mark(const char *pin, int expected)
static int read_policy(const char *pin, __u64 *active)
{
- struct shirudo_task_policy policy = {};
+ struct task_policy policy = {};
union bpf_attr attr = {};
int fd, pidfd, rc;
diff --git a/testing/helper/test-upatch-prog-metadata.c b/testing/helper/test-upatch-prog-metadata.c
index 7c218980..29b221d1 100644
--- a/testing/helper/test-upatch-prog-metadata.c
+++ b/testing/helper/test-upatch-prog-metadata.c
@@ -172,8 +172,8 @@ static int expect_policy_labels(const struct upatch *u)
"/tmp/shirudo-policy-label-test/socket-executable",
};
static const __u64 bits[] = { 1, 2, 4, 16 };
- struct shirudo_upatch_policy_label_entry entry;
- struct shirudo_upatch_policy_label_header header;
+ struct upatch_policy_label_entry entry;
+ struct upatch_policy_label_header header;
const __u8 *raw, *cursor;
__u32 len;
size_t count = ARRAY_SIZE(bits);
@@ -182,8 +182,8 @@ static int expect_policy_labels(const struct upatch *u)
if (!raw || len != sizeof(header) + count * sizeof(entry))
return fail("policy label section length mismatch");
memcpy(&header, raw, sizeof(header));
- if (le32toh(header.magic) != SHIRUDO_UPATCH_POLICY_LABELS_MAGIC ||
- le32toh(header.version) != SHIRUDO_UPATCH_POLICY_LABELS_VERSION ||
+ if (le32toh(header.magic) != UPATCH_POLICY_LABELS_MAGIC ||
+ le32toh(header.version) != UPATCH_POLICY_LABELS_VERSION ||
le32toh(header.count) != count ||
le32toh(header.policy_map_idx) != 0 ||
le32toh(header.socket_policy_map_idx) != 1)
diff --git a/tools/shirudo-build/bpm-build.c b/tools/shirudo-build/bpm-build.c
index b5caf6cd..673ef9d3 100644
--- a/tools/shirudo-build/bpm-build.c
+++ b/tools/shirudo-build/bpm-build.c
@@ -1248,7 +1248,7 @@ static int build_upatches(struct bpm_build_spec *spec, const char *pkey,
__u8 payload[CRYPTO_SHA256_LEN];
struct upatch parsed = {};
int ret;
- struct shirudo_upatch_policy_label_entry *labels = NULL;
+ struct upatch_policy_label_entry *labels = NULL;
__u32 nr_labels = 0;
if (build_resolve_source(spec, u->source, source, sizeof(source),
@@ -1298,7 +1298,7 @@ static int build_upatches(struct bpm_build_spec *spec, const char *pkey,
struct bpm_build_policy *p = &u->policies[j];
for (int k = 0; k < p->n_paths; k++) {
- struct shirudo_upatch_policy_label_entry *e =
+ struct upatch_policy_label_entry *e =
&labels[nr_labels++];
e->bit = p->bit;
diff --git a/tools/shirudo-build/bpm.h b/tools/shirudo-build/bpm.h
index aba694d6..46ef85bb 100644
--- a/tools/shirudo-build/bpm.h
+++ b/tools/shirudo-build/bpm.h
@@ -24,7 +24,7 @@
#define BPM_BUILD_MAX_POLICIES 64
struct bpm_build_policy {
- char id[SHIRUDO_UPATCH_POLICY_NAME_MAX];
+ char id[UPATCH_POLICY_NAME_MAX];
char paths[16][TREE_STRING_MAX];
int n_paths;
__u64 bit;
diff --git a/tools/shirudo-build/package.c b/tools/shirudo-build/package.c
index b838f0b0..87d2728b 100644
--- a/tools/shirudo-build/package.c
+++ b/tools/shirudo-build/package.c
@@ -1589,15 +1589,15 @@ static int finalize_object(struct bpf_object *obj, const char *out_path,
opts.gen_hash = true;
if (policy_labels_len) {
- const struct shirudo_upatch_policy_label_header *labels =
+ const struct upatch_policy_label_header *labels =
policy_labels;
__u32 map_idx = le32toh(labels->policy_map_idx);
__u32 socket_map_idx =
le32toh(labels->socket_policy_map_idx);
- if (map_idx >= nr_maps || map_idx >= SHIRUDO_UPATCH_MAPS_MAX ||
+ if (map_idx >= nr_maps || map_idx >= UPATCH_MAPS_MAX ||
socket_map_idx >= nr_maps ||
- socket_map_idx >= SHIRUDO_UPATCH_MAPS_MAX ||
+ socket_map_idx >= UPATCH_MAPS_MAX ||
map_idx == socket_map_idx) {
err = -EINVAL;
goto out;
@@ -1644,7 +1644,7 @@ static int finalize_object(struct bpf_object *obj, const char *out_path,
};
if (policy_labels_len)
sections[nr_sections++] = (struct signed_section){
- SHIRUDO_UPATCH_SECTION_POLICY_LABELS,
+ UPATCH_SECTION_POLICY_LABELS,
policy_labels, policy_labels_len,
};
}
@@ -1769,13 +1769,13 @@ static int check_upatch_name(const char *name)
int build_package_load(const char *bpf_o, const char *src_path,
const char *out_path, const char *upatch_name,
- const struct shirudo_upatch_policy_label_entry *policies,
+ const struct upatch_policy_label_entry *policies,
__u32 nr_policies,
const char *pkey_path, const char *cert_path)
{
struct bpf_object *obj;
- struct shirudo_upatch_policy_label_header *label_blob = NULL;
- struct shirudo_upatch_policy_label_entry *label_entries;
+ struct upatch_policy_label_header *label_blob = NULL;
+ struct upatch_policy_label_entry *label_entries;
struct bpf_map *map, *policy_map, *socket_policy_map;
__u32 label_len = 0, policy_map_idx = 0, socket_policy_map_idx = 0;
__u32 map_idx = 0;
@@ -1827,7 +1827,7 @@ int build_package_load(const char *bpf_o, const char *src_path,
break;
map_idx++;
}
- if (map_idx >= SHIRUDO_UPATCH_MAPS_MAX || map != policy_map) {
+ if (map_idx >= UPATCH_MAPS_MAX || map != policy_map) {
err = -E2BIG;
goto out;
}
@@ -1838,7 +1838,7 @@ int build_package_load(const char *bpf_o, const char *src_path,
break;
map_idx++;
}
- if (map_idx >= SHIRUDO_UPATCH_MAPS_MAX ||
+ if (map_idx >= UPATCH_MAPS_MAX ||
map != socket_policy_map || map_idx == policy_map_idx) {
err = -E2BIG;
goto out;
@@ -1850,8 +1850,8 @@ int build_package_load(const char *bpf_o, const char *src_path,
err = -ENOMEM;
goto out;
}
- label_blob->magic = htole32(SHIRUDO_UPATCH_POLICY_LABELS_MAGIC);
- label_blob->version = htole32(SHIRUDO_UPATCH_POLICY_LABELS_VERSION);
+ label_blob->magic = htole32(UPATCH_POLICY_LABELS_MAGIC);
+ label_blob->version = htole32(UPATCH_POLICY_LABELS_VERSION);
label_blob->count = htole32(nr_policies);
label_blob->policy_map_idx = htole32(policy_map_idx);
label_blob->socket_policy_map_idx =
diff --git a/tools/shirudo-build/package.h b/tools/shirudo-build/package.h
index 53e53c6d..ab6b8c53 100644
--- a/tools/shirudo-build/package.h
+++ b/tools/shirudo-build/package.h
@@ -10,11 +10,11 @@
#include <shirudo/misc.h>
-struct shirudo_upatch_policy_label_entry;
+struct upatch_policy_label_entry;
int build_package_load(const char *bpf_o, const char *src_path,
const char *out_upatch, const char *upatch_name,
- const struct shirudo_upatch_policy_label_entry *policies,
+ const struct upatch_policy_label_entry *policies,
__u32 nr_policies,
const char *pkey_path, const char *cert_path);
diff --git a/util/identity.h b/util/identity.h
index 8cf58ca6..8f69316c 100644
--- a/util/identity.h
+++ b/util/identity.h
@@ -68,12 +68,12 @@ BUILD_BUG_ON(sizeof(struct device_authority) != 48);
BUILD_BUG_ON(sizeof(struct task_authority) != 8);
BUILD_BUG_ON(sizeof(struct identity) != 584);
-struct shirudo_task_policy {
+struct task_policy {
__u64 active;
__u64 candidate;
};
-_Static_assert(sizeof(struct shirudo_task_policy) == 16,
+_Static_assert(sizeof(struct task_policy) == 16,
"task policy ABI");
/* The bpffs mount init made, which the unmount guard keeps mounted. */
diff --git a/util/image_guards.c b/util/image_guards.c
index 22df4a1d..4773e064 100644
--- a/util/image_guards.c
+++ b/util/image_guards.c
@@ -148,7 +148,7 @@ const struct guard_map shirudo_guard_maps[GUARD_MAP_COUNT] = {
[GUARD_POLICY] = {
"policy_map", POLICY_PIN,
BPF_MAP_TYPE_TASK_STORAGE, sizeof(__u32),
- sizeof(struct shirudo_task_policy), 0, BPF_F_NO_PREALLOC,
+ sizeof(struct task_policy), 0, BPF_F_NO_PREALLOC,
},
[GUARD_SOCKET_POLICY] = {
"socket_policy_map", SOCKET_POLICY_PIN,
diff --git a/util/upatch.c b/util/upatch.c
index 9fecb648..88d35f6b 100644
--- a/util/upatch.c
+++ b/util/upatch.c
@@ -124,10 +124,10 @@ static bool parse_policy_labels(const __u8 *p, __u32 len, __u32 nr_maps,
bool bind_policy_maps, __u32 *map_idx,
__u32 *socket_map_idx)
{
- struct shirudo_upatch_policy_label_header h;
+ struct upatch_policy_label_header h;
__u32 count, version, idx, socket_idx;
__u32 header_len = bind_policy_maps ? sizeof(h) :
- offsetof(struct shirudo_upatch_policy_label_header,
+ offsetof(struct upatch_policy_label_header,
socket_policy_map_idx);
if (len < header_len)
@@ -138,20 +138,20 @@ static bool parse_policy_labels(const __u8 *p, __u32 len, __u32 nr_maps,
version = le32toh(h.version);
idx = le32toh(h.policy_map_idx);
socket_idx = le32toh(h.socket_policy_map_idx);
- if (le32toh(h.magic) != SHIRUDO_UPATCH_POLICY_LABELS_MAGIC ||
+ if (le32toh(h.magic) != UPATCH_POLICY_LABELS_MAGIC ||
version != (bind_policy_maps ?
- SHIRUDO_UPATCH_POLICY_LABELS_VERSION :
- SHIRUDO_UPATCH_POLICY_UNLABELS_VERSION) ||
+ UPATCH_POLICY_LABELS_VERSION :
+ UPATCH_POLICY_UNLABELS_VERSION) ||
(bind_policy_maps &&
- (idx >= nr_maps || idx >= SHIRUDO_UPATCH_MAPS_MAX ||
+ (idx >= nr_maps || idx >= UPATCH_MAPS_MAX ||
socket_idx >= nr_maps ||
- socket_idx >= SHIRUDO_UPATCH_MAPS_MAX || idx == socket_idx)) ||
+ socket_idx >= UPATCH_MAPS_MAX || idx == socket_idx)) ||
(!bind_policy_maps && (idx || socket_idx)) || !count ||
(__u64)header_len + (__u64)count *
- sizeof(struct shirudo_upatch_policy_label_entry) != len)
+ sizeof(struct upatch_policy_label_entry) != len)
return false;
for (__u32 i = 0; i < count; i++) {
- struct shirudo_upatch_policy_label_entry e;
+ struct upatch_policy_label_entry e;
__u64 bit;
memcpy(&e, p + header_len + i * sizeof(e), sizeof(e));
@@ -306,7 +306,7 @@ static void parse_signed_sections(struct upatch *u)
if (!parse_decoders(u, data + off, len))
goto reject;
break;
- case SHIRUDO_UPATCH_SECTION_POLICY_LABELS:
+ case UPATCH_SECTION_POLICY_LABELS:
bit = 16;
if (!parse_policy_labels(data + off, len, u->hdr.nr_maps,
true,
@@ -316,7 +316,7 @@ static void parse_signed_sections(struct upatch *u)
u->signed_policy_labels = data + off;
u->signed_policy_labels_len = len;
break;
- case SHIRUDO_UPATCH_SECTION_POLICY_UNLABELS:
+ case UPATCH_SECTION_POLICY_UNLABELS:
bit = 32;
if (!parse_policy_labels(data + off, len, u->hdr.nr_maps,
false, NULL, NULL))