eBPF-based security platform
lsm: refuse every kexec load
Daniel Borkmann36c7b1a45929
diff --git a/Documentation/architecture.rst b/Documentation/architecture.rstindex 2f6a625d..f195b6ba 100644--- a/Documentation/architecture.rst+++ b/Documentation/architecture.rst@@ -316,6 +316,9 @@ to every task but shirudo, while viewing, listing and the possessedsearch the kernel verifies signatures with stay open. Sealing stopskeys from being added; this stops root from taking them away, so thatsigner removal happens through signed config activation.+``lsm/kernel_load_data`` and ``lsm/kernel_read_file`` refuse a kexec+image or initramfs to every task, since a kexec would carry this boot's+TPM state under a kernel of root's choosing.``lsm/sb_umount``, ``lsm/move_mount``,``lsm/sb_mount`` and ``lsm/sb_remount`` deny unconditionally, for everycaller including shirudo, direct unmount, relocation, mount-over anddiff --git a/Documentation/requirements.rst b/Documentation/requirements.rstindex 0c8c3225..0415cc8a 100644--- a/Documentation/requirements.rst+++ b/Documentation/requirements.rst@@ -119,6 +119,11 @@ fixture.only relaxes module-signature checks, and BPF signature verificationaccepts the signed-attributes form.+``CONFIG_KEXEC`` and ``CONFIG_KEXEC_FILE`` may stay enabled: the LSM+refuses every kexec load (``Kexec``, threat T6 of the threat model),+since a kexec would carry this boot's TPM state under a kernel of+root's choosing.+Image-mode requirements~~~~~~~~~~~~~~~~~~~~~~~diff --git a/Documentation/threat-model.rst b/Documentation/threat-model.rstindex d55173f7..fb6fbd2f 100644--- a/Documentation/threat-model.rst+++ b/Documentation/threat-model.rst@@ -302,7 +302,13 @@ T6 The boot windowfrom the certificate and the set. ``shirudo.service`` then finishesfrom the root file system: labels and the eventlog record. Untilthe initrd run has happened the target is unprotected; see residual- risk 7.+ risk 7. A kexec would open that window again without closing this+ boot: it hands the machine to a kernel and an initrd of root's+ choosing with the TPM as it is, PCRs 9 and 11 at this boot's values+ and the register with this boot's history, so the evidence of this+ boot would vouch for whatever ran after. ``kernel_load_data`` and+ ``kernel_read_file`` refuse a kexec image or initramfs to every+ task, by either system call (``Kexec``).T7 The delivery pathThe registry index is a detached CMS signature by the operator'sdiff --git a/bpf/admission.h b/bpf/admission.hindex c03e1822..aa811a3a 100644--- a/bpf/admission.h+++ b/bpf/admission.h@@ -418,6 +418,35 @@ int BPF_PROG(shirudo_lsm_inode_link, const struct mnt_idmap *idmap,SHIRUDO_TAMPER_PIN_ENTRY);}+/*+ * A kexec hands the machine to a kernel and an initrd of root's+ * choosing with the TPM as it is, the PCRs and this boot's register+ * with it, so the evidence of this boot would vouch for whatever runs+ * after. No task loads a kexec image or initramfs by either system+ * call.+ */+SEC("lsm/kernel_load_data")+int BPF_PROG(shirudo_lsm_kernel_load_data, enum kernel_load_data_id id,+ bool contents, int ret)+{+ if (ret)+ return ret;+ if (id != LOADING_KEXEC_IMAGE && id != LOADING_KEXEC_INITRAMFS)+ return 0;+ return shirudo_tamper_deny(SHIRUDO_TAMPER_KEXEC, -EPERM);+}++SEC("lsm/kernel_read_file")+int BPF_PROG(shirudo_lsm_kernel_read_file, struct file *file,+ enum kernel_read_file_id id, bool contents, int ret)+{+ if (ret)+ return ret;+ if (id != READING_KEXEC_IMAGE && id != READING_KEXEC_INITRAMFS)+ return 0;+ return shirudo_tamper_deny(SHIRUDO_TAMPER_KEXEC, -EPERM);+}+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.hindex d2d9ae8a..e4ab7ee4 100644--- a/bpf/lib/shirudo_tamper.h+++ b/bpf/lib/shirudo_tamper.h@@ -44,6 +44,7 @@ enum shirudo_tamper_point {SHIRUDO_TAMPER_PERF_ATTACH,SHIRUDO_TAMPER_PIN_ENTRY,SHIRUDO_TAMPER_SEAL_COPY_UP,+ SHIRUDO_TAMPER_KEXEC,SHIRUDO_TAMPER_MAX};diff --git a/util/image_guards.c b/util/image_guards.cindex ef7b6bc5..402cb3c9 100644--- a/util/image_guards.c+++ b/util/image_guards.c@@ -91,6 +91,10 @@ shirudo_observer_guards[SHIRUDO_OBSERVER_HOOK_COUNT] = {SHIRUDO_BPFFS_DIR "/inode_symlink_link" },{ "shirudo_lsm_inode_link",SHIRUDO_BPFFS_DIR "/inode_link_link" },+ { "shirudo_lsm_kernel_load_data",+ SHIRUDO_BPFFS_DIR "/kernel_load_data_link" },+ { "shirudo_lsm_kernel_read_file",+ SHIRUDO_BPFFS_DIR "/kernel_read_file_link" },};const struct shirudo_image_guarddiff --git a/util/image_guards.h b/util/image_guards.hindex f2de33e6..b7108de5 100644--- a/util/image_guards.h+++ b/util/image_guards.h@@ -11,7 +11,7 @@#define SHIRUDO_SEAL_HOOK_COUNT 20#define SHIRUDO_IMAGE_SEAL_HOOK_COUNT 2#define SHIRUDO_MOUNT_HOOK_COUNT 5-#define SHIRUDO_OBSERVER_HOOK_COUNT 7+#define SHIRUDO_OBSERVER_HOOK_COUNT 9#define SHIRUDO_IMAGE_OBSERVER_HOOK_COUNT 4struct shirudo_image_guard {diff --git a/util/tamper.c b/util/tamper.cindex eef09d15..97acd21b 100644--- a/util/tamper.c+++ b/util/tamper.c@@ -86,6 +86,8 @@ static const struct {"directory or link made in the private bpffs by another executable" },[SHIRUDO_TAMPER_SEAL_COPY_UP] = { "SealCopyUp","overlay copy-up of a sealed inode" },+ [SHIRUDO_TAMPER_KEXEC] = { "Kexec",+ "kexec image or initramfs load" },};const char *tamper_name(enum shirudo_tamper_point point)