Skip to content

eBPF-based security platform

bpf: scope pin deletion to one open upatch directory

KP Singh14cfe942ae08
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index 24acb9be..a79d0dfa 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -837,6 +837,13 @@ signed config image.
reached through a link another user owns, or an auth file through
a directory others can write that holds a link, is refused with
its message before any request
+ * - ``t7115-bpm-package-uninstall``
+ - BPM installs a signed upatch from the fixture registry. With the
+ private bpffs bound over the package or its directives, or a
+ sealed directory bound over the directives, in a mount namespace
+ of root's, uninstall refuses and the pins, the archive and the
+ state stay. Without a bind it detaches the link and retires the
+ package tree, archive and state.
``otel`` (8)
~~~~~~~~~~~~
diff --git a/Documentation/internals/enforcement.rst b/Documentation/internals/enforcement.rst
index 847f9cf6..40f206d7 100644
--- a/Documentation/internals/enforcement.rst
+++ b/Documentation/internals/enforcement.rst
@@ -55,7 +55,8 @@ The objects share eight maps, which ``init`` hands from ``bpf2`` to
* - ``shirudo_bpffs_sb``
- ``identity``
- The record ``init`` freezes: device numbers of the private bpffs
- and of ``/run/shirudo``, the runtime root hash, the ``.bpf``
+ and of ``/run/shirudo``, the state root device and inode, the runtime
+ root hash, the ``.bpf``
keyring serial and kind, the serials of the enrolled keys, the
``.dm-verity`` keyring and key serials, the NV index, the NV
writer's public modulus and seed, and the ECC endorsement key
@@ -66,6 +67,11 @@ The objects share eight maps, which ``init`` hands from ``bpf2`` to
* - ``shirudo_tasks``
- ``task_authority``
- Task storage with each task's mark and exec candidate.
+ * - ``shirudo_unlink_grant``
+ - ``unlink_grant``
+ - Task storage for the inode number of one open upatch directory
+ in the private bpffs. A grant lasts until release, removal of
+ that directory, successful exec or task exit.
* - ``shirudo_task_policy``
- ``task_policy``
- Task storage with committed policy bits and the exec candidate.
@@ -380,9 +386,13 @@ Hooks in bpf2
it, which the kernel would detach or move in every namespace.
- ``EPERM``. In the bpffs: ``PinUnlink``, ``PinEntry``
(mkdir, symlink, link), ``PinRename``, ``PinXattr``. A mount
- point: ``BpffsUmountAbove``. Rmdir and ``/run/shirudo``
- uncounted
- - Closed for those two file systems.
+ point: ``BpffsUmountAbove``. Rmdir by a runtime task outside its
+ grant counts as ``PinUnlink``.
+ - On the private bpffs a runtime task also needs a per-task grant
+ to unlink or remove an upatch directory or its children. The
+ ioctl hooks issue and release the grant on the open directory.
+ Removing that directory or committing an exec clears it.
+ Renames are refused after bootstrap.
* - ``lsm/sb_umount``
- To every caller: unmounting the bpffs, an unmount whose subtree or
propagation reaches the recorded bpffs mount, unmounting
diff --git a/Documentation/reference/files.rst b/Documentation/reference/files.rst
index d12dcb33..fe5373bc 100644
--- a/Documentation/reference/files.rst
+++ b/Documentation/reference/files.rst
@@ -383,6 +383,8 @@ by ``BPF_OBJ_GET`` (``ObjGet``). Directories stay listable.
:doc:`/security/integrity-counters`.
* - ``task_authority``, ``config_roots``
- Task storage maps of runtime authority and expected config roots.
+ * - ``unlink_grant``
+ - Per-task permission to remove pins in one open upatch directory.
* - ``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
diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rst
index 4cc46cc4..ae01f771 100644
--- a/Documentation/security/threat-model.rst
+++ b/Documentation/security/threat-model.rst
@@ -627,12 +627,23 @@ authority (``PerfAttach``).
In the private bpffs, unlink, rename, mkdir, symlink, hard link, rmdir
and xattr changes need runtime authority (``PinUnlink``, ``PinRename``,
-``PinEntry``, ``PinXattr``; rmdir is refused without a counter). The
+``PinEntry``, ``PinXattr``). The
VFS removes a rename's victim without asking ``inode_unlink``, so the
rename hook checks both directories. A symbolic link in place of a pin
directory would send the next load's pins into a bpffs of root's, and a
hard link to a pin would keep a link alive past its unlink.
+After bootstrap, even a trusted task needs a deletion grant for one
+upatch's directory. The native and compat ioctl hooks take the directory
+from an open file description on the recorded private bpffs. The grant
+is task-local. The caller holds the directory open, keeping its inode
+number unique on that superblock, until it explicitly releases the grant.
+Fork starts without a grant and successful exec clears it. Removing
+the directory consumes it. No grant names a core pin or the upatches
+root. Renaming a pin after bootstrap is refused. This protects against
+unintended cleanup by trusted code. Signed unload verification, the
+payload comparison and measurement still take place in userspace.
+
The pins live as long as the bpffs superblock, which goes with its last
mount. ``lsm/sb_umount``, ``lsm/move_mount``, ``lsm/sb_mount`` and
``lsm/sb_remount`` refuse every caller, shirudo included, an unmount, a
diff --git a/Makefile.shirudo b/Makefile.shirudo
index 3b99433e..cfb068e7 100644
--- a/Makefile.shirudo
+++ b/Makefile.shirudo
@@ -498,6 +498,8 @@ bpf/%.bpf.o: bpf/%.c $(VMLINUX_H) $(BPF_LIBBPF_HEADERS) \
-I$(BPF_UAPI_INCLUDE) \
-c $< -o $@
+bpf/bpf2.bpf.o build/unit/identity: include/shirudo/pin_grant.h
+
# ----- version_id ------------------------------------------------
# Regenerated every build; cheap (one sha256sum invocation).
diff --git a/bpf/bpf2.c b/bpf/bpf2.c
index 655841bc..5ecea018 100644
--- a/bpf/bpf2.c
+++ b/bpf/bpf2.c
@@ -8,6 +8,7 @@
*/
#include "verity.h"
#include <bpf/bpf_endian.h>
+#include <shirudo/pin_grant.h>
/*
* BPF mutations require a task marked by successful exec from the runtime
@@ -388,14 +389,78 @@ deny:
return shirudo_tamper_deny(TAMPER_BPFFS_UMOUNT_ABOVE, -EPERM);
}
+/* Core pins live outside the per-upatch directories and cannot be granted. */
+static __always_inline bool upatch_directory(struct dentry *d)
+{
+ struct dentry *parent = BPF_CORE_READ(d, d_parent);
+ struct dentry *root = BPF_CORE_READ(d, d_sb, s_root);
+ char name[sizeof("upatches")];
+
+ if ((BPF_CORE_READ(d, d_inode, i_mode) & S_IFMT) != S_IFDIR ||
+ d == parent || parent == root || BPF_CORE_READ(parent, d_parent) != root ||
+ BPF_CORE_READ(parent, d_name.len) != sizeof("upatches") - 1)
+ return false;
+ if (bpf_probe_read_kernel_str(name, sizeof(name), BPF_CORE_READ(parent, d_name.name)) !=
+ sizeof(name))
+ return false;
+ return !bpf_strncmp(name, sizeof(name), "upatches");
+}
+
+static __always_inline int pin_grant_ioctl(struct file *file, unsigned int cmd)
+{
+ struct task_struct *task = bpf_get_current_task_btf();
+ struct sb_id *id = shirudo_policy();
+ struct dentry *d;
+ __u64 *ino;
+
+ if (!id || !id->sb_dev || BPF_CORE_READ(file, f_inode, i_sb, s_dev) != id->sb_dev ||
+ !shirudo_task_is_self(id))
+ return -EPERM;
+ if (cmd == SHIRUDO_PIN_GRANT_END) {
+ bpf_task_storage_delete(&shirudo_unlink_grant, task);
+ return -SHIRUDO_PIN_GRANT_ACK;
+ }
+ d = BPF_CORE_READ(file, f_path.dentry);
+ if (!upatch_directory(d))
+ return -EPERM;
+ ino = bpf_task_storage_get(&shirudo_unlink_grant, task, NULL,
+ BPF_LOCAL_STORAGE_GET_F_CREATE);
+ if (!ino)
+ return -ENOMEM;
+ *ino = BPF_CORE_READ(file, f_inode, i_ino);
+ return -SHIRUDO_PIN_GRANT_ACK;
+}
+
+static __always_inline int pin_delete(struct inode *dir, struct dentry *d, bool rmdir)
+{
+ struct task_struct *task = bpf_get_current_task_btf();
+ __u32 dev = BPF_CORE_READ(dir, i_sb, s_dev);
+ struct sb_id *id = shirudo_policy();
+ enum pin_grant_action action;
+ __u64 *grant;
+ int ret;
+
+ ret = shirudo_bpffs_guard(dev, rmdir ? TAMPER_MAX : TAMPER_PIN_UNLINK);
+ if (ret || !id || !id->sb_dev || dev != id->sb_dev || shirudo_bootstrap_task())
+ return ret;
+ grant = bpf_task_storage_get(&shirudo_unlink_grant, task, NULL, 0);
+ action = pin_grant_delete(grant ? *grant : 0, BPF_CORE_READ(d, d_inode, i_ino),
+ BPF_CORE_READ(dir, i_ino),
+ BPF_CORE_READ(d, d_parent, d_parent, d_inode, i_ino), rmdir);
+ if (action == PIN_GRANT_CONSUME)
+ bpf_task_storage_delete(&shirudo_unlink_grant, task);
+ if (action != PIN_GRANT_DENY)
+ return 0;
+ return shirudo_tamper_deny(TAMPER_PIN_UNLINK, -EPERM);
+}
+
SEC("lsm/inode_unlink")
int BPF_PROG(shirudo_lsm_inode_unlink, struct inode *dir,
struct dentry *dentry, int ret)
{
if (ret)
return ret;
- ret = shirudo_bpffs_guard(BPF_CORE_READ(dir, i_sb, s_dev),
- TAMPER_PIN_UNLINK);
+ ret = pin_delete(dir, dentry, false);
return ret ? ret : shirudo_mountpoint_guard(dentry);
}
@@ -405,8 +470,7 @@ int BPF_PROG(shirudo_lsm_inode_rmdir, struct inode *dir,
{
if (ret)
return ret;
- ret = shirudo_bpffs_guard(BPF_CORE_READ(dir, i_sb, s_dev),
- TAMPER_MAX);
+ ret = pin_delete(dir, dentry, true);
return ret ? ret : shirudo_mountpoint_guard(dentry);
}
@@ -559,9 +623,17 @@ int BPF_PROG(shirudo_lsm_inode_rename, struct inode *old_dir,
struct dentry *old_dentry, struct inode *new_dir,
struct dentry *new_dentry, int ret)
{
+ struct sb_id *id;
+ __u32 dev;
+
if (ret)
return ret;
- ret = shirudo_bpffs_guard(BPF_CORE_READ(old_dir, i_sb, s_dev),
+ id = shirudo_policy();
+ dev = BPF_CORE_READ(old_dir, i_sb, s_dev);
+ /* Pin lifecycle operations have no rename step. */
+ if (id && id->sb_dev && id->sb_dev == dev && !shirudo_bootstrap_task())
+ return shirudo_tamper_deny(TAMPER_PIN_RENAME, -EPERM);
+ ret = shirudo_bpffs_guard(dev,
TAMPER_PIN_RENAME);
if (!ret)
ret = shirudo_bpffs_guard(BPF_CORE_READ(new_dir, i_sb, s_dev),
@@ -1114,6 +1186,8 @@ static __always_inline int shirudo_ioctl(struct file *file, unsigned int cmd,
{
if (ret)
return ret;
+ if (cmd == SHIRUDO_PIN_GRANT_BEGIN || cmd == SHIRUDO_PIN_GRANT_END)
+ return pin_grant_ioctl(file, cmd);
if (cmd == PERF_EVENT_IOC_SET_BPF)
return shirudo_self_or_deny(TAMPER_PERF_ATTACH);
if (xfs_attrmulti(file, cmd))
diff --git a/bpf/lib/lsm.h b/bpf/lib/lsm.h
index b7716cc2..75b4e5a1 100644
--- a/bpf/lib/lsm.h
+++ b/bpf/lib/lsm.h
@@ -52,6 +52,14 @@ struct {
__type(value, struct task_authority);
} shirudo_tasks SEC(".maps");
+/* The caller holds this private bpffs directory open until it drops the grant. */
+struct {
+ __uint(type, BPF_MAP_TYPE_TASK_STORAGE);
+ __uint(map_flags, BPF_F_NO_PREALLOC);
+ __type(key, int);
+ __type(value, __u64);
+} shirudo_unlink_grant SEC(".maps");
+
static __always_inline struct sb_id *shirudo_policy(void)
{
__u32 zero = 0;
diff --git a/bpf/seal.c b/bpf/seal.c
index 53856d68..fdb48e5e 100644
--- a/bpf/seal.c
+++ b/bpf/seal.c
@@ -184,6 +184,7 @@ void BPF_PROG(shirudo_seal_bprm_committed_creds,
struct task_authority *authority;
struct task_policy *policy;
+ bpf_task_storage_delete(&shirudo_unlink_grant, task);
policy = bpf_task_storage_get(&shirudo_task_policy, task, NULL, 0);
if (policy) {
policy->active = policy->candidate;
diff --git a/builtin-init.c b/builtin-init.c
index de957b83..ceaaa692 100644
--- a/builtin-init.c
+++ b/builtin-init.c
@@ -867,6 +867,7 @@ static const enum guard_map_index map_release_order[] = {
GUARD_IDENTITY,
GUARD_TAMPER,
GUARD_INTEGRITY,
+ GUARD_UNLINK_GRANT,
GUARD_TASKS,
GUARD_POLICY,
GUARD_SOCKET_POLICY,
diff --git a/builtin-upatch.c b/builtin-upatch.c
index fc5584b2..0c0266c5 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -17,6 +17,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/file.h>
+#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
@@ -33,6 +34,7 @@
#include <bpf/btf.h>
#include <bpf/libbpf.h>
+#include <shirudo/enforcement.h>
#include <shirudo/misc.h>
#include <shirudo/overflow.h>
#include <shirudo/string.h>
@@ -1610,6 +1612,42 @@ static int open_upatch_pin_dir(const char *name)
return fd;
}
+static int pin_grant_request(int fd, __u32 command)
+{
+ int ret = ioctl(fd, command, 0);
+
+ if (ret < 0 && errno == SHIRUDO_PIN_GRANT_ACK)
+ return 0;
+ return ret < 0 ? -errno : -EPROTO;
+}
+
+/* Holding fd prevents inode reuse until the task no longer has authority. */
+static int pin_grant_open(const char *name)
+{
+ int fd, ret;
+
+ fd = open_upatch_pin_dir(name);
+ if (fd < 0)
+ return fd;
+ ret = pin_grant_request(fd, SHIRUDO_PIN_GRANT_BEGIN);
+ if (ret) {
+ close(fd);
+ return ret;
+ }
+ return fd;
+}
+
+static void pin_grant_close(int *fd)
+{
+ if (*fd < 0)
+ return;
+ if (pin_grant_request(*fd, SHIRUDO_PIN_GRANT_END)) {
+ pr_err("upatch: cannot release pin deletion authority; terminating");
+ _exit(EXIT_FAILURE);
+ }
+ close(*fd);
+}
+
/*
* A pin a load left when it died before its link is bound to maps nothing
* reaches any more: replace it.
@@ -1776,6 +1814,7 @@ static int attach_and_pin_progs(const struct loader_ctx *cx,
const struct prog_spec *specs)
{
char dir[PATH_MAX], serializers_dir[PATH_MAX + 16];
+ int grant __cleanup(pin_grant_close) = -1;
bool made_dir = false, made_serializers = false;
__u32 i, attach_count = 0, attach_seen = 0;
struct xdp_device *devices = NULL;
@@ -1822,6 +1861,11 @@ static int attach_and_pin_progs(const struct loader_ctx *cx,
pr_err("mkdir %s: %s", dir, strerror(-ret));
goto out;
}
+ grant = pin_grant_open(name);
+ if (grant < 0) {
+ ret = grant;
+ goto out;
+ }
count_attach_progs(specs, nr_progs, &attach_count);
for (i = 0; i < nr_progs; i++) {
@@ -3325,6 +3369,7 @@ static int upatch_pinned(const char *name)
/* Unlinking the link pin drops its last reference, which detaches. */
static int remove_pin_dir(const char *name)
{
+ int grant __cleanup(pin_grant_close) = -1;
char dir[PATH_MAX], maps_dir[PATH_MAX + 8];
char serializers_dir[PATH_MAX + 16];
struct stat st;
@@ -3337,8 +3382,9 @@ static int remove_pin_dir(const char *name)
if (strsprintf(serializers_dir, sizeof(serializers_dir),
"%s/serializers", dir) < 0)
return -ENAMETOOLONG;
- if (stat(dir, &st) != 0)
- return -errno;
+ grant = pin_grant_open(name);
+ if (grant < 0)
+ return grant;
if (stat(maps_dir, &st) == 0) {
ret = wipe_dir_flat(maps_dir);
if (ret)
@@ -5097,6 +5143,7 @@ static int reconcile_collect(struct xdp_work **out, size_t *count,
}
struct link_scan {
+ const char *name;
__u32 next;
bool dead;
bool collect;
@@ -5111,6 +5158,12 @@ static int scan_link(__u32 index, const char *pin,
if (info->type == BPF_LINK_TYPE_XDP && !info->xdp.ifindex) {
scan->dead = true;
if (scan->collect) {
+ int grant __cleanup(pin_grant_close) = -1;
+
+ grant = pin_grant_open(scan->name);
+
+ if (grant < 0)
+ return grant;
if (unlink(pin))
return -errno;
pr_info("XDP: removed %s, its device is gone", pin);
@@ -5220,7 +5273,7 @@ static int reconcile_apply(const struct xdp_work *w,
const struct xdp_device *devices, size_t count,
struct op_report *rep)
{
- struct link_scan scan = { .collect = true };
+ struct link_scan scan = { .name = w->name, .collect = true };
__u8 payload[UPATCH_PAYLOAD_HASH_LEN];
bool held, needed = false;
struct upatch again;
diff --git a/include/shirudo/enforcement.h b/include/shirudo/enforcement.h
index 5d45830a..84308fb3 100644
--- a/include/shirudo/enforcement.h
+++ b/include/shirudo/enforcement.h
@@ -7,6 +7,11 @@
#define PR_GET_ENFORCEMENT 0x53520001
#define PR_ENFORCING_ERR 1002
+/* Private bpffs directory requests acknowledged by the file_ioctl LSM. */
+#define SHIRUDO_PIN_GRANT_BEGIN 0x53520002u
+#define SHIRUDO_PIN_GRANT_END 0x53520003u
+#define SHIRUDO_PIN_GRANT_ACK 1003
+
/*
* vmlinux.h carries no UAPI macros, so BPF code takes the ioctl number
* from here: _IOW('$', 8, __u32) on every supported architecture.
diff --git a/include/shirudo/pin_grant.h b/include/shirudo/pin_grant.h
new file mode 100644
index 00000000..647218e7
--- /dev/null
+++ b/include/shirudo/pin_grant.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
+/* Copyright (c) 2026 Authors of shirudo */
+
+#ifndef SHIRUDO_PIN_GRANT_H
+#define SHIRUDO_PIN_GRANT_H
+
+/* The caller already checked runtime authority and the private superblock. */
+enum pin_grant_action {
+ PIN_GRANT_DENY,
+ PIN_GRANT_ALLOW,
+ PIN_GRANT_CONSUME,
+};
+
+static __always_inline enum pin_grant_action
+pin_grant_delete(__u64 granted, __u64 target, __u64 parent, __u64 grandparent,
+ bool rmdir)
+{
+ if (!granted)
+ return PIN_GRANT_DENY;
+ if (rmdir && granted == target)
+ return PIN_GRANT_CONSUME;
+ if (granted == parent || granted == grandparent)
+ return PIN_GRANT_ALLOW;
+ return PIN_GRANT_DENY;
+}
+
+#endif /* SHIRUDO_PIN_GRANT_H */
diff --git a/testing/functional/bpm/t7115-bpm-package-uninstall.sh b/testing/functional/bpm/t7115-bpm-package-uninstall.sh
new file mode 100755
index 00000000..d6b109ff
--- /dev/null
+++ b/testing/functional/bpm/t7115-bpm-package-uninstall.sh
@@ -0,0 +1,90 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+
+cd "$(dirname "$0")/../.."
+. ./integration-lib.sh
+target_guard
+
+WORK=$(mktemp -d)
+PKG=uninstall-fixture
+NAME=shirudo-test-lifecycle
+VERSION=1.0.0
+ARCHIVE=$PKG-$VERSION
+TREE=$WORK/$ARCHIVE
+REPO=$WORK/registry/test/$PKG
+STORE=/var/lib/shirudo/bpm/packages/$PKG
+PIN=/run/shirudo/bpffs/upatches/$NAME/link
+TREE_SERVER_PID=
+
+cleanup() {
+ tree_registry_stop
+ rm -rf "$WORK"
+}
+trap cleanup EXIT
+
+mkdir -p "$TREE/upatches" "$REPO/manifests" "$REPO/blobs"
+cp /var/lib/shirudo/keys/cert.der "$TREE/"
+cp "$SHIRUDO_TEST_FIXTURES_DIR/$NAME.upatch" \
+ "$SHIRUDO_TEST_FIXTURES_DIR/$NAME.unload.upatch" "$TREE/upatches/"
+printf '[package]\nname = "%s"\n' "$PKG" >"$TREE/Beefile"
+tar --format=ustar -czf "$WORK/package.bee" -C "$WORK" "$ARCHIVE"
+digest=sha256:$(sha256sum "$WORK/package.bee" | cut -d' ' -f1)
+size=$(wc -c <"$WORK/package.bee")
+mv "$WORK/package.bee" "$REPO/blobs/$digest"
+cat >"$REPO/manifests/$VERSION" <<EOF
+{"schemaVersion":2,"layers":[{"mediaType":"application/vnd.shirudo.bpm.package.v1+gzip",
+"digest":"$digest","size":$size}]}
+EOF
+
+tree_registry_start "$WORK/registry" "$WORK"
+export BPM_OCI_SCHEME=http NO_PROXY=127.0.0.1 no_proxy=127.0.0.1
+
+test_expect_success 'install records the version and attaches its signed upatch' '
+ "$SHIRUDO_BIN" bpm install "oci://127.0.0.1:5443/test/$PKG:$VERSION" &&
+ test -e "$PIN" &&
+ test -f "$STORE/$ARCHIVE.bee" &&
+ "$SHIRUDO_BIN" bpm list | grep -q "$PKG"
+'
+
+# Root binds another directory over the directives, or over the package,
+# in a mount namespace of its own. Uninstall then finds no directive to
+# apply and must not go on to delete what the bind shows instead.
+RUNTIME=$(runtime_binary)
+bound_uninstall() {
+ unshare -m sh -c "mount --bind \"$1\" \"$2\" &&
+ ! \"$RUNTIME\" bpm uninstall \"$PKG\"" >"$WORK/out" 2>&1
+}
+still_installed() {
+ test -e "$PIN" &&
+ test -e /run/shirudo/bpffs/lsm_link &&
+ test -s "/var/lib/shirudo/upatches/$NAME.upatch" &&
+ test -s "$STORE/$VERSION/upatches/$NAME.unload.upatch" &&
+ test -f "$STORE/$ARCHIVE.bee" &&
+ "$SHIRUDO_BIN" bpm list | grep -q "$PKG"
+}
+
+test_expect_success 'uninstall refuses the private bpffs bound over the directives' '
+ bound_uninstall /run/shirudo/bpffs "$STORE/$VERSION/upatches" &&
+ still_installed
+'
+
+test_expect_success 'and bound over the package directory' '
+ bound_uninstall /run/shirudo/bpffs "$STORE" &&
+ still_installed
+'
+
+test_expect_success 'a sealed directory bound over the directives is no empty package' '
+ bound_uninstall /var/lib/shirudo/upatches "$STORE/$VERSION/upatches" &&
+ still_installed
+'
+
+test_expect_success 'uninstall detaches and removes the package, archive and state' '
+ "$SHIRUDO_BIN" bpm uninstall "$PKG" &&
+ test ! -e "$PIN" &&
+ test ! -e "$STORE" &&
+ "$SHIRUDO_BIN" bpm list >"$WORK/list" &&
+ ! grep -q "$PKG" "$WORK/list"
+'
+
+test_done
diff --git a/testing/unit/identity.c b/testing/unit/identity.c
index 8e53fba6..2c8bb744 100644
--- a/testing/unit/identity.c
+++ b/testing/unit/identity.c
@@ -10,6 +10,7 @@
#include "identity.h"
#include "unit.h"
+#include <shirudo/pin_grant.h>
static void kernel_name_is_the_start_of_a_long_one(void)
{
@@ -72,7 +73,22 @@ static void state_root_requires_the_recorded_directory(void)
ASSERT_EQ(rmdir(path), 0);
}
+static void unlink_grant_only_covers_one_directory(void)
+{
+ enum { root = 1, upatches, selected, sibling, maps, pin };
+
+ EXPECT_EQ(pin_grant_delete(0, pin, selected, upatches, false), PIN_GRANT_DENY);
+ EXPECT_EQ(pin_grant_delete(selected, pin, sibling, upatches, false), PIN_GRANT_DENY);
+ EXPECT_EQ(pin_grant_delete(selected, pin, root, root, false), PIN_GRANT_DENY);
+ EXPECT_EQ(pin_grant_delete(selected, upatches, root, root, true), PIN_GRANT_DENY);
+ EXPECT_EQ(pin_grant_delete(selected, pin, selected, upatches, false), PIN_GRANT_ALLOW);
+ EXPECT_EQ(pin_grant_delete(selected, pin, maps, selected, false), PIN_GRANT_ALLOW);
+ EXPECT_EQ(pin_grant_delete(selected, maps, selected, upatches, true), PIN_GRANT_ALLOW);
+ EXPECT_EQ(pin_grant_delete(selected, selected, upatches, root, true), PIN_GRANT_CONSUME);
+}
+
static const struct unit_case cases[] = {
+ UNIT_CASE(unlink_grant_only_covers_one_directory),
UNIT_CASE(state_root_requires_the_recorded_directory),
UNIT_CASE(kernel_name_is_the_start_of_a_long_one),
UNIT_CASE(short_name_is_the_whole_one),
diff --git a/util/identity.c b/util/identity.c
index 115ef676..2eb60d19 100644
--- a/util/identity.c
+++ b/util/identity.c
@@ -38,6 +38,10 @@ const struct guard_map shirudo_guard_maps[GUARD_MAP_COUNT] = {
BPF_MAP_TYPE_TASK_STORAGE, sizeof(__u32),
sizeof(struct task_authority), 0, BPF_F_NO_PREALLOC,
},
+ [GUARD_UNLINK_GRANT] = {
+ "shirudo_unlink_grant", BPFFS_DIR "/unlink_grant",
+ BPF_MAP_TYPE_TASK_STORAGE, sizeof(__u32), sizeof(__u64), 0, BPF_F_NO_PREALLOC,
+ },
[GUARD_POLICY] = {
"shirudo_task_policy", POLICY_PIN,
BPF_MAP_TYPE_TASK_STORAGE, sizeof(__u32),
diff --git a/util/identity.h b/util/identity.h
index 6052ae4d..88b77520 100644
--- a/util/identity.h
+++ b/util/identity.h
@@ -96,6 +96,7 @@ enum guard_map_index {
GUARD_POLICY,
GUARD_SOCKET_POLICY,
GUARD_INTEGRITY,
+ GUARD_UNLINK_GRANT,
GUARD_MAP_COUNT,
};