Skip to content

eBPF-based security platform

seal: keep a directory's mark when its label cannot be read

Daniel Borkmannc6b86cc1676c
diff --git a/Documentation/internals/seal.rst b/Documentation/internals/seal.rst
index 7349a0ff..5bfc94cd 100644
--- a/Documentation/internals/seal.rst
+++ b/Documentation/internals/seal.rst
@@ -208,7 +208,8 @@ attribute. It uses a cached mark instead: ``seal_dir_marks``, inode
storage that records a directory's label. A directory gets its mark when
any task opens it and its label is read, when an extended attribute on it
changes, and when it is created under a marked parent. A directory open
-whose label read finds nothing removes the mark.
+whose label read finds nothing removes the mark; a read that fails, for
+a caller who may not read the directory, leaves it.
shirudo's writers keep the mark in place. They open the parent directory
and create files relative to that descriptor, which holds the inode in
diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rst
index 7d014d52..348a7818 100644
--- a/Documentation/security/threat-model.rst
+++ b/Documentation/security/threat-model.rst
@@ -1390,16 +1390,16 @@ R15 Directory marks can be evicted
The label at creation and the entry checks follow a mark that the
seal keeps on a directory inode in memory. Root can evict the inode,
by dropping caches for instance, whenever shirudo does not hold the
- directory open, or make the label read fail (U12). While the mark is
- absent, root can create entries in a labeled directory and
- hard-link an already labeled inode into it; a hard link is the same
- inode and carries the label. shirudo replaces state by rename, so
- root can keep earlier labeled versions alive through hard links in
- an unsealed directory on the same file system and bring them back.
- An unlabeled entry stays inert: shirudo neither follows nor restores
- it. A returned labeled entry is taken for shirudo's own. Detection:
- only signatures and measurement; an archived upatch restored at the
- next boot appears in the init event's set. Mitigation: D6.
+ directory open. While the mark is absent, root can create entries in
+ a labeled directory and hard-link an already labeled inode into it; a
+ hard link is the same inode and carries the label. shirudo replaces
+ state by rename, so root can keep earlier labeled versions alive
+ through hard links in an unsealed directory on the same file system
+ and bring them back. An unlabeled entry stays inert: shirudo neither
+ follows nor restores it. A returned labeled entry is taken for
+ shirudo's own. Detection: only signatures and measurement; an
+ archived upatch restored at the next boot appears in the init event's
+ set. Mitigation: D6.
R16 Any artifact ever signed loads at any time
There is no version floor, no expiry and no per-target
@@ -1630,8 +1630,8 @@ U12 Another LSM can switch the seal off
permission, and every LSM's ``inode_permission`` hook takes part.
A policy that grants write or unlink but refuses read makes a
labeled file look unlabeled, and the operation goes through
- without a counter. The same refusal on a directory open removes
- its mark.
+ without a counter. The same refusal on a directory open leaves
+ its mark as it was.
:Status: Confirmed in code and in the kernel; the attack is a
code-path reading, not reproduced.
:Meanwhile: Run no other LSM whose policy root can change at
diff --git a/bpf/seal.c b/bpf/seal.c
index d5322b1a..f14f7870 100644
--- a/bpf/seal.c
+++ b/bpf/seal.c
@@ -117,12 +117,18 @@ static __always_inline bool seal_is_dir(struct inode *inode)
return (BPF_CORE_READ(inode, i_mode) & S_IFMT) == S_IFDIR;
}
-/* Remember a directory's label as just read (len bytes), or forget it. */
+/*
+ * Remember a directory's label as just read (len bytes), or forget it
+ * when there is none. A read that failed, for a caller who may not read
+ * the directory say, tells nothing about the label: the mark stands.
+ */
static __always_inline void seal_mark(struct inode *inode, const char *label,
int len)
{
struct seal_dir_mark *m;
+ if (len < 0 && len != -ENODATA && len != -EOPNOTSUPP)
+ return;
if (len != LABEL_LEN) {
bpf_inode_storage_delete(&seal_dir_marks, inode);
return;