[PATCH v3 3/6] landlock: Mediate CAP_SETPCAP for inheritable capabilities
From: Mickaël Salaün
Date: Wed Nov 18 2026 - 09:53:03 EST
cap_capset() checks CAP_SETPCAP with cap_capable() (through
cap_inh_is_capped()), which skips the capable hook, so a domain denying
CAP_SETPCAP cannot prevent adding capabilities outside of the old
inheritable and permitted sets to the inheritable set. Without
no_new_privs (possible when a task with CAP_SYS_ADMIN enforced the
domain), file inheritable capabilities can then grant permitted
capabilities on execve().
Add a Landlock capset hook that checks CAP_SETPCAP against the domain
under the same condition, as SELinux checks its own setcap permission in
this hook.
Cc: Günther Noack <gnoack@xxxxxxxxxx>
Cc: Paul Moore <paul@xxxxxxxxxxxxxx>
Cc: Serge Hallyn <serge@xxxxxxxxxx>
Acked-by: Serge Hallyn (AMD) <sergeh@xxxxxxxxxx>
Reviewed-by: Günther Noack <gnoack@xxxxxxxxxx>
Fixes: 97c8386f1d74 ("landlock: Enforce capability restrictions")
Signed-off-by: Mickaël Salaün <mic@xxxxxxxxxxx>
---
Changes since v2:
https://patch.msgid.link/20261117101157.2520463-4-mic@xxxxxxxxxxx
- Describe the hook's condition from cap_capset()'s point of view in its
comment (suggested by Günther Noack).
- Shorten the commit message.
- Add Günther Noack's Reviewed-by.
Changes since v1:
https://patch.msgid.link/20261110202436.2408244-4-mic@xxxxxxxxxxx
- Add Serge Hallyn's Acked-by.
---
security/landlock/cap.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/security/landlock/cap.c b/security/landlock/cap.c
index 10e1ca772b9c..cdb95b979eaa 100644
--- a/security/landlock/cap.c
+++ b/security/landlock/cap.c
@@ -91,6 +91,36 @@ static int hook_capable(const struct cred *cred, struct user_namespace *ns,
return check_cap(cred, cap, opts);
}
+/**
+ * hook_capset - Restrict inheritable capability changes
+ *
+ * @new: New credentials (unused).
+ * @old: Current credentials.
+ * @effective: New effective set (unused).
+ * @inheritable: New inheritable set.
+ * @permitted: New permitted set (unused).
+ *
+ * cap_capset() denies a new inheritable set that is not a subset of the old
+ * inheritable and permitted sets, unless cap_inh_is_capped() finds CAP_SETPCAP.
+ * This check uses cap_capable(), which skips hook_capable(). commoncap runs
+ * first, so such a set reaching this hook means that commoncap granted
+ * CAP_SETPCAP: check it against the domain. capset(2) discards @new if this
+ * hook fails, so nothing is committed.
+ *
+ * Return: 0 if allowed, -EPERM if CAP_SETPCAP use is denied.
+ */
+static int hook_capset(struct cred *new, const struct cred *old,
+ const kernel_cap_t *effective,
+ const kernel_cap_t *inheritable,
+ const kernel_cap_t *permitted)
+{
+ if (cap_issubset(*inheritable,
+ cap_combine(old->cap_inheritable, old->cap_permitted)))
+ return 0;
+
+ return check_cap(old, CAP_SETPCAP, CAP_OPT_NONE);
+}
+
/**
* hook_mmap_addr - Restrict mappings below dac_mmap_min_addr
*
@@ -113,6 +143,7 @@ static int hook_mmap_addr(unsigned long addr)
static struct security_hook_list landlock_hooks[] __ro_after_init = {
LSM_HOOK_INIT(capable, hook_capable),
+ LSM_HOOK_INIT(capset, hook_capset),
LSM_HOOK_INIT(mmap_addr, hook_mmap_addr),
};
--
2.56.0