From: "Mickaël Salaün" <mic@digikod.net>
To: "Günther Noack" <gnoack@google.com>
Cc: "Mickaël Salaün" <mic@digikod.net>,
"Christian Brauner" <brauner@kernel.org>,
"Eric Paris" <eparis@redhat.com>,
"Masami Hiramatsu" <mhiramat@kernel.org>,
"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
"Paul Moore" <paul@paul-moore.com>,
"Steven Rostedt" <rostedt@goodmis.org>,
audit@vger.kernel.org, linux-security-module@vger.kernel.org,
linux-trace-kernel@vger.kernel.org
Subject: [PATCH 2/4] landlock: Add capability objects to denial tracing
Date: Tue, 17 Nov 2026 11:21:05 +0100 [thread overview]
Message-ID: <20261117102110.2524197-3-mic@digikod.net> (raw)
In-Reply-To: <20261117102110.2524197-1-mic@digikod.net>
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 arguments from capable() through the
synchronous Landlock logging request and add them to the tracepoint's
BTF prototype. Keep them 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>
---
include/trace/events/landlock.h | 10 ++++++++--
security/landlock/cap.c | 11 +++++++++--
security/landlock/log.h | 9 +++++++++
security/landlock/trace.c | 9 ++++++++-
4 files changed, 34 insertions(+), 5 deletions(-)
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
next prev parent reply other threads:[~2026-11-17 10:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 10:21 [PATCH 0/4] Landlock: Fix namespace and capability denials Mickaël Salaün
2026-11-17 10:21 ` [PATCH 1/4] landlock: Distinguish namespace creation and entry denials Mickaël Salaün
2026-11-17 10:21 ` Mickaël Salaün [this message]
2026-11-17 10:21 ` [PATCH 3/4] selftests/landlock: Test namespace denial operations Mickaël Salaün
2026-11-17 10:21 ` [PATCH 4/4] landlock: Document " Mickaël Salaün
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261117102110.2524197-3-mic@digikod.net \
--to=mic@digikod.net \
--cc=audit@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=eparis@redhat.com \
--cc=gnoack@google.com \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=paul@paul-moore.com \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox