All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: linux-fsdevel@vger.kernel.org, bpf@vger.kernel.org
Cc: linux-security-module@vger.kernel.org,
	 Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	 Paul Moore <paul@paul-moore.com>,
	netdev@vger.kernel.org,
	 "Christian Brauner (Amutable)" <brauner@kernel.org>,
	stable@kernel.org
Subject: [PATCH 4/8] landlock: pass the namespace id to log to check_ns_type()
Date: Mon, 26 Oct 2026 10:57:12 +0100	[thread overview]
Message-ID: <20261026-work-security-namespace_free-v1-4-ffa3ebbf71bd@kernel.org> (raw)
In-Reply-To: <20261026-work-security-namespace_free-v1-0-ffa3ebbf71bd@kernel.org>

Landlock logs the namespace id when it denies the use of a namespace.
check_ns_type() takes it from the namespace itself. When it is called
from the namespace_init hook the id is always zero as it is only
allocated after the hook has run.

A follow-up patch will allocate the id before the namespace_init hook is
called. But a namespace whose creation is denied never becomes visible
and the Landlock documentation says that namespace_id is zero for
namespace creation (cf. Documentation/admin-guide/LSM/landlock.rst and
Documentation/trace/events-landlock.rst). So pass the id to log to
check_ns_type() and keep passing zero from hook_namespace_init().

No functional changes.

Fixes: f675d2e95569 ("lsm: add LSM blob and hooks for namespaces")
Cc: <stable@kernel.org> # mainline only
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 security/landlock/ns.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/security/landlock/ns.c b/security/landlock/ns.c
index cd44c927f83a..39795c4e1404 100644
--- a/security/landlock/ns.c
+++ b/security/landlock/ns.c
@@ -90,15 +90,16 @@ static const struct access_masks ns_permission = {
  * check_ns_type - Check namespace use permission
  *
  * @ns: The namespace being allocated or installed.
+ * @ns_id: The namespace id to log.
  *
  * 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
  * when the namespace type is not in the domain's allowed set.  At allocation
- * time @ns->ns_id is still zero and is logged as such.
+ * time the namespace isn't visible yet so @ns_id is zero.
  *
  * 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 u64 ns_id)
 {
 	const struct landlock_cred_security *subject;
 	size_t denied_layer;
@@ -121,7 +122,7 @@ static int check_ns_type(struct ns_common *const ns)
 				    .permission =
 					    LANDLOCK_PERMISSION_NAMESPACE_USE,
 				    .audit.u.ns.ns_type = ns->ns_type,
-				    .audit.u.ns.ns_id = ns->ns_id,
+				    .audit.u.ns.ns_id = ns_id,
 				    .layer_plus_one = denied_layer,
 			    });
 	return -EPERM;
@@ -129,13 +130,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, 0);
 }
 
 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, ns->ns_id);
 }
 
 static struct security_hook_list landlock_hooks[] __ro_after_init = {

-- 
2.53.0


  parent reply	other threads:[~2026-10-26  9:57 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-26  9:57 [PATCH 0/8] ns: fixes for the namespace LSM hooks Christian Brauner
2026-10-26  9:57 ` [PATCH 1/8] lsm: always call the namespace_free hook Christian Brauner
2026-10-26 10:37   ` sashiko-bot
2026-10-26  9:57 ` [PATCH 2/8] bpf: don't mark namespace_init and namespace_free arguments as trusted Christian Brauner
2026-10-26 10:41   ` sashiko-bot
2026-10-26  9:57 ` [PATCH 3/8] selftests/bpf: add verifier tests for the namespace LSM hooks Christian Brauner
2026-10-26 10:44   ` sashiko-bot
2026-10-26  9:57 ` Christian Brauner [this message]
2026-10-26 10:45   ` [PATCH 4/8] landlock: pass the namespace id to log to check_ns_type() sashiko-bot
2026-10-29 11:27   ` Mickaël Salaün
2026-10-26  9:57 ` [PATCH 5/8] ns: allocate the namespace id before the namespace_init hook Christian Brauner
2026-10-26 10:51   ` sashiko-bot
2026-10-26  9:57 ` [PATCH 6/8] nstree: drop ns_tree_add_raw() Christian Brauner
2026-10-26 10:55   ` sashiko-bot
2026-10-26  9:57 ` [PATCH 7/8] lsm: fix the security_namespace_init() kernel-doc Christian Brauner
2026-10-26 10:57   ` sashiko-bot
2026-10-26  9:57 ` [PATCH 8/8] selftests/bpf: add a lifecycle test for the namespace LSM hooks Christian Brauner
2026-10-26 11:03   ` sashiko-bot
2026-10-26 20:31 ` [PATCH 0/8] ns: fixes " Paul Moore
2026-10-27  9:24   ` Christian Brauner
2026-10-27 14:36     ` Daniel Borkmann
2026-10-27 22:37     ` Paul Moore
2026-10-28 10:42       ` Christian Brauner
2026-10-28 15:59         ` Paul Moore
2026-10-26 23:31 ` Alexei Starovoitov

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=20261026-work-security-namespace_free-v1-4-ffa3ebbf71bd@kernel.org \
    --to=brauner@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=paul@paul-moore.com \
    --cc=stable@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.