Skip to content

eBPF-based security platform

bpf2: keep every entry in the private bpffs shirudo's

Daniel Borkmann4550edb35339
diff --git a/Documentation/architecture.rst b/Documentation/architecture.rst
index 4ef8c323..a3fc7c13 100644
--- a/Documentation/architecture.rst
+++ b/Documentation/architecture.rst
@@ -302,7 +302,10 @@ mapping. Other device records are maintained by the kernel hooks.
``lsm/inode_setxattr`` and ``lsm/inode_removexattr`` on shirudo's bpffs
allow the operation only for a task with runtime authority: root ``rm`` cannot drop a pin, ``mv`` cannot replace
one (the VFS unlinks a rename's victim without ``inode_unlink``), and
-nobody else can forge the payload xattr. ``lsm/key_permission`` applies the same test
+nobody else can forge the payload xattr. ``lsm/inode_mkdir``,
+``lsm/inode_symlink`` and ``lsm/inode_link`` there are shirudo's too,
+so that no symbolic link of root's stands where a load would make its
+pin directory and no hard link of root's keeps a pin past its unlink. ``lsm/key_permission`` applies the same test
to the trust anchor in the kernel's keyrings: write, setattr and unlink
on the sealed keyring and on the keys it holds, and the unpossessed
search ``keyctl invalidate`` uses to reach a key by serial, are denied
diff --git a/Documentation/threat-model.rst b/Documentation/threat-model.rst
index 92a8541c..9bff89c0 100644
--- a/Documentation/threat-model.rst
+++ b/Documentation/threat-model.rst
@@ -127,7 +127,12 @@ T2 Detaching or replacing enforcement
event, which would bind a kprobe program reached by id to a probe of
the caller's own, is kept to the same task by ``file_ioctl`` and
``file_ioctl_compat``. Root cannot re-attach a vetted program
- at a site its signer never meant it for, nor pin objects of its own.
+ at a site its signer never meant it for, nor pin objects of its own,
+ nor make a directory or a link in the private bpffs, which bpffs
+ would otherwise let it: a symbolic link in place of a pin directory
+ would send the next load's pins into a bpffs of root's own, and a
+ hard link to a pin would keep a link alive past its unlink
+ (``inode_mkdir``, ``inode_symlink``, ``inode_link``).
The site a load attaches at is partly the caller's to arrange, and
root runs ``shirudo upatch load``: a cgroup_skb program under a
cgroup namespace root or a bind mount of a subtree, a netfilter
diff --git a/bpf/admission.h b/bpf/admission.h
index 030a2923..c03e1822 100644
--- a/bpf/admission.h
+++ b/bpf/admission.h
@@ -379,6 +379,45 @@ int BPF_PROG(shirudo_lsm_inode_rmdir, struct inode *dir,
SHIRUDO_TAMPER_MAX);
}
+/*
+ * The private bpffs takes no entry shirudo did not make. bpffs lets
+ * root make directories, symbolic links and hard links: a symbolic
+ * link in place of a pin directory would send the pins of the next
+ * load into a bpffs of root's own, where no guard reaches them, and a
+ * hard link to a pin would keep the link alive past its unlink.
+ */
+SEC("lsm/inode_mkdir")
+int BPF_PROG(shirudo_lsm_inode_mkdir, const struct mnt_idmap *idmap,
+ struct inode *dir, struct dentry *dentry, umode_t mode, int ret)
+{
+ if (ret)
+ return ret;
+ return shirudo_bpffs_guard(BPF_CORE_READ(dir, i_sb, s_dev),
+ SHIRUDO_TAMPER_PIN_ENTRY);
+}
+
+SEC("lsm/inode_symlink")
+int BPF_PROG(shirudo_lsm_inode_symlink, const struct mnt_idmap *idmap,
+ struct inode *dir, struct dentry *dentry, const char *old_name,
+ int ret)
+{
+ if (ret)
+ return ret;
+ return shirudo_bpffs_guard(BPF_CORE_READ(dir, i_sb, s_dev),
+ SHIRUDO_TAMPER_PIN_ENTRY);
+}
+
+SEC("lsm/inode_link")
+int BPF_PROG(shirudo_lsm_inode_link, const struct mnt_idmap *idmap,
+ struct dentry *old_dentry, struct inode *dir,
+ struct dentry *new_dentry, int ret)
+{
+ if (ret)
+ return ret;
+ return shirudo_bpffs_guard(BPF_CORE_READ(dir, i_sb, s_dev),
+ SHIRUDO_TAMPER_PIN_ENTRY);
+}
+
SEC("lsm/inode_rename")
int BPF_PROG(shirudo_lsm_inode_rename, struct inode *old_dir,
struct dentry *old_dentry, struct inode *new_dir,
diff --git a/bpf/lib/shirudo_tamper.h b/bpf/lib/shirudo_tamper.h
index 97e2edba..148acbf9 100644
--- a/bpf/lib/shirudo_tamper.h
+++ b/bpf/lib/shirudo_tamper.h
@@ -42,6 +42,7 @@ enum shirudo_tamper_point {
SHIRUDO_TAMPER_EXEC_TRACED,
SHIRUDO_TAMPER_SEAL_ENTRY,
SHIRUDO_TAMPER_PERF_ATTACH,
+ SHIRUDO_TAMPER_PIN_ENTRY,
SHIRUDO_TAMPER_MAX
};
diff --git a/util/image_guards.c b/util/image_guards.c
index 71d07c30..bfa3e075 100644
--- a/util/image_guards.c
+++ b/util/image_guards.c
@@ -84,6 +84,12 @@ shirudo_observer_guards[SHIRUDO_OBSERVER_HOOK_COUNT] = {
SHIRUDO_BPFFS_DIR "/inode_rmdir_link" },
{ "shirudo_lsm_inode_rename",
SHIRUDO_INODE_RENAME_LINK_PIN },
+ { "shirudo_lsm_inode_mkdir",
+ SHIRUDO_BPFFS_DIR "/inode_mkdir_link" },
+ { "shirudo_lsm_inode_symlink",
+ SHIRUDO_BPFFS_DIR "/inode_symlink_link" },
+ { "shirudo_lsm_inode_link",
+ SHIRUDO_BPFFS_DIR "/inode_link_link" },
};
const struct shirudo_image_guard
diff --git a/util/image_guards.h b/util/image_guards.h
index cb75e8d3..441eb4ba 100644
--- a/util/image_guards.h
+++ b/util/image_guards.h
@@ -11,7 +11,7 @@
#define SHIRUDO_SEAL_HOOK_COUNT 19
#define SHIRUDO_IMAGE_SEAL_HOOK_COUNT 2
#define SHIRUDO_MOUNT_HOOK_COUNT 5
-#define SHIRUDO_OBSERVER_HOOK_COUNT 4
+#define SHIRUDO_OBSERVER_HOOK_COUNT 7
#define SHIRUDO_IMAGE_OBSERVER_HOOK_COUNT 4
struct shirudo_image_guard {
diff --git a/util/tamper.c b/util/tamper.c
index 32ab0e73..15963446 100644
--- a/util/tamper.c
+++ b/util/tamper.c
@@ -82,6 +82,8 @@ static const struct {
"entry created, linked or renamed into a sealed directory" },
[SHIRUDO_TAMPER_PERF_ATTACH] = { "PerfAttach",
"program attached to a perf event by another executable" },
+ [SHIRUDO_TAMPER_PIN_ENTRY] = { "PinEntry",
+ "directory or link made in the private bpffs by another executable" },
};
const char *tamper_name(enum shirudo_tamper_point point)