eBPF-based security platform
seal: refuse removal of the label without authority
Daniel Borkmann8c59057ac499
diff --git a/AGENTS.md b/AGENTS.mdindex 31a5c9c4..5c4ab28d 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -296,9 +296,9 @@ one usually still compiles and passes tests.from the authenticated runtime grants the committed task mark. Fork inheritsit, successful exec re-evaluates it and failed exec preserves it. Writablestate retains its seal xattrs; runtime and config files use dm-verity. Only- an authorized caller may set the exact seal xattr. Both rename endpoints,- write open, unlink, setattr and xattr changes are checked. There is no- executable replacement exception.+ an authorized caller may set or remove the exact seal xattr. Both rename+ endpoints, write open, unlink, setattr and xattr changes are checked. There+ is no executable replacement exception.Label read errors require authority except ENODATA, EOPNOTSUPP, EACCESand EPERM; scratch allocation failure also requires authority. The seallabels new inodes during creation when the parent has a cached directorydiff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex c45b4062..7d014d52 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -649,8 +649,8 @@ refused, since it is a tree bound over the path rather than the oneunlink, either end of a rename, a setattr (truncate, chmod, chown,utimes) and an xattr change need runtime authority (``SealWrite``,``SealUnlink``, ``SealRename``, ``SealSetattr``, ``SealXattr``). Only an-authorized task sets the exact seal label or changes the policy label on-any inode (``SealLabel``).+authorized task sets or removes the exact seal label or changes the+policy label on any inode (``SealLabel``).The label is a public constant, the same on every build. It marks atarget and never grants authority: a file system root mounts can carry@@ -659,7 +659,11 @@ with an error other than ``ENODATA``, ``EOPNOTSUPP``, ``EACCES`` or``EPERM`` requires authority, and so does a failure to allocate theseal's scratch memory. The two permission errors count as unlabeledbecause the kernel checks read permission for the caller before it-returns the label (U12).+returns the label (U12). The labels themselves are refused to such a+caller whatever the read said: root takes a file system uid that cannot+read the inode with ``setfsuid()`` and keeps the ``CAP_SYS_ADMIN`` that+a ``security.*`` xattr change needs, so the read fails where the+removal would pass (``t6111``).Executables may carry ``security.bpf.shirudo.policy``, an 8-bytetarget-native ``__u64`` bitset. During exec, the seal ORs the value fromdiff --git a/bpf/seal.c b/bpf/seal.cindex c6c0d7c9..d5322b1a 100644--- a/bpf/seal.c+++ b/bpf/seal.c@@ -460,13 +460,18 @@ int BPF_PROG(shirudo_seal_inode_setxattr, struct mnt_idmap *idmap,return seal_dentry(dentry, TAMPER_SEAL_XATTR);}+/*+ * The label read fails with -EACCES for a caller who may not read the+ * inode, which root becomes at will with setfsuid() while it keeps the+ * CAP_SYS_ADMIN the removal needs: the labels are never left to it.+ */SEC("lsm.s/inode_removexattr")int BPF_PROG(shirudo_seal_inode_removexattr, struct mnt_idmap *idmap,struct dentry *dentry, const char *name, int ret){if (ret)return ret;- if (seal_is_policy(name))+ if (seal_is_label(name) || seal_is_policy(name))return seal_caller(TAMPER_SEAL_LABEL);return seal_dentry(dentry, TAMPER_SEAL_XATTR);}