[PATCH v3 2/6] landlock: Mediate CAP_SYS_RAWIO for mappings below mmap_min_addr

From: Mickaël Salaün

Date: Wed Nov 18 2026 - 09:52:50 EST


commoncap's mmap_addr hook checks CAP_SYS_RAWIO for mappings below
vm.mmap_min_addr with cap_capable(), which skips the capable hook, so a
domain denying CAP_SYS_RAWIO cannot prevent these mappings. Mapping the
lowest pages helps to exploit kernel NULL pointer dereferences.

Add a Landlock mmap_addr hook that checks CAP_SYS_RAWIO against the
domain under the same condition, as SELinux checks its own mmap_zero
permission in this hook. commoncap runs first, so the hook only sees
mappings that commoncap allowed. This also covers the x86 vm86(2) and
vm86old(2) system calls. Calling capable() from cap_mmap_addr() would
instead expose this check to the capable hook of all LSMs.

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-3-mic@xxxxxxxxxxx
- Shorten the commit message (suggested by Günther Noack).
- Add Günther Noack's Reviewed-by.

Changes since v1:
https://patch.msgid.link/20261110202436.2408244-3-mic@xxxxxxxxxxx
- Add Serge Hallyn's Acked-by.
---
security/landlock/cap.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

diff --git a/security/landlock/cap.c b/security/landlock/cap.c
index fa59118e3486..10e1ca772b9c 100644
--- a/security/landlock/cap.c
+++ b/security/landlock/cap.c
@@ -9,6 +9,7 @@
#include <linux/cred.h>
#include <linux/lsm_audit.h>
#include <linux/lsm_hooks.h>
+#include <linux/security.h>
#include <uapi/linux/landlock.h>

#include "cap.h"
@@ -90,8 +91,29 @@ static int hook_capable(const struct cred *cred, struct user_namespace *ns,
return check_cap(cred, cap, opts);
}

+/**
+ * hook_mmap_addr - Restrict mappings below dac_mmap_min_addr
+ *
+ * @addr: Address of the new mapping.
+ *
+ * cap_mmap_addr() requires CAP_SYS_RAWIO to map below dac_mmap_min_addr, but
+ * calls cap_capable() directly, which skips hook_capable(). Check the same
+ * condition against the domain. commoncap runs first, so this only sees
+ * mappings that commoncap allowed.
+ *
+ * Return: 0 if allowed, -EPERM if CAP_SYS_RAWIO use is denied.
+ */
+static int hook_mmap_addr(unsigned long addr)
+{
+ if (addr >= dac_mmap_min_addr)
+ return 0;
+
+ return check_cap(current_cred(), CAP_SYS_RAWIO, CAP_OPT_NONE);
+}
+
static struct security_hook_list landlock_hooks[] __ro_after_init = {
LSM_HOOK_INIT(capable, hook_capable),
+ LSM_HOOK_INIT(mmap_addr, hook_mmap_addr),
};

__init void landlock_add_cap_hooks(void)
--
2.56.0