Skip to content

eBPF-based security platform

bpf: inherit task policy across exec

John Fastabende1b76faafee9
diff --git a/Documentation/internals/enforcement.rst b/Documentation/internals/enforcement.rst
index c93b47f6..4f25db06 100644
--- a/Documentation/internals/enforcement.rst
+++ b/Documentation/internals/enforcement.rst
@@ -419,10 +419,10 @@ when the record it needs is missing.
- No task storage leaves the task without authority.
* - ``lsm.s/bprm_creds_for_exec``, ``lsm.s/bprm_check_security``,
``lsm.s/bprm_committed_creds`` (``seal``)
- - Reset, accumulate and commit the policy bitset from the original
- executable and each interpreter. An absent policy or a file system
- without xattrs contributes zero bits; a malformed or unreadable
- policy xattr refuses exec.
+ - Seed with the task's committed bits, accumulate the original
+ executable and each interpreter, then commit. An absent policy or
+ a file system without xattrs contributes zero bits; a malformed
+ or unreadable policy xattr refuses exec.
- ``EACCES``
- Uncounted
- Failed exec leaves committed policy unchanged.
diff --git a/Documentation/internals/seal.rst b/Documentation/internals/seal.rst
index 22059d65..2a48e651 100644
--- a/Documentation/internals/seal.rst
+++ b/Documentation/internals/seal.rst
@@ -77,12 +77,13 @@ An executable may carry ``security.bpf.shirudo.policy``, an 8-byte native
``__u64`` bitset. During exec, ``bprm_check_security`` ORs the bitsets
from the original file and each interpreter into a task-local candidate
in ``policy_map``. ``bprm_committed_creds`` commits that value only after
-exec succeeds; a successful exec with no policy bits clears the previous
-value, while a failed exec leaves it unchanged. A fork or clone inherits
-the committed bits. The xattr remains on the inode. Only a task with
-runtime authority may set, update or remove it. An absent policy or a
-file system without xattrs contributes zero bits; invalid lengths and
-other read errors refuse the exec.
+exec succeeds. The candidate starts with the task's committed bits, so
+policy accumulates across execs as well as interpreter handlers. A failed
+exec leaves the committed value unchanged. A fork or clone inherits the
+committed bits. The xattr remains on the inode. Only a task with runtime
+authority may set, update or remove it. An absent policy or a file system
+without xattrs contributes zero bits; invalid lengths and other read
+errors refuse the exec.
The device record that the exec check consults comes from
``lsm.s/bdev_setintegrity``: it records a dm-verity device as runtime
diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rst
index 23bb954b..5fa9e07a 100644
--- a/Documentation/security/threat-model.rst
+++ b/Documentation/security/threat-model.rst
@@ -659,13 +659,14 @@ returns the label (U12).
Executables may carry ``security.bpf.shirudo.policy``, an 8-byte
target-native ``__u64`` bitset. During exec, the seal ORs the value from
-the original file and each interpreter into ``policy_map``. ``ENODATA``
-or ``EOPNOTSUPP`` means no policy; malformed or unreadable values refuse
-exec.
-Successful exec commits the accumulated bits, an unlabeled exec clears
-them, failed exec preserves the previous value, and children inherit the
-committed value. The xattr remains on the inode, and only a task with
-runtime authority may set, update or remove it (``SealLabel``).
+the original file and each interpreter into ``policy_map``. Only
+``ENODATA`` or ``EOPNOTSUPP`` means no policy; malformed or unreadable
+values refuse exec.
+The candidate starts with the task's committed bits, so successful exec
+accumulates policy bits and an unlabeled exec preserves the existing
+value. Failed exec preserves the previous value, and children inherit
+the committed value. The xattr remains on the inode, and only a task
+with runtime authority may set, update or remove it (``SealLabel``).
The seal keeps a mark in inode storage on every labeled directory it
has seen since the inode came into memory. A new inode under a marked
diff --git a/bpf/seal.c b/bpf/seal.c
index 1f4e7890..95df8291 100644
--- a/bpf/seal.c
+++ b/bpf/seal.c
@@ -488,12 +488,11 @@ static __always_inline bool shirudo_task_has_seccomp(struct task_struct *task)
SEC("lsm.s/bprm_creds_for_exec")
int BPF_PROG(shirudo_seal_bprm_creds_for_exec,
- struct linux_binprm *bprm, int ret)
+ struct linux_binprm *bprm __attribute__((__unused__)), int ret)
{
struct task_struct *task = bpf_get_current_task_btf();
struct shirudo_task_policy *policy;
- (void)bprm;
if (ret)
return ret;
policy = bpf_task_storage_get(&policy_map, task, NULL,