eBPF-based security platform
bpf: revert mount-tree checks that break systemd startup
KP Singh09f298302231
diff --git a/Documentation/architecture.rst b/Documentation/architecture.rstindex fea856f9..02289d84 100644--- a/Documentation/architecture.rst+++ b/Documentation/architecture.rst@@ -295,9 +295,7 @@ unlinking a key is ``shirudo keys revoke`` and nothing else.``lsm/sb_umount``, ``lsm/move_mount``,``lsm/sb_mount`` and ``lsm/sb_remount`` deny unconditionally, for everycaller including shirudo, any unmount, relocation, mount-over or-remount of that superblock, and ``sb_umount`` refuses any mount with-the bpffs beneath it, which a lazy unmount would take down too. This-last set is load-bearing, not+remount of that superblock. This last set is load-bearing, notdefence in depth: shirudo is agentless, the pins are the only thingkeeping the enforcement programs alive, and one ``umount`` wouldotherwise detach everything. Every guard counts what it refuses, bydiff --git a/Documentation/threat-model.rst b/Documentation/threat-model.rstindex 36bc863e..e12fe3ba 100644--- a/Documentation/threat-model.rst+++ b/Documentation/threat-model.rst@@ -129,10 +129,7 @@ T2 Detaching or replacing enforcementdrop its only reference), and ``sb_umount``, ``move_mount``,``sb_mount`` and ``sb_remount`` deny everyone, so neither ``rm``nor ``mv`` nor ``umount`` nor mounting over the directory removes a- pin; ``sb_umount`` also refuses any mount with the bpffs beneath- it, so a lazy unmount of ``/run`` or of a bind of it, which would- take the subtree down with the hook fired for the ancestor alone,- is refused as well. Infrastructure maps are+ pin. Infrastructure maps arefrozen at creation, so even with the LSM gone userspace could notrewrite the identity map. ``lsm/bpf_map`` denies writable map fdsto every process except shirudo; map updates and freezes have the@@ -277,7 +274,7 @@ T10 An attempt that leaves no traceload that is no signed loader, one without a signature, one whosesignature was verified against the wrong kind of keyring or thewrong keyring, a writable map descriptor, a rename of a pin, an- unmount above the bpffs, a write to a sealed file, a ptrace of a+ unmount of the bpffs, a write to a sealed file, a ptrace of ashirudo task, and so on), in a map ``init`` pins and freezes, sothat no task, shirudo included, can reset it from userspace whilethe hooks still add to it. ``shirudo status`` lists the counters@@ -318,20 +315,17 @@ Each of these is known, documented and bounded; none is silent.``CAP_SYS_RESOURCE`` out of untrusted contexts with``CapabilityBoundingSet=`` and container capability profiles.-3. A lazy (``MNT_DETACH``) unmount of an ancestor of- ``/run/shirudo/bpffs`` tears the subtree down and fires- ``sb_umount`` for the ancestor alone, so ``sb_umount`` walks the- mount tree below its target and refuses one that has the bpffs- beneath it, in the caller's own namespace, where a copy of the- bpffs mount sits wherever a propagated unmount would reach the- original. The walk is bounded; a tree it cannot cover is refused.- The cost is that a tree holding a bind of the bpffs cannot be- unmounted by anyone until the boot ends, which nothing legitimate- does. A namespace torn down with its last task frees its copies- without any unmount, and the original mount keeps the superblock.- Mounting over ``/run/shirudo`` hides the pins without- detaching anything: enforcement stays, and every state-changing- command refuses ``lsm_detached`` until the mount is gone.+3. A lazy unmount of a mount above ``/run/shirudo/bpffs``, such as+ ``umount -l /run``, can detach the bpffs with it. The kernel calls+ ``sb_umount`` for the requested parent mount alone, so the direct+ bpffs check does not stop this. Once its last references disappear,+ the pins can be released and enforcement can detach. The mount-tree+ check was reverted because it blocked systemd service startup.+ `Issue 22 <https://github.com/shirudo-dev/shirudo/issues/22>`__ tracks+ keeping the pins alive without depending on a visible mount tree.+ Mounting over ``/run/shirudo`` only hides the pins; it does not release+ them. Enforcement continues, but state-changing commands refuse+ ``lsm_detached`` while their pins are hidden.4. Register denial of service. A process that can open``/dev/tpmrm0`` can extend PCR 9 or the written register withdiff --git a/bpf/bpf2.c b/bpf/bpf2.cindex bddbd99a..08645a4f 100644--- a/bpf/bpf2.c+++ b/bpf/bpf2.c@@ -325,11 +325,8 @@ int BPF_PROG(shirudo_lsm_inode_removexattr, struct mnt_idmap *idmap,* hooks are self-protecting: their own pins live in the bpffs they keep* mounted.*- * A lazy unmount (MNT_DETACH) of a mount above the bpffs, /run or the- * root, takes the subtree down with it and fires sb_umount for the- * ancestor alone, so sb_umount also refuses any mount that has the- * bpffs beneath it. Nothing unmounts /run or the root on a live- * system; switch-root moves /run and never unmounts it.+ * A lazy unmount of a parent such as /run can still detach this bpffs+ * without calling sb_umount for it.*/static __always_inline __u32 shirudo_bpffs_dev(void){@@ -351,81 +348,11 @@ shirudo_deny_bpffs_mount(__u32 sb_dev, enum shirudo_tamper_point point)return shirudo_tamper_deny(point, -EPERM);}-/* The address a trusted pointer holds, as a plain number. */-static __always_inline unsigned long shirudo_ptr_addr(const void *ptr)-{- unsigned long addr = 0;-- bpf_probe_read_kernel(&addr, sizeof(addr), &ptr);- return addr;-}--#define shirudo_mount_of(ptr, member) \- ((struct mount *)((unsigned long)(ptr) - \- bpf_core_field_offset(struct mount, member)))--#define SHIRUDO_MOUNT_WALK_MAX 4096-#define SHIRUDO_MOUNT_DEPTH_MAX 64--/*- * Whether `root` or a mount below it is of the file system `sb_dev`:- * the subtree an unmount of `root` takes down. The walk is over the- * caller's own mount tree, so a copy of the bpffs mount in another- * namespace is found where a propagated unmount would reach it.- * Stackless: down to the first child, else across to the next sibling- * of the nearest ancestor that has one, until the walk is back at- * `root`. A tree the budget cannot cover is taken to hold the bpffs.- */-static __always_inline bool shirudo_mount_tree_has(struct mount *root,- __u32 sb_dev)-{- struct mount *cur = root, *parent;- struct list_head *next;- bool climbed;- int i, j;-- bpf_for(i, 0, SHIRUDO_MOUNT_WALK_MAX) {- if (BPF_CORE_READ(cur, mnt.mnt_sb, s_dev) == sb_dev)- return true;- next = BPF_CORE_READ(cur, mnt_mounts.next);- if (next != &cur->mnt_mounts) {- cur = shirudo_mount_of(next, mnt_child);- continue;- }- climbed = false;- bpf_for(j, 0, SHIRUDO_MOUNT_DEPTH_MAX) {- if (cur == root)- return false;- parent = BPF_CORE_READ(cur, mnt_parent);- next = BPF_CORE_READ(cur, mnt_child.next);- if (next != &parent->mnt_mounts) {- cur = shirudo_mount_of(next, mnt_child);- climbed = true;- break;- }- cur = parent;- }- if (!climbed)- return true;- }- return true;-}-SEC("lsm/sb_umount")int BPF_PROG(shirudo_lsm_sb_umount, struct vfsmount *mnt, int flags){- __u32 bpffs = shirudo_bpffs_dev();- struct mount *target;-- if (!bpffs)- return 0;- if (BPF_CORE_READ(mnt, mnt_sb, s_dev) == bpffs)- return shirudo_tamper_deny(SHIRUDO_TAMPER_BPFFS_UMOUNT, -EPERM);- target = shirudo_mount_of(shirudo_ptr_addr(mnt), mnt);- if (shirudo_mount_tree_has(target, bpffs))- return shirudo_tamper_deny(SHIRUDO_TAMPER_BPFFS_UMOUNT_ABOVE,- -EPERM);- return 0;+ return shirudo_deny_bpffs_mount(BPF_CORE_READ(mnt, mnt_sb, s_dev),+ SHIRUDO_TAMPER_BPFFS_UMOUNT);}SEC("lsm/move_mount")diff --git a/testing/tamperproof/t1113-mount-lockdown.sh b/testing/tamperproof/t1113-mount-lockdown.shindex 0653c937..8ded47fd 100755--- a/testing/tamperproof/t1113-mount-lockdown.sh+++ b/testing/tamperproof/t1113-mount-lockdown.sh@@ -9,10 +9,6 @@# the whole mount lifecycle of that superblock, so a plain (or lazy)# `umount` of /run/shirudo/bpffs -- which before these hooks silently# disabled every LSM program -- is refused, and enforcement survives.-# sb_umount also refuses a mount with the bpffs beneath it, since a lazy-# unmount of /run or of a bind of it takes the subtree down and fires-# the hook for the ancestor alone; that is tried in a private mount-# namespace, where a regression would cost only the namespace's copies.## Non-destructive when the guards work (the operations are denied, so# nothing changes). If a guard has regressed and the bpffs actually gets@@ -58,22 +54,6 @@ test_expect_success 'remount of the bpffs is denied' '[ "$(./$H)" = "errno=13" ]'-test_expect_success 'lazy umount of a mount above the bpffs is denied' '- unshare -m sh -c "- mount -t tmpfs none /mnt && mkdir -p /mnt/b /mnt/plain &&- mount --bind $B /mnt/b && mount -t tmpfs none /mnt/plain &&- umount -l /mnt/plain &&- ! umount -l /mnt 2>/dev/null && mountpoint -q /mnt/b" &&- mountpoint -q "$B" &&- [ "$(./$H)" = "errno=13" ]-'--test_expect_success 'lazy umount of /run itself is denied' '- unshare -m sh -c "! umount -l /run 2>/dev/null && mountpoint -q $B" &&- mountpoint -q "$B" &&- [ "$(./$H)" = "errno=13" ]-'-test_expect_success 'mounting over the bpffs is denied' 'mount -t tmpfs none "$B" 2>/dev/null# A successful shadow-mount would leave a tmpfs (not bpf) on top.diff --git a/testing/tamperproof/t1136-tamper-counters.sh b/testing/tamperproof/t1136-tamper-counters.shindex 027ea1c2..e32daabf 100755--- a/testing/tamperproof/t1136-tamper-counters.sh+++ b/testing/tamperproof/t1136-tamper-counters.sh@@ -84,13 +84,6 @@ test_expect_success 'an unmount of the bpffs moves BpffsUmount' 'grew BpffsUmount "$before"'-test_expect_success 'an unmount above the bpffs moves BpffsUmountAbove' '- before=$(counter BpffsUmountAbove) &&- unshare -m sh -c "umount -l /run" 2>/dev/null- mountpoint -q "$B" &&- grew BpffsUmountAbove "$before"-'-test_expect_success 'a link creation moves ProgAttach and a pin moves ObjPin' 'ProgAttach=$(counter ProgAttach) && pin=$(counter ObjPin) &&[ "$(./$C LINK_CREATE)" = "errno=13" ] &&@@ -114,7 +107,7 @@ test_expect_success 'the human report lists the counters that moved' '"$SHIRUDO_BIN" status >"$W/status" &&grep -q "^Tamper attempts (refused this boot):" "$W/status" &&grep -q "^ PinRename *[1-9][0-9]* rename of a pin" "$W/status" &&- grep -q "^ BpffsUmountAbove *[1-9][0-9]* unmount of a mount above" \+ grep -q "^ BpffsUmount *[1-9][0-9]* unmount of the private bpffs" \"$W/status" &&! grep -q "^ none$" "$W/status"'diff --git a/testing/tamperproof/test.plan.md b/testing/tamperproof/test.plan.mdindex 7ef1569d..e8abbf51 100644--- a/testing/tamperproof/test.plan.md+++ b/testing/tamperproof/test.plan.md@@ -27,7 +27,7 @@ checks that Shirudo can still export the pre-existing Python exec record.| TP-05 | Add a key to the sealed BPF keyring | Covered | `t1121-bpf-keyring.sh` | Keep sealing denial and enrollment checks. || TP-06 | Unlink, clear, revoke, invalidate, re-permission, timeout, or link a key in the anchor | Covered | `t1125-key-permission.sh` | Keep per-operation denial assertions and status check. || TP-07 | Root modifies a labelled file under `/var/lib/shirudo` or changes its xattr | Covered | `t1101-seal.sh` | Keep certificate and archived-upatch write, xattr, unlink, rename-away, and rename-over denial assertions. |-| TP-08 | Direct or lazy unmount, remount, or mount over private bpffs, or lazy unmount of a mount above it | Covered | `t1113-mount-lockdown.sh` | Keep mountpoint and enforcement-survival checks; the ancestor case runs in a private mount namespace. |+| TP-08 | Direct or lazy unmount, remount, or mount over private bpffs | Covered | `t1113-mount-lockdown.sh` | Keep mountpoint and enforcement-survival checks. || TP-09 | Obtain writable serializer-array or arena FD by pinned path | Covered | `t1130-map-lockdown.sh` | Current test covers `shirudo_ser` and `obs_i_arena`. || TP-10 | Obtain writable map FD by map ID | Covered | `t1130-map-lockdown.sh` | Current test covers both maps. || TP-11 | Read-only map FD access as a positive control | Covered | `t1130-map-lockdown.sh` | Preserve both path and map-ID read-only checks. |