* [PATCH v2 1/4] landlock: Distinguish namespace creation and entry denials
2026-11-18 16:32 [PATCH v2 0/4] Landlock: Fix namespace and capability denials Mickaël Salaün
@ 2026-11-18 16:32 ` Mickaël Salaün
2026-11-18 16:40 ` sashiko-bot
2026-11-18 16:32 ` [PATCH v2 2/4] landlock: Add capability objects to denial tracing Mickaël Salaün
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Mickaël Salaün @ 2026-11-18 16:32 UTC (permalink / raw)
To: Günther Noack
Cc: Mickaël Salaün, Christian Brauner, Eric Paris,
Masami Hiramatsu, Mathieu Desnoyers, Paul Moore, Steven Rostedt,
audit, kernel-team, linux-security-module, linux-trace-kernel
Landlock reports denied namespace creation and entry with the same
internal request type. Before commit 08471914d6bb ("ns: allocate the
namespace id before the namespace_init hook"), denied creation carried
ID zero and could be distinguished from entry by ID alone. That commit
moved ID allocation before namespace_init(), so creation now carries the
ID of an unreachable new namespace while entry carries the existing
target ID. Namespace IDs are object context, not operation
discriminators.
Split the request type into creation and entry. Keep the two namespace
values together before capability; this renumbers the unreleased
capability request in raw and typed trace context. Report
namespace_op=create or namespace_op=enter immediately after blockers in
namespace audit records and trace event text. Placing the operation
before namespace_type and namespace_id lets consumers establish the
semantics before interpreting the following namespace context,
especially whether namespace_id is the creation-time value or identifies
an existing entry target.
Keep namespace.use as the policy blocker: the new value only describes
the semantic hook context and does not add a policy control.
Cc: Günther Noack <gnoack@google.com>
Fixes: 15dd86021b57 ("landlock: Enforce namespace use restrictions")
Signed-off-by: Mickaël Salaün <mic@digikod.net>
---
Changes since v1:
https://patch.msgid.link/20261117102110.2524197-2-mic@digikod.net
- Trim syscall-path narration already covered by the hook documentation.
---
include/trace/events/landlock.h | 25 ++++++++++++++--------
security/landlock/audit.c | 10 +++++++--
security/landlock/log.c | 6 ++++--
security/landlock/log.h | 3 ++-
security/landlock/ns.c | 10 +++++----
security/landlock/trace.c | 3 ++-
tools/testing/selftests/landlock/ns_test.c | 18 +++++++++++-----
tools/testing/selftests/landlock/trace.h | 1 +
8 files changed, 52 insertions(+), 24 deletions(-)
diff --git a/include/trace/events/landlock.h b/include/trace/events/landlock.h
index b6fdc6e2eef8..9b3e24a613d8 100644
--- a/include/trace/events/landlock.h
+++ b/include/trace/events/landlock.h
@@ -36,7 +36,8 @@ static_assert(sizeof(access_mask_t) <= sizeof(u64));
TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_FS_CHANGE_TOPOLOGY);
TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_FS_ACCESS);
TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_NET_ACCESS);
-TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_NAMESPACE);
+TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_NAMESPACE_CREATE);
+TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_NAMESPACE_ENTER);
TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_CAPABILITY);
#ifdef CREATE_TRACE_POINTS
@@ -990,7 +991,8 @@ TRACE_EVENT(landlock_deny_access_net,
* @namespace_id: Namespace ID, not directly visible from user space when
* creation was denied.
*
- * Emitted when a Landlock domain denies namespace use.
+ * Emitted when a Landlock domain denies namespace creation or entry. The
+ * namespace_op field distinguishes these operations.
*/
TRACE_EVENT(landlock_deny_permission_namespace,
@@ -1021,13 +1023,18 @@ TRACE_EVENT(landlock_deny_permission_namespace,
__entry->namespace_id = namespace_id;
),
- TP_printk("domain=%llx same_exec=%d logged=%d blockers=%s namespace_type=0x%x namespace_id=%llu",
- __entry->domain_id, __entry->same_exec, __entry->logged,
- __entry->blockers_type == LANDLOCK_REQUEST_NAMESPACE ?
- __print_flags(__entry->blockers_access, "|",
- _LANDLOCK_PERMISSION_BLOCKER_NAMES) :
- "unknown",
- __entry->namespace_type, __entry->namespace_id)
+ TP_printk("domain=%llx same_exec=%d logged=%d blockers=%s namespace_op=%s namespace_type=0x%x namespace_id=%llu",
+ __entry->domain_id, __entry->same_exec, __entry->logged,
+ (__entry->blockers_type == LANDLOCK_REQUEST_NAMESPACE_CREATE ||
+ __entry->blockers_type == LANDLOCK_REQUEST_NAMESPACE_ENTER) ?
+ __print_flags(__entry->blockers_access, "|",
+ _LANDLOCK_PERMISSION_BLOCKER_NAMES) :
+ "unknown",
+ __entry->blockers_type == LANDLOCK_REQUEST_NAMESPACE_CREATE ?
+ "create" :
+ __entry->blockers_type == LANDLOCK_REQUEST_NAMESPACE_ENTER ?
+ "enter" : "unknown",
+ __entry->namespace_type, __entry->namespace_id)
);
/**
diff --git a/security/landlock/audit.c b/security/landlock/audit.c
index be49ef47b4ea..6d9e54f5deed 100644
--- a/security/landlock/audit.c
+++ b/security/landlock/audit.c
@@ -80,7 +80,8 @@ get_blocker(const enum landlock_request_type type,
WARN_ON_ONCE(access_bit != -1);
return scope_strings[BIT_INDEX(LANDLOCK_SCOPE_SIGNAL)];
- case LANDLOCK_REQUEST_NAMESPACE:
+ case LANDLOCK_REQUEST_NAMESPACE_CREATE:
+ case LANDLOCK_REQUEST_NAMESPACE_ENTER:
case LANDLOCK_REQUEST_CAPABILITY:
if (WARN_ON_ONCE(access_bit >= ARRAY_SIZE(permission_strings)))
return "unknown";
@@ -115,7 +116,8 @@ blocker_prefix(const enum landlock_request_type type)
case LANDLOCK_REQUEST_SCOPE_SIGNAL:
return "scope.";
- case LANDLOCK_REQUEST_NAMESPACE:
+ case LANDLOCK_REQUEST_NAMESPACE_CREATE:
+ case LANDLOCK_REQUEST_NAMESPACE_ENTER:
return _LANDLOCK_PERMISSION_NAMESPACE_NAME ".";
case LANDLOCK_REQUEST_CAPABILITY:
@@ -212,6 +214,10 @@ void landlock_audit_denial(const struct landlock_request *const request,
audit_log_format(ab, "domain=%llx blockers=", youngest_denied->id);
log_blockers(ab, request->type, missing);
+ if (request->type == LANDLOCK_REQUEST_NAMESPACE_CREATE)
+ audit_log_format(ab, " namespace_op=create");
+ else if (request->type == LANDLOCK_REQUEST_NAMESPACE_ENTER)
+ audit_log_format(ab, " namespace_op=enter");
audit_log_lsm_data(ab, &request->audit);
audit_log_end(ab);
diff --git a/security/landlock/log.c b/security/landlock/log.c
index 43efbb95725c..c132b343f0ee 100644
--- a/security/landlock/log.c
+++ b/security/landlock/log.c
@@ -388,7 +388,8 @@ static bool is_valid_request(const struct landlock_request *const request)
return false;
switch (request->type) {
- case LANDLOCK_REQUEST_NAMESPACE:
+ case LANDLOCK_REQUEST_NAMESPACE_CREATE:
+ case LANDLOCK_REQUEST_NAMESPACE_ENTER:
if (WARN_ON_ONCE(request->permission !=
LANDLOCK_PERMISSION_NAMESPACE_USE) ||
WARN_ON_ONCE(request->audit.type != LSM_AUDIT_DATA_NS))
@@ -485,7 +486,8 @@ is_denial_quieted(const struct landlock_request *const request,
case LANDLOCK_REQUEST_SCOPE_ABSTRACT_UNIX_SOCKET:
return !!(youngest_denied->quiet_access.scope &
LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET);
- case LANDLOCK_REQUEST_NAMESPACE:
+ case LANDLOCK_REQUEST_NAMESPACE_CREATE:
+ case LANDLOCK_REQUEST_NAMESPACE_ENTER:
return !!(youngest_denied->quiet_permission.ns_types &
landlock_ns_type_to_bit(request->audit.u.ns.ns_type));
case LANDLOCK_REQUEST_CAPABILITY:
diff --git a/security/landlock/log.h b/security/landlock/log.h
index 596feeeb7aa6..641a2c3c78ed 100644
--- a/security/landlock/log.h
+++ b/security/landlock/log.h
@@ -25,7 +25,8 @@ enum landlock_request_type {
LANDLOCK_REQUEST_NET_ACCESS,
LANDLOCK_REQUEST_SCOPE_ABSTRACT_UNIX_SOCKET,
LANDLOCK_REQUEST_SCOPE_SIGNAL,
- LANDLOCK_REQUEST_NAMESPACE,
+ LANDLOCK_REQUEST_NAMESPACE_CREATE,
+ LANDLOCK_REQUEST_NAMESPACE_ENTER,
LANDLOCK_REQUEST_CAPABILITY,
};
diff --git a/security/landlock/ns.c b/security/landlock/ns.c
index 06d9784746fe..3d443599b16f 100644
--- a/security/landlock/ns.c
+++ b/security/landlock/ns.c
@@ -90,6 +90,7 @@ static const struct access_masks ns_permission = {
* check_ns_type - Check namespace use permission
*
* @ns: The namespace being allocated or installed.
+ * @request_type: Namespace operation reported on denial.
*
* Shared check for namespace_init (creation via clone(2), unshare(2),
* open_tree(2), or fsmount(2)) and namespace_install (use via setns(2)): denies
@@ -99,7 +100,8 @@ static const struct access_masks ns_permission = {
*
* Return: 0 if allowed, -EPERM if denied.
*/
-static int check_ns_type(struct ns_common *const ns)
+static int check_ns_type(struct ns_common *const ns,
+ const enum landlock_request_type request_type)
{
const struct landlock_cred_security *subject;
size_t denied_layer;
@@ -117,7 +119,7 @@ static int check_ns_type(struct ns_common *const ns)
landlock_log_denial(subject,
&(struct landlock_request){
- .type = LANDLOCK_REQUEST_NAMESPACE,
+ .type = request_type,
.audit.type = LSM_AUDIT_DATA_NS,
.permission =
LANDLOCK_PERMISSION_NAMESPACE_USE,
@@ -130,13 +132,13 @@ static int check_ns_type(struct ns_common *const ns)
static int hook_namespace_init(struct ns_common *const ns)
{
- return check_ns_type(ns);
+ return check_ns_type(ns, LANDLOCK_REQUEST_NAMESPACE_CREATE);
}
static int hook_namespace_install(const struct nsset *const nsset,
struct ns_common *const ns)
{
- return check_ns_type(ns);
+ return check_ns_type(ns, LANDLOCK_REQUEST_NAMESPACE_ENTER);
}
static struct security_hook_list landlock_hooks[] __ro_after_init = {
diff --git a/security/landlock/trace.c b/security/landlock/trace.c
index 995c6b948e16..00cb497eaffb 100644
--- a/security/landlock/trace.c
+++ b/security/landlock/trace.c
@@ -81,7 +81,8 @@ void landlock_trace_denial(
const access_mask_t missing, const bool same_exec, const bool logged)
{
switch (request->type) {
- case LANDLOCK_REQUEST_NAMESPACE:
+ case LANDLOCK_REQUEST_NAMESPACE_CREATE:
+ case LANDLOCK_REQUEST_NAMESPACE_ENTER:
if (trace_landlock_deny_permission_namespace_enabled()) {
const struct landlock_blockers blockers = {
.access = missing,
diff --git a/tools/testing/selftests/landlock/ns_test.c b/tools/testing/selftests/landlock/ns_test.c
index 8f387fc47e21..d4a85cbebeae 100644
--- a/tools/testing/selftests/landlock/ns_test.c
+++ b/tools/testing/selftests/landlock/ns_test.c
@@ -1897,11 +1897,14 @@ TEST(setns_inherited_fd)
/* Audit tests */
+#define REGEX_LANDLOCK_NS_CREATE \
+ REGEX_LANDLOCK_PREFIX " blockers=namespace\\.use namespace_op=create"
+
static int matches_log_ns_create(int audit_fd, __u64 ns_type)
{
/* A denied creation logs the ID allocated for the new namespace. */
- static const char log_template[] = REGEX_LANDLOCK_PREFIX
- " blockers=namespace\\.use namespace_type=0x%x namespace_id=[1-9][0-9]*$";
+ static const char log_template[] = REGEX_LANDLOCK_NS_CREATE
+ " namespace_type=0x%x namespace_id=[1-9][0-9]*$";
char log_match[sizeof(log_template) + 10];
int log_match_len;
@@ -1917,12 +1920,12 @@ static int matches_log_ns_create(int audit_fd, __u64 ns_type)
static int matches_log_ns_setns(int audit_fd, __u64 ns_type, __u64 ns_id)
{
static const char log_template[] = REGEX_LANDLOCK_PREFIX
- " blockers=namespace\\.use namespace_type=0x%x namespace_id=%llu$";
+ " blockers=namespace\\.use namespace_op=%s namespace_type=0x%x namespace_id=%llu$";
char log_match[sizeof(log_template) + 32];
int log_match_len;
log_match_len = snprintf(log_match, sizeof(log_match), log_template,
- (unsigned int)ns_type,
+ "enter", (unsigned int)ns_type,
(unsigned long long)ns_id);
if (log_match_len >= sizeof(log_match))
return -E2BIG;
@@ -1958,7 +1961,7 @@ FIXTURE_TEARDOWN(ns_audit)
/*
* Verifies that a denied namespace creation produces the expected audit record
- * with the namespace.use blocker string and namespace_type.
+ * with the namespace.use blocker string, namespace type, and create operation.
*/
TEST_F(ns_audit, create_denied)
{
@@ -2542,6 +2545,11 @@ static void test_ns_trace_denial(struct __test_metadata *const _metadata,
EXPECT_STRNE("0", field);
if (use_setns)
EXPECT_EQ(expected_ns_id, strtoull(field, NULL, 10));
+ ret = tracefs_extract_field(buf,
+ REGEX_DENY_PERMISSION_NAMESPACE(TRACE_TASK),
+ "namespace_op", field, sizeof(field));
+ ASSERT_EQ(0, ret);
+ EXPECT_STREQ(use_setns ? "enter" : "create", field);
free(buf);
}
diff --git a/tools/testing/selftests/landlock/trace.h b/tools/testing/selftests/landlock/trace.h
index 36e8f16171b0..e67f239a8507 100644
--- a/tools/testing/selftests/landlock/trace.h
+++ b/tools/testing/selftests/landlock/trace.h
@@ -185,6 +185,7 @@
"same_exec=[01] " \
"logged=[01] " \
"blockers=[a-z_|]* " \
+ "namespace_op=\\(create\\|enter\\) " \
"namespace_type=0x[0-9a-f]\\+ " \
"namespace_id=[0-9]\\+$"
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v2 1/4] landlock: Distinguish namespace creation and entry denials
2026-11-18 16:32 ` [PATCH v2 1/4] landlock: Distinguish namespace creation and entry denials Mickaël Salaün
@ 2026-11-18 16:40 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-18 16:40 UTC (permalink / raw)
Cc: audit, linux-security-module
> Landlock reports denied namespace creation and entry with the same
> internal request type. Before commit 08471914d6bb ("ns: allocate the
> namespace id before the namespace_init hook"), denied creation carried
> ID zero and could be distinguished from entry by ID alone. That commit
> moved ID allocation before namespace_init(), so creation now carries the
> ID of an unreachable new namespace while entry carries the existing
> target ID. Namespace IDs are object context, not operation
> discriminators.
>
> Split the request type into creation and entry. Keep the two namespace
> values together before capability; this renumbers the unreleased
> capability request in raw and typed trace context. Report
> namespace_op=create or namespace_op=enter immediately after blockers in
> namespace audit records and trace event text. Placing the operation
> before namespace_type and namespace_id lets consumers establish the
> semantics before interpreting the following namespace context,
> especially whether namespace_id is the creation-time value or identifies
> an existing entry target.
>
> Keep namespace.use as the policy blocker: the new value only describes
> the semantic hook context and does not add a policy control.
>
> Cc: Günther Noack <gnoack@google.com>
> Fixes: 15dd86021b57 ("landlock: Enforce namespace use restrictions")
> Signed-off-by: Mickaël Salaün <mic@digikod.net>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118163254.2554413-1-mic@digikod.net?part=1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 2/4] landlock: Add capability objects to denial tracing
2026-11-18 16:32 [PATCH v2 0/4] Landlock: Fix namespace and capability denials Mickaël Salaün
2026-11-18 16:32 ` [PATCH v2 1/4] landlock: Distinguish namespace creation and entry denials Mickaël Salaün
@ 2026-11-18 16:32 ` Mickaël Salaün
2026-11-18 16:39 ` sashiko-bot
2026-11-18 16:32 ` [PATCH v2 3/4] selftests/landlock: Test namespace denial operations Mickaël Salaün
2026-11-18 16:32 ` [PATCH v2 4/4] landlock: Document " Mickaël Salaün
3 siblings, 1 reply; 9+ messages in thread
From: Mickaël Salaün @ 2026-11-18 16:32 UTC (permalink / raw)
To: Günther Noack
Cc: Mickaël Salaün, Christian Brauner, Eric Paris,
Masami Hiramatsu, Mathieu Desnoyers, Paul Moore, Steven Rostedt,
audit, kernel-team, linux-security-module, linux-trace-kernel
The capability denial tracepoint identifies the capability number but
not the credentials or user namespace against which it was checked.
Typed BPF consumers therefore cannot reconstruct the authoritative hook
context, especially when a check targets a user namespace other than the
caller's current namespace.
Carry the exact cred and user_ns used by each commoncap check through
check_cap() to the tracepoint's BTF prototype. The capable hook
forwards its arguments. Other callers mirror old->user_ns for
CAP_SETPCAP, and init_user_ns for CAP_SYS_RAWIO and CAP_SYS_ADMIN. The
latter checks protect global hardening and the global admin memory
reserve, so nested user-namespace capabilities must not authorize them.
Keep these pointers out of TP_STRUCT__entry and TP_printk so the raw
ring-buffer layout and textual format remain unchanged. They provide
context only and do not participate in Landlock's verdict.
Do not carry the capability options. CAP_OPT_NOAUDIT already suppresses
the complete denial record, and the remaining option bits do not explain
the checked security relationship.
Cc: Günther Noack <gnoack@google.com>
Fixes: 97c8386f1d74 ("landlock: Enforce capability restrictions")
Signed-off-by: Mickaël Salaün <mic@digikod.net>
---
Changes since v1:
https://patch.msgid.link/20261117102110.2524197-3-mic@digikod.net
- Adapt check_cap() callers on landlock-next to forward the exact target
user namespace used by commoncap.
- Document why global checks target init_user_ns and identify the new
standard BTF objects as commoncap check context.
---
Documentation/trace/events-landlock.rst | 6 ++--
include/trace/events/landlock.h | 11 ++++--
security/landlock/cap.c | 45 ++++++++++++++++++-------
security/landlock/log.h | 9 +++++
security/landlock/trace.c | 9 ++++-
5 files changed, 61 insertions(+), 19 deletions(-)
diff --git a/Documentation/trace/events-landlock.rst b/Documentation/trace/events-landlock.rst
index dc5f05a17c2c..1ddc123df59e 100644
--- a/Documentation/trace/events-landlock.rst
+++ b/Documentation/trace/events-landlock.rst
@@ -303,9 +303,9 @@ event prototypes in `Event reference`_ document their argument layouts.
The arguments include both standard kernel objects and Landlock-internal
objects:
-- Standard kernel objects (``struct task_struct``, ``struct sock``,
- ``struct path``, ``struct dentry``) can be used with existing BPF
- helpers.
+- Standard kernel objects (for example ``struct task_struct``, ``struct cred``,
+ ``struct user_namespace``, ``struct sock``, ``struct path``, and
+ ``struct dentry``) can be used with existing BPF helpers.
- Landlock-internal objects (``struct landlock_domain``,
``struct landlock_ruleset``, ``struct landlock_rule``,
``struct landlock_hierarchy``) can be read via ``BPF_CORE_READ``.
diff --git a/include/trace/events/landlock.h b/include/trace/events/landlock.h
index 9b3e24a613d8..09e90e4a9cd7 100644
--- a/include/trace/events/landlock.h
+++ b/include/trace/events/landlock.h
@@ -21,6 +21,7 @@
#include <net/af_unix.h>
enum landlock_request_type;
+struct cred;
struct dentry;
struct landlock_blockers;
struct landlock_domain;
@@ -30,6 +31,7 @@ struct landlock_ruleset;
struct path;
struct sock;
struct task_struct;
+struct user_namespace;
static_assert(sizeof(access_mask_t) <= sizeof(u64));
@@ -1046,6 +1048,9 @@ TRACE_EVENT(landlock_deny_permission_namespace,
* @logged: Whether this denial was selected for audit logging.
* @blockers: Request type and final missing permission subset (never NULL).
* @capability: CAP_* number that was denied.
+ * @cred: Credentials used by commoncap's capability check (never NULL).
+ * @user_ns: Target user namespace used by commoncap's capability check (never
+ * NULL).
*
* Emitted when a Landlock domain denies capability use, except for checks
* made with CAP_OPT_NOAUDIT, which are denied without emitting this event.
@@ -1054,9 +1059,11 @@ TRACE_EVENT(landlock_deny_permission_capability,
TP_PROTO(const struct landlock_hierarchy *hierarchy, bool same_exec,
bool logged, const struct landlock_blockers *blockers,
- int capability),
+ int capability, const struct cred *cred,
+ const struct user_namespace *user_ns),
- TP_ARGS(hierarchy, same_exec, logged, blockers, capability),
+ TP_ARGS(hierarchy, same_exec, logged, blockers, capability, cred,
+ user_ns),
TP_STRUCT__entry(
__field( u64, domain_id )
diff --git a/security/landlock/cap.c b/security/landlock/cap.c
index caf514be3df0..ae3acd13a367 100644
--- a/security/landlock/cap.c
+++ b/security/landlock/cap.c
@@ -28,6 +28,10 @@ static const struct access_masks cap_permission = {
* check_cap - Check a capability use against the domain of @cred
*
* @cred: Credentials being checked.
+ * @ns: Target user namespace used by commoncap's capability check, which is
+ * not necessarily @cred->user_ns. It is forwarded unchanged to typed
+ * trace context but is not used for the verdict (policy depends on @cred
+ * and @cap).
* @cap: Capability number (CAP_*).
* @opts: Capability check options. CAP_OPT_NOAUDIT skips the denial record:
* no audit record, no trace event, and no denial count.
@@ -38,7 +42,8 @@ static const struct access_masks cap_permission = {
*
* Return: 0 if allowed, -EPERM if capability use is denied.
*/
-static int check_cap(const struct cred *const cred, const int cap,
+static int check_cap(const struct cred *const cred,
+ struct user_namespace *const ns, const int cap,
const unsigned int opts)
{
const struct landlock_cred_security *subject;
@@ -64,6 +69,13 @@ static int check_cap(const struct cred *const cred, const int cap,
.permission =
LANDLOCK_PERMISSION_CAPABILITY_USE,
.layer_plus_one = denied_layer,
+#ifdef CONFIG_TRACEPOINTS
+ .trace_cap =
+ &(struct landlock_cap_trace){
+ .cred = cred,
+ .user_ns = ns,
+ },
+#endif /* CONFIG_TRACEPOINTS */
});
return -EPERM;
@@ -73,8 +85,7 @@ static int check_cap(const struct cred *const cred, const int cap,
* hook_capable - Deny capability use for Landlock-sandboxed processes
*
* @cred: Credentials being checked.
- * @ns: Target user namespace (intentionally ignored; policy depends on the
- * acting credentials and @cap, not namespace ownership).
+ * @ns: Target user namespace, used only as typed trace context.
* @cap: Capability number (CAP_*).
* @opts: Capability check options, see check_cap().
*
@@ -88,7 +99,7 @@ static int check_cap(const struct cred *const cred, const int cap,
static int hook_capable(const struct cred *cred, struct user_namespace *ns,
int cap, unsigned int opts)
{
- return check_cap(cred, cap, opts);
+ return check_cap(cred, ns, cap, opts);
}
/**
@@ -118,7 +129,7 @@ static int hook_capset(struct cred *new, const struct cred *old,
cap_combine(old->cap_inheritable, old->cap_permitted)))
return 0;
- return check_cap(old, CAP_SETPCAP, CAP_OPT_NONE);
+ return check_cap(old, old->user_ns, CAP_SETPCAP, CAP_OPT_NONE);
}
/**
@@ -127,8 +138,11 @@ static int hook_capset(struct cred *new, const struct cred *old,
* @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
+ * calls cap_capable() directly, which skips hook_capable(). It checks the
+ * acting task's credentials against init_user_ns because this global limit must
+ * not be bypassed with a capability only held in a nested user namespace.
+ * Mirror the condition, using the same credential for the domain check and both
+ * objects for typed trace context. commoncap runs first, so this only sees
* mappings that commoncap allowed.
*
* Return: 0 if allowed, -EPERM if CAP_SYS_RAWIO use is denied.
@@ -138,7 +152,8 @@ 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);
+ return check_cap(current_cred(), &init_user_ns, CAP_SYS_RAWIO,
+ CAP_OPT_NONE);
}
/**
@@ -148,10 +163,13 @@ static int hook_mmap_addr(unsigned long addr)
* @pages: Number of pages being charged (unused).
*
* cap_vm_enough_memory() lets CAP_SYS_ADMIN use the vm.admin_reserve_kbytes
- * reserve, but calls cap_capable() directly, which skips hook_capable(). Check
- * the same capability against the domain. commoncap runs first, so this only
- * sees tasks that commoncap let use the reserve. Like commoncap, do not log
- * denials: this only selects a memory limit.
+ * reserve, but calls cap_capable() directly, which skips hook_capable(). It
+ * checks the acting task's credentials against init_user_ns because a
+ * capability only held in a nested user namespace must not grant access to the
+ * global reserve. Mirror the check, using the same credential for the domain
+ * check and both objects for typed trace context. commoncap runs first, so
+ * this only sees tasks that commoncap let use the reserve. Like commoncap, do
+ * not log denials: this only selects a memory limit.
*
* Return: 0 if the domain does not withhold the reserve, -EPERM if
* CAP_SYS_ADMIN use is denied. An error does not fail the allocation by
@@ -159,7 +177,8 @@ static int hook_mmap_addr(unsigned long addr)
*/
static int hook_vm_enough_memory(struct mm_struct *mm, long pages)
{
- return check_cap(current_cred(), CAP_SYS_ADMIN, CAP_OPT_NOAUDIT);
+ return check_cap(current_cred(), &init_user_ns, CAP_SYS_ADMIN,
+ CAP_OPT_NOAUDIT);
}
static struct security_hook_list landlock_hooks[] __ro_after_init = {
diff --git a/security/landlock/log.h b/security/landlock/log.h
index 641a2c3c78ed..5ca87870c7b7 100644
--- a/security/landlock/log.h
+++ b/security/landlock/log.h
@@ -13,10 +13,12 @@
#include "access.h"
+struct cred;
struct landlock_cred_security;
struct landlock_hierarchy;
struct sockaddr;
struct task_struct;
+struct user_namespace;
enum landlock_request_type {
LANDLOCK_REQUEST_PTRACE = 1,
@@ -54,6 +56,11 @@ struct landlock_signal_trace {
int signal;
};
+struct landlock_cap_trace {
+ const struct cred *cred;
+ const struct user_namespace *user_ns;
+};
+
#endif /* CONFIG_TRACEPOINTS */
/*
@@ -104,6 +111,8 @@ struct landlock_request {
const struct landlock_ptrace_trace *trace_ptrace;
/* Synchronous context for a signal denial. */
const struct landlock_signal_trace *trace_signal;
+ /* Synchronous context for a capability denial. */
+ const struct landlock_cap_trace *trace_cap;
};
#endif /* CONFIG_TRACEPOINTS */
};
diff --git a/security/landlock/trace.c b/security/landlock/trace.c
index 00cb497eaffb..a47fb10dec45 100644
--- a/security/landlock/trace.c
+++ b/security/landlock/trace.c
@@ -97,14 +97,21 @@ void landlock_trace_denial(
break;
case LANDLOCK_REQUEST_CAPABILITY:
if (trace_landlock_deny_permission_capability_enabled()) {
+ const struct landlock_cap_trace *const trace_cap =
+ request->trace_cap;
const struct landlock_blockers blockers = {
.access = missing,
.type = request->type,
};
+ if (WARN_ON_ONCE(!trace_cap || !trace_cap->cred ||
+ !trace_cap->user_ns))
+ return;
+
trace_landlock_deny_permission_capability(
youngest_denied, same_exec, logged, &blockers,
- request->audit.u.cap);
+ request->audit.u.cap, trace_cap->cred,
+ trace_cap->user_ns);
}
break;
case LANDLOCK_REQUEST_FS_ACCESS:
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v2 2/4] landlock: Add capability objects to denial tracing
2026-11-18 16:32 ` [PATCH v2 2/4] landlock: Add capability objects to denial tracing Mickaël Salaün
@ 2026-11-18 16:39 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-18 16:39 UTC (permalink / raw)
Cc: audit, linux-security-module
> The capability denial tracepoint identifies the capability number but
> not the credentials or user namespace against which it was checked.
> Typed BPF consumers therefore cannot reconstruct the authoritative hook
> context, especially when a check targets a user namespace other than the
> caller's current namespace.
>
> Carry the exact cred and user_ns used by each commoncap check through
> check_cap() to the tracepoint's BTF prototype. The capable hook
> forwards its arguments. Other callers mirror old->user_ns for
> CAP_SETPCAP, and init_user_ns for CAP_SYS_RAWIO and CAP_SYS_ADMIN. The
> latter checks protect global hardening and the global admin memory
> reserve, so nested user-namespace capabilities must not authorize them.
>
> Keep these pointers out of TP_STRUCT__entry and TP_printk so the raw
> ring-buffer layout and textual format remain unchanged. They provide
> context only and do not participate in Landlock's verdict.
>
> Do not carry the capability options. CAP_OPT_NOAUDIT already suppresses
> the complete denial record, and the remaining option bits do not explain
> the checked security relationship.
>
> Cc: Günther Noack <gnoack@google.com>
> Fixes: 97c8386f1d74 ("landlock: Enforce capability restrictions")
> Signed-off-by: Mickaël Salaün <mic@digikod.net>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118163254.2554413-1-mic@digikod.net?part=2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 3/4] selftests/landlock: Test namespace denial operations
2026-11-18 16:32 [PATCH v2 0/4] Landlock: Fix namespace and capability denials Mickaël Salaün
2026-11-18 16:32 ` [PATCH v2 1/4] landlock: Distinguish namespace creation and entry denials Mickaël Salaün
2026-11-18 16:32 ` [PATCH v2 2/4] landlock: Add capability objects to denial tracing Mickaël Salaün
@ 2026-11-18 16:32 ` Mickaël Salaün
2026-11-18 16:37 ` sashiko-bot
2026-11-18 16:32 ` [PATCH v2 4/4] landlock: Document " Mickaël Salaün
3 siblings, 1 reply; 9+ messages in thread
From: Mickaël Salaün @ 2026-11-18 16:32 UTC (permalink / raw)
To: Günther Noack
Cc: Mickaël Salaün, Christian Brauner, Eric Paris,
Masami Hiramatsu, Mathieu Desnoyers, Paul Moore, Steven Rostedt,
audit, kernel-team, linux-security-module, linux-trace-kernel
The namespace trace tests cover creation and entry denials, but only
creation exercises the quiet path. This leaves the new ENTER request
tag untested through quiet selection and trace dispatch when audit
logging is suppressed.
Add the missing quiet setns(2) case. Together with the existing cases,
this exercises all four combinations of CREATE and ENTER with logged and
quieted denials, including each exact namespace_op value.
Cc: Günther Noack <gnoack@google.com>
Signed-off-by: Mickaël Salaün <mic@digikod.net>
---
tools/testing/selftests/landlock/ns_test.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/tools/testing/selftests/landlock/ns_test.c b/tools/testing/selftests/landlock/ns_test.c
index d4a85cbebeae..52206ad94eca 100644
--- a/tools/testing/selftests/landlock/ns_test.c
+++ b/tools/testing/selftests/landlock/ns_test.c
@@ -2575,6 +2575,13 @@ TEST_F(ns_trace, deny_setns)
test_ns_trace_denial(_metadata, true, false);
}
+TEST_F(ns_trace, deny_setns_quiet)
+{
+ if (!self->tracefs_ok)
+ SKIP(return, "tracefs not available");
+ test_ns_trace_denial(_metadata, true, true);
+}
+
/* clang-format off */
FIXTURE(ns_proc_open) {
/* clang-format on */
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 4/4] landlock: Document namespace denial operations
2026-11-18 16:32 [PATCH v2 0/4] Landlock: Fix namespace and capability denials Mickaël Salaün
` (2 preceding siblings ...)
2026-11-18 16:32 ` [PATCH v2 3/4] selftests/landlock: Test namespace denial operations Mickaël Salaün
@ 2026-11-18 16:32 ` Mickaël Salaün
2026-11-18 16:39 ` sashiko-bot
3 siblings, 1 reply; 9+ messages in thread
From: Mickaël Salaün @ 2026-11-18 16:32 UTC (permalink / raw)
To: Günther Noack
Cc: Mickaël Salaün, Christian Brauner, Eric Paris,
Masami Hiramatsu, Mathieu Desnoyers, Paul Moore, Steven Rostedt,
audit, kernel-team, linux-security-module, linux-trace-kernel
Namespace denial records now distinguish creation from entry. Document
the namespace_op field in the audit and trace references, and clarify
that it describes the semantic namespace hook rather than exact syscall
provenance.
Creation reports the ID allocated for a namespace that never becomes
reachable, whereas entry reports the existing target ID.
Cc: Günther Noack <gnoack@google.com>
Signed-off-by: Mickaël Salaün <mic@digikod.net>
---
Documentation/admin-guide/LSM/landlock.rst | 21 ++++++++++++---------
Documentation/trace/events-landlock.rst | 20 +++++++++++++-------
2 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/Documentation/admin-guide/LSM/landlock.rst b/Documentation/admin-guide/LSM/landlock.rst
index 946f3bf89650..a79912e8a684 100644
--- a/Documentation/admin-guide/LSM/landlock.rst
+++ b/Documentation/admin-guide/LSM/landlock.rst
@@ -7,7 +7,7 @@ Landlock: system-wide management
================================
:Author: Mickaël Salaün
-:Date: October 2026
+:Date: November 2026
Landlock can leverage the audit framework to log events.
@@ -72,10 +72,13 @@ AUDIT_LANDLOCK_ACCESS
:manpage:`unshare(2)`, :manpage:`clone(2)`, :manpage:`clone3(2)`,
:manpage:`open_tree(2)`, or :manpage:`fsmount(2)`, or joining via
:manpage:`setns(2)`);
- ``namespace_type`` indicates the type (hex ``CLONE_NEW*`` bitmask),
- and ``namespace_id`` identifies the target namespace (for a denied
- creation, the namespace never becomes reachable so its ID is not
- directly visible from user space)
+ ``namespace_op`` is ``create`` for construction or ``enter`` for
+ :manpage:`setns(2)`. These values describe semantic namespace hooks,
+ not exact system calls. ``namespace_type`` indicates the type (hex
+ ``CLONE_NEW*`` bitmask), and ``namespace_id`` identifies the namespace
+ object. For a denied creation, the new namespace never becomes
+ reachable, so its ID is not directly visible from user space. For a
+ denied entry, this is the exact existing target ID.
**capability.*** - Capability restrictions (ABI 12+):
- capability.use - Capability use was denied;
@@ -86,10 +89,10 @@ AUDIT_LANDLOCK_ACCESS
in a directory that lacks both ``make_reg`` and ``refer`` rights would show
``blockers=fs.make_reg,fs.refer``.
- The object identification fields depend on the type of access being blocked:
- ``path``, ``dev``, ``ino`` for filesystem; ``opid``, ``ocomm`` for signals;
- ``namespace_type`` and ``namespace_id`` for namespace operations;
- ``capability`` for capability use.
+ The operation and object context fields depend on the type of access being
+ blocked: ``path``, ``dev``, ``ino`` for filesystem; ``opid``, ``ocomm`` for
+ signals; ``namespace_op``, ``namespace_type``, and ``namespace_id`` for
+ namespace operations; ``capability`` for capability use.
AUDIT_LANDLOCK_DOMAIN
diff --git a/Documentation/trace/events-landlock.rst b/Documentation/trace/events-landlock.rst
index 1ddc123df59e..0647a87677a1 100644
--- a/Documentation/trace/events-landlock.rst
+++ b/Documentation/trace/events-landlock.rst
@@ -6,7 +6,7 @@ Landlock Trace Events
=====================
:Author: Mickaël Salaün
-:Date: October 2026
+:Date: November 2026
Landlock emits trace events for sandbox lifecycle operations and access
denials. These events can be consumed by ftrace (for human-readable
@@ -186,13 +186,19 @@ known allowed and quiet member masks. Capability masks and the raw
therefore appears as zero while still advancing the ruleset version, and adding
a member already present still emits an event.
-``landlock_deny_permission_namespace`` reports the denied raw
-``CLONE_NEW*`` value. ``namespace_id`` is the exact target namespace ID. For
-a denied namespace creation, the namespace never becomes reachable so its ID
-is not directly visible from user space.
+``landlock_deny_permission_namespace`` reports ``namespace_op`` as ``create``
+for namespace construction, for example through :manpage:`clone(2)`,
+:manpage:`clone3(2)`, :manpage:`unshare(2)`, :manpage:`open_tree(2)`, or
+:manpage:`fsmount(2)`, and ``enter`` for :manpage:`setns(2)`. These values
+describe the semantic namespace hook, not the exact system call.
+``namespace_type`` is the denied raw ``CLONE_NEW*`` value. For a denied
+creation, ``namespace_id`` is allocated for the new namespace, which never
+becomes reachable, so its ID is not directly visible from user space. For a
+denied entry, ``namespace_id`` is the exact existing target ID.
+
``landlock_deny_permission_capability`` reports the denied ``CAP_*`` number.
-Like every denial event, both include the denying domain, ``same_exec``, and
-``logged``.
+Like every denial event, the namespace and capability events include the
+denying domain, ``same_exec``, and ``logged``.
Per-member quiet masks suppress audit submission but never these trace events,
which report ``logged=0``.
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread