Skip to content

eBPF-based security platform

treewide: name the policy maps like the other guard maps

Daniel Borkmannc8cb69e66cd6
diff --git a/Documentation/internals/enforcement.rst b/Documentation/internals/enforcement.rst
index 230dc55c..b0a4336c 100644
--- a/Documentation/internals/enforcement.rst
+++ b/Documentation/internals/enforcement.rst
@@ -62,11 +62,11 @@ The objects share seven maps, which ``init`` hands from ``bpf2`` to
* - ``shirudo_tasks``
- ``task_authority``
- Task storage with each task's mark and exec candidate.
- * - ``policy_map``
- - ``policy_map``
+ * - ``shirudo_task_policy``
+ - ``task_policy``
- Task storage with committed policy bits and the exec candidate.
- * - ``socket_policy_map``
- - ``socket_policy_map``
+ * - ``shirudo_sock_policy``
+ - ``socket_policy``
- Socket storage for committed policy bits, cloned from listeners
to accepted sockets.
* - ``shirudo_devices``
diff --git a/Documentation/internals/seal.rst b/Documentation/internals/seal.rst
index f3051a12..7349a0ff 100644
--- a/Documentation/internals/seal.rst
+++ b/Documentation/internals/seal.rst
@@ -76,7 +76,7 @@ Policy bits
An executable may carry ``security.bpf.shirudo.policy``, an 8-byte native
``__u64`` bitset. During exec, ``bprm_check_security`` ORs the bitsets
from the original file and each interpreter into a task-local candidate
-in ``policy_map``. ``bprm_committed_creds`` commits that value only after
+in ``shirudo_task_policy``. ``bprm_committed_creds`` commits that value only after
exec succeeds. The candidate starts with the task's committed bits, so
policy accumulates across execs as well as interpreter handlers. A failed
exec leaves the committed value unchanged. A fork or clone inherits the
@@ -86,7 +86,7 @@ without xattrs contributes zero bits; invalid lengths and other read
errors refuse the exec.
``socket_post_create`` snapshots a task's committed bits into
-``socket_policy_map`` when it creates a socket. A socket with no policy
+``shirudo_sock_policy`` when it creates a socket. A socket with no policy
uses no storage and reads as zero. If nonzero policy storage cannot be
allocated, socket creation fails. The map uses ``BPF_F_CLONE`` so an
accepted socket inherits the listener's snapshot, even when the task
diff --git a/Documentation/internals/signed-loader.rst b/Documentation/internals/signed-loader.rst
index ba72232f..b997393f 100644
--- a/Documentation/internals/signed-loader.rst
+++ b/Documentation/internals/signed-loader.rst
@@ -117,8 +117,8 @@ loader inside the kernel, which ``lsm/bpf`` sees with ``kernel`` true.
- ``BPF_PROG_TEST_RUN`` of the loader
- ``lsm/bpf``, runtime authority (``ProgRun``). The loader then
runs in the kernel. When the signed ``SHPL`` section is present,
- shirudo opens its pinned ``policy_map`` and
- ``socket_policy_map`` and supplies both FDs at their signed
+ shirudo opens its pinned ``shirudo_task_policy`` and
+ ``shirudo_sock_policy`` and supplies both FDs at their signed
descriptor indices. The generated loader reuses them; it neither
creates nor pins private copies.
* - loader
diff --git a/Documentation/reference/files.rst b/Documentation/reference/files.rst
index 9754acec..72818d5c 100644
--- a/Documentation/reference/files.rst
+++ b/Documentation/reference/files.rst
@@ -342,6 +342,10 @@ by ``BPF_OBJ_GET`` (``ObjGet``). Directories stay listable.
:doc:`/security/tamper-counters`.
* - ``task_authority``, ``config_roots``
- Task storage maps of runtime authority and expected config roots.
+ * - ``task_policy``, ``socket_policy``
+ - Maps ``shirudo_task_policy`` and ``shirudo_sock_policy``: the
+ policy bits of each task and of each socket it creates, which
+ policy-label upatches read.
* - ``devices``
- Map of the dm-verity devices shirudo set up, with their root
hashes.
diff --git a/Documentation/reference/formats/upatch-format.rst b/Documentation/reference/formats/upatch-format.rst
index d2662cc5..81755178 100644
--- a/Documentation/reference/formats/upatch-format.rst
+++ b/Documentation/reference/formats/upatch-format.rst
@@ -300,7 +300,8 @@ Section tags
- variable
- Signed policy labels, each naming a policy ID, one-hot bit and
absolute file path. Its presence opts into the shared task
- ``policy_map`` and socket ``socket_policy_map`` bindings.
+ ``shirudo_task_policy`` and socket ``shirudo_sock_policy``
+ bindings.
The writer emits ``NAME``, then ``UNLD`` for an unload directive, or
``UPGM`` and optional ``DCDB`` and ``SHPL`` sections for a load artifact.
@@ -589,10 +590,10 @@ SHPL section
fixed-size entries. ``policy_map_idx`` and ``socket_policy_map_idx`` are
the zero-based indices of the shared maps in the loader's map descriptor
array. The builder accepts this section only when the BPF object declares
-compatible maps named ``policy_map`` and ``socket_policy_map``. At load
-time, shirudo supplies the pinned task and socket storage maps at those
-descriptors; the loader does not create or pin private copies. upatches
-without ``SHPL`` use their normal maps.
+compatible maps named ``shirudo_task_policy`` and ``shirudo_sock_policy``.
+At load time, shirudo supplies the pinned task and socket storage maps at
+those descriptors; the loader does not create or pin private copies.
+upatches without ``SHPL`` use their normal maps.
.. list-table::
:header-rows: 1
diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rst
index d9acc465..c45b4062 100644
--- a/Documentation/security/threat-model.rst
+++ b/Documentation/security/threat-model.rst
@@ -301,11 +301,11 @@ Assets
- Frozen against ``bpf()`` writes; only the seal's programs set a
mark (T3).
* - Task policy bits
- - ``policy_map`` task storage, pinned as ``policy_map``
+ - ``shirudo_task_policy`` task storage, pinned as ``task_policy``
- Frozen against userspace writes; exec hooks OR protected inode
values and commit only after a successful exec.
* - Socket policy bits
- - ``socket_policy_map`` socket storage, pinned as ``socket_policy_map``
+ - ``shirudo_sock_policy`` socket storage, pinned as ``socket_policy``
- Frozen against userspace writes; socket creation snapshots task
bits and accepted sockets inherit the listener's value.
* - Device records and expected roots
@@ -663,7 +663,7 @@ returns the label (U12).
Executables may carry ``security.bpf.shirudo.policy``, an 8-byte
target-native ``__u64`` bitset. During exec, the seal ORs the value from
-the original file and each interpreter into ``policy_map``. Only
+the original file and each interpreter into ``shirudo_task_policy``. Only
``ENODATA`` or ``EOPNOTSUPP`` means no policy; malformed or unreadable
values refuse exec.
The candidate starts with the task's committed bits, so successful exec
diff --git a/Documentation/upatches/publish/beefile.rst b/Documentation/upatches/publish/beefile.rst
index 2d90dedf..19b86817 100644
--- a/Documentation/upatches/publish/beefile.rst
+++ b/Documentation/upatches/publish/beefile.rst
@@ -209,8 +209,8 @@ has fails. Entries that share a name must name the same input.
A policy table declares a named bit and the absolute paths whose
``security.bpf.shirudo.policy`` xattrs this upatch labels. The builder
embeds the entries in the signed ``SHPL`` section. Its presence opts the
-upatch into shirudo's shared task ``policy_map`` and socket
-``socket_policy_map``. The generated loader reuses both pinned maps
+upatch into shirudo's shared task ``shirudo_task_policy`` and socket
+``shirudo_sock_policy`` maps. The generated loader reuses both pinned maps
rather than creating private copies. The BPF source must declare the map
ABI, normally by including ``policy.h`` after ``vmlinux.h`` and the
libbpf headers.
diff --git a/bpf/lib/policy.h b/bpf/lib/policy.h
index 92e65cbe..0d247a52 100644
--- a/bpf/lib/policy.h
+++ b/bpf/lib/policy.h
@@ -20,13 +20,13 @@ struct {
__uint(map_flags, BPF_F_NO_PREALLOC);
__type(key, int);
__type(value, struct task_policy);
-} policy_map SEC(".maps");
+} shirudo_task_policy SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_SK_STORAGE);
__uint(map_flags, BPF_F_NO_PREALLOC | BPF_F_CLONE);
__type(key, int);
__type(value, __u64);
-} socket_policy_map SEC(".maps");
+} shirudo_sock_policy SEC(".maps");
#endif /* SHIRUDO_BPF_POLICY_H */
diff --git a/bpf/seal.c b/bpf/seal.c
index 7dd38e2d..c6c0d7c9 100644
--- a/bpf/seal.c
+++ b/bpf/seal.c
@@ -142,7 +142,7 @@ void BPF_PROG(shirudo_seal_bprm_committed_creds,
struct task_authority *authority;
struct task_policy *policy;
- policy = bpf_task_storage_get(&policy_map, task, NULL, 0);
+ policy = bpf_task_storage_get(&shirudo_task_policy, task, NULL, 0);
if (policy) {
policy->active = policy->candidate;
policy->candidate = 0;
@@ -168,9 +168,10 @@ int BPF_PROG(shirudo_seal_task_alloc, struct task_struct *child,
if (ret)
return ret;
- parent_policy = bpf_task_storage_get(&policy_map, parent, NULL, 0);
+ parent_policy = bpf_task_storage_get(&shirudo_task_policy, parent,
+ NULL, 0);
if (parent_policy && parent_policy->active) {
- policy = bpf_task_storage_get(&policy_map, child, NULL,
+ policy = bpf_task_storage_get(&shirudo_task_policy, child, NULL,
BPF_LOCAL_STORAGE_GET_F_CREATE);
if (!policy)
return -ENOMEM;
@@ -485,14 +486,14 @@ int BPF_PROG(shirudo_seal_socket_post_create, struct socket *sock, int family,
return ret;
if (!sock)
return -ENOMEM;
- policy = bpf_task_storage_get(&policy_map, task, NULL, 0);
+ policy = bpf_task_storage_get(&shirudo_task_policy, task, NULL, 0);
if (!policy || !policy->active)
return 0;
sk = sock->sk;
if (!sk)
return -ENOMEM;
active = policy->active;
- if (!bpf_sk_storage_get(&socket_policy_map, sk, &active,
+ if (!bpf_sk_storage_get(&shirudo_sock_policy, sk, &active,
BPF_LOCAL_STORAGE_GET_F_CREATE))
return -ENOMEM;
return 0;
@@ -520,7 +521,7 @@ int BPF_PROG(shirudo_seal_bprm_creds_for_exec, struct linux_binprm *bprm,
if (ret)
return ret;
- policy = bpf_task_storage_get(&policy_map, task, NULL,
+ policy = bpf_task_storage_get(&shirudo_task_policy, task, NULL,
BPF_LOCAL_STORAGE_GET_F_CREATE);
if (!policy)
return -ENOMEM;
@@ -562,7 +563,7 @@ int BPF_PROG(shirudo_seal_bprm_check_security,
return -EACCES;
if (len == sizeof(value))
__builtin_memcpy(&value, scratch->target, sizeof(value));
- policy = bpf_task_storage_get(&policy_map, task, NULL, 0);
+ policy = bpf_task_storage_get(&shirudo_task_policy, task, NULL, 0);
if (!policy)
return -ENOMEM;
policy->candidate |= value;
diff --git a/builtin-upatch.c b/builtin-upatch.c
index e9fbf055..6166faad 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -2086,10 +2086,10 @@ static int __upatch_apply(const char *path, bool verify_only,
2 * sizeof(__u64),
BPF_F_NO_PREALLOC);
if (policy_map_fd < 0) {
- pr_err("upatch load: open policy_map: %s",
+ pr_err("upatch load: open shirudo_task_policy: %s",
strerror(-policy_map_fd));
rep_fail(rep, "payload_load", "unknown", -policy_map_fd,
- "policy_map binding failed");
+ "shirudo_task_policy binding failed");
ret = 1;
goto out;
}
@@ -2100,10 +2100,10 @@ static int __upatch_apply(const char *path, bool verify_only,
if (socket_policy_map_fd < 0) {
int err = -socket_policy_map_fd;
- pr_err("upatch load: open socket_policy_map: %s",
+ pr_err("upatch load: open shirudo_sock_policy: %s",
strerror(err));
rep_fail(rep, "payload_load", "unknown", err,
- "socket_policy_map binding failed");
+ "shirudo_sock_policy binding failed");
close(policy_map_fd);
policy_map_fd = -1;
ret = 1;
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 c422e795..376f2754 100644
--- a/testing/fixtures/policy-exec-graph/policy-exec-graph.bpf.c
+++ b/testing/fixtures/policy-exec-graph/policy-exec-graph.bpf.c
@@ -57,7 +57,7 @@ int BPF_PROG(shirudo_test_policy_exec_graph,
return -13;
if (len == sizeof(scratch->target))
target = scratch->target;
- policy = bpf_task_storage_get(&policy_map, task, NULL, 0);
+ policy = bpf_task_storage_get(&shirudo_task_policy, task, NULL, 0);
if (!policy)
return -13;
if ((!policy->active && (target == 0 || target == 1)) ||
@@ -94,7 +94,7 @@ int BPF_PROG(shirudo_test_policy_socket_graph, struct socket *sock,
sk = sock->sk;
if (!sk)
return -13;
- socket_policy = bpf_sk_storage_get(&socket_policy_map, sk, NULL, 0);
+ socket_policy = bpf_sk_storage_get(&shirudo_sock_policy, sk, NULL, 0);
if (!socket_policy)
return -13;
if (*socket_policy & 16)
diff --git a/testing/fixtures/policy-labels/policy-labels.bpf.c b/testing/fixtures/policy-labels/policy-labels.bpf.c
index f6508cb6..b77e7386 100644
--- a/testing/fixtures/policy-labels/policy-labels.bpf.c
+++ b/testing/fixtures/policy-labels/policy-labels.bpf.c
@@ -19,8 +19,8 @@ int BPF_PROG(shirudo_test_policy_verdict, struct linux_binprm *bprm, int ret)
if (ret)
return ret;
- policy = bpf_task_storage_get(&policy_map, bpf_get_current_task_btf(),
- NULL, 0);
+ policy = bpf_task_storage_get(&shirudo_task_policy,
+ bpf_get_current_task_btf(), NULL, 0);
return policy && (policy->candidate & 1) ? -13 : 0;
}
@@ -37,9 +37,9 @@ int BPF_PROG(shirudo_test_socket_policy_verdict, struct socket *sock,
sk = sock->sk;
if (!sk)
return 0;
- socket_policy = bpf_sk_storage_get(&socket_policy_map, sk, NULL, 0);
- policy = bpf_task_storage_get(&policy_map, bpf_get_current_task_btf(),
- NULL, 0);
+ socket_policy = bpf_sk_storage_get(&shirudo_sock_policy, sk, NULL, 0);
+ policy = bpf_task_storage_get(&shirudo_task_policy,
+ bpf_get_current_task_btf(), NULL, 0);
return (socket_policy && (*socket_policy & 16)) ||
(policy && (policy->active & 16)) ? -13 : 0;
}
diff --git a/tools/shirudo-build/package.c b/tools/shirudo-build/package.c
index 719b5dc0..1b3a2344 100644
--- a/tools/shirudo-build/package.c
+++ b/tools/shirudo-build/package.c
@@ -1775,8 +1775,8 @@ int build_package_load(const char *bpf_o, const char *src_path,
{
__u32 label_len = 0, policy_map_idx = 0, socket_policy_map_idx = 0;
struct upatch_policy_label_header *label_blob = NULL;
- struct bpf_map *map, *policy_map, *socket_policy_map;
struct upatch_policy_label_entry *label_entries;
+ struct bpf_map *map, *task_map, *sock_map;
int handler_ids[2] = {-1, -1};
struct bpf_object *obj;
__u32 map_idx = 0;
@@ -1800,46 +1800,47 @@ int build_package_load(const char *bpf_o, const char *src_path,
return err;
}
if (nr_policies) {
- policy_map = bpf_object__find_map_by_name(obj, "policy_map");
- socket_policy_map =
- bpf_object__find_map_by_name(obj, "socket_policy_map");
- if (!policy_map ||
- bpf_map__type(policy_map) != BPF_MAP_TYPE_TASK_STORAGE ||
- bpf_map__key_size(policy_map) != sizeof(__s32) ||
- bpf_map__value_size(policy_map) != 2 * sizeof(__u64) ||
- bpf_map__map_flags(policy_map) != BPF_F_NO_PREALLOC) {
- pr_err("policy labels require compatible policy_map task storage");
+ task_map = bpf_object__find_map_by_name(obj,
+ "shirudo_task_policy");
+ sock_map = bpf_object__find_map_by_name(obj,
+ "shirudo_sock_policy");
+ if (!task_map ||
+ bpf_map__type(task_map) != BPF_MAP_TYPE_TASK_STORAGE ||
+ bpf_map__key_size(task_map) != sizeof(__s32) ||
+ bpf_map__value_size(task_map) != 2 * sizeof(__u64) ||
+ bpf_map__map_flags(task_map) != BPF_F_NO_PREALLOC) {
+ pr_err("policy labels require a compatible shirudo_task_policy map");
err = -EINVAL;
goto out;
}
- if (!socket_policy_map ||
- bpf_map__type(socket_policy_map) != BPF_MAP_TYPE_SK_STORAGE ||
- bpf_map__key_size(socket_policy_map) != sizeof(__s32) ||
- bpf_map__value_size(socket_policy_map) != sizeof(__u64) ||
- bpf_map__map_flags(socket_policy_map) !=
+ if (!sock_map ||
+ bpf_map__type(sock_map) != BPF_MAP_TYPE_SK_STORAGE ||
+ bpf_map__key_size(sock_map) != sizeof(__s32) ||
+ bpf_map__value_size(sock_map) != sizeof(__u64) ||
+ bpf_map__map_flags(sock_map) !=
(BPF_F_NO_PREALLOC | BPF_F_CLONE)) {
- pr_err("policy labels require compatible socket_policy_map storage");
+ pr_err("policy labels require a compatible shirudo_sock_policy map");
err = -EINVAL;
goto out;
}
bpf_object__for_each_map(map, obj) {
- if (map == policy_map)
+ if (map == task_map)
break;
map_idx++;
}
- if (map_idx >= UPATCH_MAPS_MAX || map != policy_map) {
+ if (map_idx >= UPATCH_MAPS_MAX || map != task_map) {
err = -E2BIG;
goto out;
}
policy_map_idx = map_idx;
map_idx = 0;
bpf_object__for_each_map(map, obj) {
- if (map == socket_policy_map)
+ if (map == sock_map)
break;
map_idx++;
}
if (map_idx >= UPATCH_MAPS_MAX ||
- map != socket_policy_map || map_idx == policy_map_idx) {
+ map != sock_map || map_idx == policy_map_idx) {
err = -E2BIG;
goto out;
}
diff --git a/util/image_guards.c b/util/image_guards.c
index 4773e064..a648f167 100644
--- a/util/image_guards.c
+++ b/util/image_guards.c
@@ -146,12 +146,12 @@ const struct guard_map shirudo_guard_maps[GUARD_MAP_COUNT] = {
sizeof(struct task_authority), 0, BPF_F_NO_PREALLOC,
},
[GUARD_POLICY] = {
- "policy_map", POLICY_PIN,
+ "shirudo_task_policy", POLICY_PIN,
BPF_MAP_TYPE_TASK_STORAGE, sizeof(__u32),
sizeof(struct task_policy), 0, BPF_F_NO_PREALLOC,
},
[GUARD_SOCKET_POLICY] = {
- "socket_policy_map", SOCKET_POLICY_PIN,
+ "shirudo_sock_policy", SOCKET_POLICY_PIN,
BPF_MAP_TYPE_SK_STORAGE, sizeof(__u32), sizeof(__u64), 0,
BPF_F_NO_PREALLOC | BPF_F_CLONE,
},
diff --git a/util/paths.h b/util/paths.h
index 59df93ff..1b8b7db2 100644
--- a/util/paths.h
+++ b/util/paths.h
@@ -99,10 +99,10 @@
#define BPFFS_UPATCHES_DIR BPFFS_DIR "/upatches"
#define IDENTITY_PIN BPFFS_DIR "/identity"
#define TAMPER_PIN BPFFS_DIR "/tamper"
-#define POLICY_PIN BPFFS_DIR "/policy_map"
+#define POLICY_PIN BPFFS_DIR "/task_policy"
#define SEAL_SOCKET_POST_CREATE_PIN \
BPFFS_DIR "/seal_socket_post_create_link"
-#define SOCKET_POLICY_PIN BPFFS_DIR "/socket_policy_map"
+#define SOCKET_POLICY_PIN BPFFS_DIR "/socket_policy"
#define RUNTIME_DIR RUN_DIR "/runtime"
#define CONFIG_IMAGE_DIR RUN_DIR "/config"