diff --git a/include/trace/events/landlock.h b/include/trace/events/landlock.h
index 9b3e24a613d8..1e115c80b741 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,8 @@ 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 checked by the capability hook (never NULL).
+ * @user_ns: Target user namespace checked by the capability hook (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 +1058,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 b4f491b09baa..8e1a9c458783 100644
--- a/security/landlock/cap.c
+++ b/security/landlock/cap.c
@@ -27,8 +27,8 @@ static const struct access_masks cap_permission = {
* 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, forwarded unchanged to typed trace context but
+ * 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.@@ -67,6 +67,13 @@ static int hook_capable(const struct cred *cred, struct user_namespace *ns,
.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;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