Skip to contentSkip to conversation

Landlock: Fix namespace and capability denials

PATCH New Mickaël Salaün 2 participants 9 messages Nov 18

Subsystems (6)
lore
Share & tools
lore

Mickaël Salaün

author maintainer
#0 lore raw

v2 cover Landlock: Fix namespace and capability denials

Hi,

Landlock namespace denial records identify the namespace type and ID but do not say whether the hook denied creation or entry. The ID is object context rather than an operation discriminator: after allocating IDs before the namespace_init hook, construction carries an ID for a new namespace that never becomes reachable, whereas entry carries the existing target ID.

Capability denial tracepoints have the complementary problem. They report the capability number but omit the exact credentials and target user namespace used by commoncap's capability check. Either argument can differ from current state, so reconstructing them from the tracing task can misidentify the security relationship being checked.

Fix both denial interfaces without changing Landlock policy or UAPI. Namespace denials gain distinct internal CREATE and ENTER request tags and print namespace_op=create or namespace_op=enter after the common blockers field and before the namespace type and ID. Both operations remain context for the same namespace.use blocker and describe semantic hooks rather than exact syscall provenance.

Capability denial tracepoints gain the authoritative checked cred and target user_ns as synchronous BTF-only arguments. They are not copied into the raw ring buffer, printed, audited, retained, or used for the Landlock verdict. Capability options remain omitted: CAP_OPT_NOAUDIT suppresses the denial record, while the remaining bits do not explain a Landlock decision.

Paul and Eric, please review the audit record addition and field ordering. The new namespace_op field is Landlock-local because Landlock is currently the only LSM_AUDIT_DATA_NS emitter; it can move to the generic formatter if another LSM later needs the same contract.

The base includes Christian's namespace-ID allocation fix. Patch 1 distinguishes namespace creation and entry in audit and trace output. Patch 2 supplies the checked capability objects to typed trace consumers. Patch 3 completes quiet ENTER coverage in the Landlock selftests. Patch 4 documents the namespace operation field.

Changes since v1:
https://patch.msgid.link/[email protected]
- Rebase on the commoncap-check fixes, forward their exact user namespace context, and document why global checks target the initial user namespace.
- List the new standard BTF objects, correct capable-hook-only wording, and trim duplicate commit-message narration.

This series depends on the commoncap-check fixes:
https://patch.msgid.link/[email protected]

Regards,

Mickaël Salaün (4):
landlock: Distinguish namespace creation and entry denials
landlock: Add capability objects to denial tracing selftests/landlock: Test namespace denial operations
landlock: Document namespace denial operations

 Documentation/admin-guide/LSM/landlock.rst | 21 +++++-----
 Documentation/trace/events-landlock.rst    | 26 ++++++++-----
 include/trace/events/landlock.h            | 36 +++++++++++------
 security/landlock/audit.c                  | 10 ++++-
 security/landlock/cap.c                    | 45 +++++++++++++++-------
 security/landlock/log.c                    |  6 ++-
 security/landlock/log.h                    | 12 +++++-
 security/landlock/ns.c                     | 10 +++--
 security/landlock/trace.c                  | 12 +++++-
 tools/testing/selftests/landlock/ns_test.c | 25 +++++++++---
 tools/testing/selftests/landlock/trace.h   |  1 +
 11 files changed, 145 insertions(+), 59 deletions(-)

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
prerequisite-patch-id: 365071039dd2be439f67707944d12edbe1422d60
prerequisite-patch-id: 021705fb5147cdc8edcac9dbe53c06b854cf976a
prerequisite-patch-id: ddc6687ae87f8f782ed8ad5b005834f242aec2fb
prerequisite-patch-id: 0bf745b08b99168d266461ef5b0b943a2b71eceb
prerequisite-patch-id: 03ec09be2416d4cc932b07dfb0e7450f15c22804
prerequisite-patch-id: 383fa2ce8a4ed44e4b5c828c99c5be5ee75048af

Signature · 1 line
2.56.0
author maintainer
#1 lore raw

PATCH v2 1/4 landlock: Distinguish namespace creation and entry denials

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 <[email protected]>
Fixes 15dd86021b57 ("landlock: Enforce namespace use restrictions")

---

Changes since v1:
https://patch.msgid.link/[email protected]
- 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(-)
include/trace/events/landlock.h +16 -9
index b6fdc6e2eef8..9b3e24a613d8 100644
@@ -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)
 );
 
 /**
security/landlock/audit.c +8 -2
index be49ef47b4ea..6d9e54f5deed 100644
@@ -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);
 
security/landlock/log.c +4 -2
index 43efbb95725c..c132b343f0ee 100644
@@ -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:
security/landlock/log.h +2 -1
index 596feeeb7aa6..641a2c3c78ed 100644
@@ -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,
 };
 
security/landlock/ns.c +6 -4
index 06d9784746fe..3d443599b16f 100644
@@ -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 = {
security/landlock/trace.c +2 -1
index 995c6b948e16..00cb497eaffb 100644
@@ -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,
tools/testing/selftests/landlock/ns_test.c +13 -5
index 8f387fc47e21..d4a85cbebeae 100644
@@ -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);
 }
tools/testing/selftests/landlock/trace.h +1 -0
index 36e8f16171b0..e67f239a8507 100644
@@ -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]\\+$"
 
Signature · 1 line
2.56.0
#2 lore raw

Re: [PATCH v2 1/4] landlock: Distinguish namespace creation and entry denials

Sashiko has reviewed this patch and found no issues.
Quoted 19 lines

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.

Quoted 6 lines

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 <[email protected]>
Fixes 15dd86021b57 ("landlock: Enforce namespace use restrictions")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author maintainer
#3 lore raw

PATCH v2 2/4 landlock: Add capability objects to denial tracing

In reply to Mickaël Salaün

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 <[email protected]>
Fixes 97c8386f1d74 ("landlock: Enforce capability restrictions")

---

Changes since v1:
https://patch.msgid.link/[email protected]
- 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(-)
Documentation/trace/events-landlock.rst +3 -3
index dc5f05a17c2c..1ddc123df59e 100644
@@ -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``.
include/trace/events/landlock.h +9 -2
index 9b3e24a613d8..09e90e4a9cd7 100644
@@ -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	)
security/landlock/cap.c +32 -13

105 lines not on this page · raw message

security/landlock/log.h +9 -0
index 641a2c3c78ed..5ca87870c7b7 100644
@@ -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 */
 };
security/landlock/trace.c +8 -1
index 00cb497eaffb..a47fb10dec45 100644
@@ -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:
Signature · 1 line
2.56.0
#4 lore raw

Re: [PATCH v2 2/4] landlock: Add capability objects to denial tracing

Sashiko has reviewed this patch and found no issues.
Quoted 17 lines

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.

Quoted 7 lines

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 <[email protected]>
Fixes 97c8386f1d74 ("landlock: Enforce capability restrictions")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
author maintainer
#5 lore raw

PATCH v2 3/4 selftests/landlock: Test namespace denial operations

In reply to Mickaël Salaün

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.

---
 tools/testing/selftests/landlock/ns_test.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/testing/selftests/landlock/ns_test.c +7 -0
index d4a85cbebeae..52206ad94eca 100644
@@ -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 */
Signature · 1 line
2.56.0
#6 lore raw

Re: [PATCH v2 3/4] selftests/landlock: Test namespace denial operations

Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

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.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
author maintainer
#7 lore raw

PATCH v2 4/4 landlock: Document namespace denial operations

In reply to Mickaël Salaün

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.

---
 Documentation/admin-guide/LSM/landlock.rst | 21 ++++++++++++---------
 Documentation/trace/events-landlock.rst    | 20 +++++++++++++-------
 2 files changed, 25 insertions(+), 16 deletions(-)
Documentation/admin-guide/LSM/landlock.rst +12 -9
index 946f3bf89650..a79912e8a684 100644
@@ -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
Documentation/trace/events-landlock.rst +13 -7
index 1ddc123df59e..0647a87677a1 100644
@@ -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``.
Signature · 1 line
2.56.0
#8 lore raw

Re: [PATCH v2 4/4] landlock: Document namespace denial operations

Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

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.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4