Article View: linux.kernel.netdev
Article #8544Re: [PATCH 4/8] landlock: pass the namespace id to log to check_ns_type()
From: Mickaël Salaün
Date: Thu, 29 Oct 2026 11:27
Date: Thu, 29 Oct 2026 11:27
94 lines
12425 bytes
12425 bytes
On Mon, Oct 26, 2026 at 10:57:12AM +0100, Christian Brauner wrote:
> 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);
The use of 0 as a namespace ID in logs was mainly a consequence of the
hook implementation and the fact that no ID were visible to user space.
This changes with this series: the kernel allocates a new ID and other
LSMs see this newly created ID. Landlock's logs should follow this
change consistently and always reflect the real namespace ID instead of
faking it with 0 for namespace creation.
Could you please update the doc and tests instead? The doc should still
warn that when blocking a namespace creation, the logged namespace ID is
still not *directly* visible from user space.
Being able to differentiate namespace creation (i.e. when a namespace is
not yet reachable by user space) from a namespace enter operation is
important for Landlock from an observability point of view. We then
need at least the Landlock tracepoints to make this possible. I'm
working alongside what you're doing and I'll send patches next week.
> }
>
> 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
>
>
Technical Details
Message-ID:
<20261028.oonaisai0Doh@digikod.net>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353267-linux-kernel-netdev=dewy.ruReferences:
<20261026-work-security-namespace_free-v1-0-ffa3ebbf71bd@kernel.org> <20261026-work-security-namespace_free-v1-4-ffa3ebbf71bd@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353267-linux-kernel-netdev=dewy.ru From: mic@digikod.net (Mickaël Salaün) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH 4/8] landlock: pass the namespace id to log to check_ns_type() Date: Thu, 29 Oct 2026 12:27:47 +0100 Organization: Usenet Network Message-ID: <20261028.oonaisai0Doh@digikod.net> References: <20261026-work-security-namespace_free-v1-0-ffa3ebbf71bd@kernel.org> <20261026-work-security-namespace_free-v1-4-ffa3ebbf71bd@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Injection-Info: usenet.network; logging-data="1996246"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:t2X/kwXgWJSsJCJjSXTnGywr2/Q= sha256:Z2uRxOY0eJO2U6lc45J9IDj/vdG6AudrVA/fiARQ3eM= sha1:RZLnl9jWmD3Z2HdqqMq/DwPy0eU= sha256:Q38Q4FHJTbaafJyavsarjDWvGs3e4CeicvH856WEABY= Content-Disposition: inline List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 3972B125C64; Thu, 29 Oct 2026 14:28:42 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.05 X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=digikod.net X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Po1QIVm1aXMf; Thu, 29 Oct 2026 14:28:39 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-353267-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=digikod.net X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 271DB125C62; Thu, 29 Oct 2026 14:28:30 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id ABAC6275F0; Thu, 29 Oct 2026 11:28:12 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793273290; b=EkgZsajwIVSX1AHTpouPFcd6s8SznW6yAZ9DY7uKl8orLlV8pDQ3pSs0StYKvkCeUgcH QtpuI2AUeYc2hLBVBzDBo5p+pdiKGLWXAK3WpBI9enQt3V8pm9HmrYlalL77GThnwVT0H W8JDh1EdUx8hzslSaq+vim7CGRgwF7GgO4yNneeykwHo8/ryGR5Ub8skQXHFhkWLALyEA z/Sec8VlOmXjYJwsRYhPAbb6rECnxdxjtDTl9IUVrHYmas4sDclqzswmg1d88kzWh5F6U 1SjfrpfofBelJXtawKQQhMIA0xC8ToPtodqNGXmh3oPBzhp2u0F6EqLpuPRlmlrq7kw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793273290; h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:Received: Date:From:To:Cc:Subject:Message-ID:References:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version:Content-Type:Content-Disposition:In-Reply-To: X-Infomaniak-Routing; bh=LaD9WrR+AACReb/Fw3idhuufgElFfvZMlx/OJIXbArA=; b=eTKCRjhusbV1ZBnWl5lAmlMOLP34fqKalSo4r5z5aoXcTa8FE/zwDW2/Pk8QoRpab3t/ 4bDKJODyTQPZUkJPODn/ojTMT3Ug9V9Z+X1ila0uDU0FKCSHMUBRWK1hTx7vffak+WGs9 xmvZCoUVPPahwnxTi18lID1QPU1HWgTGXcGZUoy3H5+JpWElqt0saHzNfswNyhDsP6z/X FXkNuCQSCtejFC2w4ZB++NXUhYlU/04YBaHLev1iBqPGOcMXpe3p5QZtkuKNIJ/vEURsh ST+hhSwbO17yVjkSnHC+r6gYO6+y0FhHja+SPdLlixwH2o1+7mjoV2dUGSWLnP9vKPQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=digikod.net header.i=@digikod.net header.a=rsa-sha256 header.s=20191114 header.b=GzCpnY9w; dmarc=none header.from=digikod.net; spf=pass smtp.mailfrom=digikod.net; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E9C4606A31E; Thu, 29 Oct 2026 11:28:10 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=digikod.net header.i=@digikod.net header.a=rsa-sha256 header.s=20191114 header.b=GzCpnY9w X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.125.25.13 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793273284; b=pehw9vG3OV6tm0qUW517NB73eSO8IMDE2upUHtqdKR5+T2lQR1FcXKbwtnN7qde8P9xM MJNQutxV2PQSIwW5vbCLYPt5mKFRMLXKX69P+cxYH24/lUQ4YgP+cb/A2ZqiVxPgSvnz7 /MvUcxZowveslbdNJ8Pig2ZFEc7/mh84OhVl/mid1AthRcQk4NiLZAQHMrgXxA1a20/wC 7NoNe5JY5i6BKJsUoi3U7d0fntylbL8dcF23JKqbZrPS5TbxSkBTT0W/KWEoRDHrDCPFd aZkDnpVlEWsZoeiEHLobUKy6Dd2HE8Jxio1AcLpY2kYxEUrNxsJn9rVSMtjijsDziew== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793273284; h=DMARC-Filter:Received:DKIM-Signature:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To:X-Infomaniak-Routing; bh=LaD9WrR+AACReb/Fw3idhuufgElFfvZMlx/OJIXbArA=; b=agp4Z5rxkKVovLeqbnu5kvJOvI16tMI7mBxabSuJkRMcUSjG2IPSCoKHXDXSKBw8FMnW JTbclpHb+egyTi+VS0K+W3eHMP7mpLXi4DuV9Jy/4+QhH+f3yBIKxzatjcJ2X9vVCy444 EtA4dSYIaXRgKqfHsGJTmzV65HJ32TplB8+H+KmR47kb1PRlWHl2MADtxsvTvM4wtu1t4 WR7ZEypNkGwoN6BB6BHxNxgLO6cW9w7VUxfgtzVkDmMk9uNLmbiJNijKizAxhamyoDSzQ nLILsO264sG1bx8WjyZobxhZkGIroxTcQVNfnl73WBIhgpatxPkwvInVSEZHtl1lxsQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=digikod.net; spf=pass smtp.mailfrom=digikod.net; dkim=pass header.d=digikod.net header.i=@digikod.net header.a=rsa-sha256 header.s=20191114 header.b=GzCpnY9w; arc=none smtp.remote-ip=185.125.25.13 X-Received: from smtp-190d.mail.infomaniak.ch (smtp-190d.mail.infomaniak.ch [185.125.25.13]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B99A0606A31C for <netdev@vger.kernel.org>; Thu, 29 Oct 2026 11:28:00 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B99A0606A31C X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=digikod.net X-Received: from smtp-3-0000.mail.infomaniak.ch (smtp-3-0000.mail.infomaniak.ch [10.4.36.107]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4jFhmS6Y9lzn3b; Thu, 29 Oct 2026 12:27:52 +0100 (CET) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digikod.net; s=20191114; t=1793273272; bh=LaD9WrR+AACReb/Fw3idhuufgElFfvZMlx/OJIXbArA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GzCpnY9wpDf60mcnYuroXbFa9YCakGFBrOjfurb2f7UxJM3jUmzmm71A+H/ex0U95 Ezw0UDC5/DXLdfO9xfh2E7NHLu4mmTw+EV8TXVuVR5Zv2qJiAyasin7EDuqpetc/yo QmYhNWapgWaCBAEkibByaPzDgOQutFwZnHYo9qng= X-Received: from unknown by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4jFhmR4mH2z8lf; Thu, 29 Oct 2026 12:27:51 +0100 (CET) X-Cc: linux-fsdevel@vger.kernel.org, bpf@vger.kernel.org, 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, stable@kernel.org X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261026-work-security-namespace_free-v1-4-ffa3ebbf71bd@kernel.org> X-Infomaniak-Routing: alpha