eBPF-based security platform
docs: give the label verdict one home, a table in seal.rst
Daniel Borkmann5f99382697b2
diff --git a/Documentation/internals/enforcement.rst b/Documentation/internals/enforcement.rstindex ddfd65cb..3e2759a5 100644--- a/Documentation/internals/enforcement.rst+++ b/Documentation/internals/enforcement.rst@@ -566,7 +566,7 @@ when the record it needs is missing.or clears the mark from the label; a write open only records it.- ``EACCES``- ``SealWrite``- - See the label verdict below.+ - :ref:`The label verdict <seal-label-verdict>`.* - ``lsm.s/inode_unlink``, ``lsm.s/inode_rmdir``,``lsm.s/inode_setattr``, ``lsm.s/inode_removexattr`` (``seal``)- The operation on a labeled inode to a task without authority.@@ -575,14 +575,14 @@ when the record it needs is missing.inode without authority.- ``EACCES``- ``SealUnlink``, ``SealSetattr``, ``SealXattr``, ``SealLabel``- - See the label verdict below.+ - :ref:`The label verdict <seal-label-verdict>`.* - ``lsm.s/inode_set_acl``, ``lsm.s/inode_remove_acl``,``lsm.s/inode_file_setattr`` (``seal``)- A POSIX ACL change or a change of the inode flags (``chattr``) ona labeled inode to a task without authority.- ``EACCES``- ``SealXattr``, ``SealSetattr``- - See the label verdict below.+ - :ref:`The label verdict <seal-label-verdict>`.* - ``lsm.s/inode_setxattr`` (``seal``)- Setting ``security.bpf.shirudo``,``security.bpf.shirudo.policy`` or@@ -590,14 +590,14 @@ when the record it needs is missing.on a labeled inode, to a task without authority.- ``EACCES``- ``SealLabel``, ``SealXattr``- - See the label verdict below.+ - :ref:`The label verdict <seal-label-verdict>`.* - ``lsm.s/inode_rename`` (``seal``)- A labeled source, a labeled destination directory or a labeledinode it would replace, or a source or replaced directory thatcarries the ancestor mark, to a task without authority.- ``EACCES``- ``SealRename``, ``SealEntry``- - See the label verdict below.+ - :ref:`The label verdict <seal-label-verdict>`.* - ``lsm.s/inode_create``, ``lsm.s/inode_mkdir``,``lsm.s/inode_symlink``, ``lsm.s/inode_mknod``,``lsm.s/inode_link`` (``seal``)@@ -606,7 +606,7 @@ when the record it needs is missing.inode anywhere. Each refreshes the directory's mark.- ``EACCES``- ``SealEntry``- - See the label verdict below.+ - :ref:`The label verdict <seal-label-verdict>`.* - ``lsm/inode_init_security`` (``seal``)- Labels a new inode under a marked directory, inside the creation,and marks the new inode. Refuses the creation when it cannot add@@ -619,7 +619,7 @@ when the record it needs is missing.- The overlay copy-up of a labeled inode, by anyone.- ``EPERM``- ``SealCopyUp``- - As the label verdict below, but a label, any other read error+ - As :ref:`the label verdict <seal-label-verdict>`, but a label, any other read errorand a failure to allocate the scratch buffer refuse every caller.* - ``lsm.s/inode_post_setxattr``, ``lsm.s/inode_post_removexattr``(``seal``)@@ -629,17 +629,9 @@ when the record it needs is missing.- No label, or a label of another length, removes the mark; afailed read leaves it.-The label verdict of the ``seal`` hooks reads ``security.bpf.shirudo``-with the xattr kfuncs, which with the carried patch 0002 return it-without the calling task's permission and upstream check that-permission first. No label (``ENODATA``) and no security-extended attributes on the file system (``EOPNOTSUPP``) count as-unlabeled, and the operation goes ahead. A label the caller may not-read (``EACCES``, ``EPERM``) counts as unlabeled unless the inode, or-the directory the operation changes, carries a mark, which requires-runtime authority. A label of any length, any other read error and a-failure to allocate the scratch buffer require runtime authority.-:doc:`seal` explains why and what follows from it.+The label verdict the ``seal`` rows name is the table of+:ref:`seal-label-verdict`, which says what each result of a label read+decides and why.Limits------diff --git a/Documentation/internals/seal.rst b/Documentation/internals/seal.rstindex f0304229..a8354eb1 100644--- a/Documentation/internals/seal.rst+++ b/Documentation/internals/seal.rst@@ -257,6 +257,8 @@ copy-up of a labeled inode to every caller (``SealCopyUp``): a writethrough an overlay mounted over sealed state would otherwise land in theupper directory and leave the sealed inode as it was.+.. _seal-label-verdict:+Reading the label~~~~~~~~~~~~~~~~~@@ -264,19 +266,46 @@ The seal reads the label with the ``bpf_get_file_xattr()`` and``bpf_get_dentry_xattr()`` kfuncs. With the carried kernel patch theyreturn a ``security.bpf.`` label as the in-kernel LSMs read theirs,without the calling task's permission. Upstream they first check that-the calling task may read the inode, against its raw ids. If the seal-refused every operation whose label read failed, it would refuse every-write-only open and every unlink of a file the caller cannot read, on-every file system. So no label (``ENODATA``) and no security extended-attributes on the file system (``EOPNOTSUPP``) count as unlabeled and-the operation goes ahead. A label the caller may not read (``EACCES``,-``EPERM``) is, on an upstream kernel, also what root makes of any label-by granting a write without a read, through an idmapped bind mount or-an ACL, and then acting at a file system uid that cannot read. There-the mark of the inode, or of the directory the operation changes,-decides, and a marked one requires runtime authority. A label of any-length, any other error, and a failure to allocate the scratch buffer-the kfunc writes into require runtime authority.+the calling task may read the inode, against its raw ids, and root can+make any label unreadable to a caller that may still write: through an+idmapped bind mount or an ACL, and then acting at a file system uid+that cannot read. A seal that refused every operation whose label read+failed would refuse every write-only open and every unlink of a file the+caller cannot read, on every file system; one that let every failed+read through would let root shed every label.++The table gives the verdict of each read result, ``seal_verdict()`` in+:src:`bpf/seal.c`. Every hook that decides on a label uses it.++.. list-table::+ :header-rows: 1+ :widths: 24 34 42++ * - Read result+ - Verdict+ - Why+ * - A label, of any length+ - Labeled: the operation needs runtime authority.+ - The inode is shirudo's; the value carries no meaning.+ * - ``ENODATA``, ``EOPNOTSUPP``+ - Unlabeled: the operation goes ahead.+ - No label, or a file system without security extended attributes.+ * - ``EACCES``, ``EPERM``+ - Labeled when the inode, or the directory the operation changes,+ carries a mark; otherwise unlabeled.+ - The read failed for the caller, which upstream root can arrange.+ The mark remembers a label the seal read before. With the carried+ patch these errors do not occur.+ * - Any other error, or no scratch buffer for the read+ - Labeled: the operation needs runtime authority.+ - A read that fails for another reason does not show that the+ inode is unlabeled.++Three checks differ. Setting or removing the label, the policy label or+the ancestor mark needs runtime authority whatever the read says+(``SealLabel``). The ancestor mark lets a rename through only on+``ENODATA`` or ``EOPNOTSUPP``. ``inode_copy_up`` refuses every caller,+with or without authority, where the table requires authority.Labeling at creation---------------------diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex 9a443598..c7aa3aaa 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -748,21 +748,14 @@ What the next boot mounts at the path stays root's choice (R19).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-it, and a binary that carries it gains nothing. A label read that fails-with an error other than ``ENODATA``, ``EOPNOTSUPP``, ``EACCES`` or-``EPERM`` requires authority, and so does a failure to allocate the-seal's scratch memory. With the carried xattr patch (A3) the kernel-returns the label to the seal without the caller's read permission, as-it returns their labels to the in-kernel LSMs, and the two permission-errors do not occur. Upstream, the kernel checks read permission for-the caller before it returns the label, against the raw ids of the-inode, so the two errors mean either a caller that may do nothing or-one that root gave a write without a read: through an idmapped bind-mount, which shows uid 0's files as another id's to the permission-check, or through an ACL, and then at a file system uid that cannot-read. Where the read fails that way, the mark of the inode, or of the-directory the operation changes, decides, and the operation needs-authority when either is marked (``t6111``). The seal marks every inode+it, and a binary that carries it gains nothing. What a label read decides is the+table of :ref:`seal-label-verdict`: no label, or no security extended+attributes, lets an operation through, a permission error does so only+where neither the inode nor the directory the operation changes carries+a mark, and every other result requires authority (``t6111``). With+the carried xattr patch (A3) the permission errors do not occur;+upstream, root brings them about with an idmapped bind mount or an ACL+and a file system uid that cannot read. The seal marks every inodeit labels at creation, every file shirudo opens, every file anyoneopens for writing, every directory anyone opens and the directory ofevery new entry, from the label the entry hook reads; the marks are a