From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=83.166.143.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796224960; b=AI8aUPbUKy3du4edi0cHqNdo7ssRD9ukHIVPd/8/agClOjJI0D7Q8u+7jDbQu1OHZhSt 1jUbbmFyyWXdJ/mZP1n4tkGc6EAh5NZWs72NLUr/qxCTqVnW5inqRf5aCX15LcaWmb3aj 7vrBbsxDZ7P3o6QyPGxRQ17t32V1O/JsEtW19RGqItdnuMblv9AfRiUhfX+NYaNu/1hkA X5jEaiu/uG+91tJPIpQoVRt7WNcBd/NFFQv/CO185W6nWC7NFEzUJzeV9BgcJAOZfBlSL 3tC5xWUSCpX7bZm9GOc42uwisnW4d6cTwyawKA2eVw/BCjcbZaBr2lVdewB4pLp88Iw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796224960; h=DMARC-Filter:Received:DKIM-Signature:Received:From:To:Cc:Subject: Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding: X-Infomaniak-Routing; bh=g13nJ6IfY452cHvAamgcQ5w19ab1N8zfI0ZMaW5noXE=; b=LWSpGdG8gM/kB8YnXVTEJjmHF5sWgxmy1fundo9CV1GBV7d0c483U98CRJRMXLXzFwMN S/k55fVoDi6lRKYTBw3DzuQD93jczE9/rIlZzsGUUbC4YI/CZfmtV6y1R8uqeyOFS3cmf eNrTQdpF0sFdURcqLdkSM4p9TLduPS+57j/bkjk8kPCV0wmfW6BoYuqLwdKmcodt3SJUX tPBjP1hGV8uCGRr2w+brE7x/3VM/UKDCkSox51JMul+IzyCwNR3GfJOlQh9FMX3JUwLbY ULASJfw6woCF85RCyA9gZtIV2p8g73jz59m7Mmj13rMkglXUVqjX7lumo/YYmyFWUpQ== 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=Y3TwDqnd; arc=none smtp.remote-ip=83.166.143.170 Received: from smtp-8faa.mail.infomaniak.ch (smtp-8faa.mail.infomaniak.ch [83.166.143.170]) (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 C7AB5606A31A for ; Wed, 2 Dec 2026 15:22:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C7AB5606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=digikod.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.a=rsa-sha256 header.s=20191114 header.b=Y3TwDqnd Received: from smtp-3-0001.mail.infomaniak.ch (unknown [IPv6:2001:1600:4:17::246c]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4jfhMV4TXzzgxC; Wed, 2 Dec 2026 16:22:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digikod.net; s=20191114; t=1796224950; bh=g13nJ6IfY452cHvAamgcQ5w19ab1N8zfI0ZMaW5noXE=; h=From:To:Cc:Subject:Date:From; b=Y3TwDqnd5yFSA4fh9LJgtAu7V5Dw/JsLKlV5WEbTfQnMGOx2L32P6BvUJU+eOvXdr D3QGZQWnI4UYPK9UMAcWkLunmHZsQx11wQrfUctyvhncorq8BfTVcHcgxMiS+EnNdC oBpMUzFfwFcJwL861gnb27rIrn5dISKMOxJc3y2Y= Received: from unknown by smtp-3-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4jfhMT1lLszqyr; Wed, 2 Dec 2026 16:22:29 +0100 (CET) From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: =?UTF-8?q?G=C3=BCnther=20Noack?= , Jonathan Corbet Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Christian Brauner , Randy Dunlap , Shawn Shao , Shuah Khan , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH v2] landlock: Clarify namespace and capability permission boundaries Date: Wed, 2 Dec 2026 16:22:26 +0100 Message-ID: <20261202152228.805597-1-mic@digikod.net> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Infomaniak-Routing: alpha A report [1] interpreted opening a reference to an existing namespace as an operation covered by LANDLOCK_PERMISSION_NAMESPACE_USE. The current wording invites that reading, but a namespace reference identifies a target without authorizing reassociation or capability exercise. Distinguish namespace creation and reassociation from opening existing namespaces. Describe capability exercise as an independent check so readers can tell how the two permissions limit reachable kernel code. Cc: Günther Noack Cc: Shawn Shao Link: https://patch.msgid.link/179566442733.1993761.8053687674090289362@163.com [1] Signed-off-by: Mickaël Salaün --- Changes since v1: https://patch.msgid.link/20261201193814.760891-1-mic@digikod.net - Align the ruleset tutorial, compatibility note, and UAPI kernel-doc with namespace creation and reassociation (pointed out by Sashiko). --- Documentation/userspace-api/landlock.rst | 75 +++++++++++------------- include/uapi/linux/landlock.h | 12 ++-- 2 files changed, 39 insertions(+), 48 deletions(-) diff --git a/Documentation/userspace-api/landlock.rst b/Documentation/userspace-api/landlock.rst index 7cc5fde48262..1608292c898b 100644 --- a/Documentation/userspace-api/landlock.rst +++ b/Documentation/userspace-api/landlock.rst @@ -8,7 +8,7 @@ Landlock: unprivileged access control ===================================== :Author: Mickaël Salaün -:Date: November 2026 +:Date: December 2026 The goal of Landlock is to enable restriction of ambient rights (e.g. global filesystem or network access) for a set of processes. Because Landlock @@ -284,11 +284,10 @@ process can call :manpage:`chroot(2)` inside a user namespace): err = landlock_add_rule(ruleset_fd, LANDLOCK_RULE_CAPABILITY, &cap_attr, 0); -For namespace access-control, we can add rules that allow using specific -namespace types (see :manpage:`namespaces(7)` for the list of ``CLONE_NEW*`` -values): creating them via :manpage:`unshare(2)` / :manpage:`clone(2)` / -:manpage:`clone3(2)`, joining them via :manpage:`setns(2)`, or acquiring an fd -reference via :manpage:`open_tree(2)` / :manpage:`fsmount(2)`. For instance, +For namespace access-control, we can add rules that allow creating or +reassociating with namespaces of specific types (see :manpage:`namespaces(7)` +for the list of ``CLONE_NEW*`` values). Creation is covered even when it +returns a file descriptor without making the caller a member. For instance, to allow creating user namespaces (which grants all capabilities inside the new namespace): @@ -525,25 +524,23 @@ rights (``handled_access_*``) or cross-domain scopes (``scoped``), per-category permissions constrain the sandboxed process's own use of these enums; members not allowed by a rule are denied by default. -``LANDLOCK_PERMISSION_NAMESPACE_USE`` gates *acquisition of access* to -namespaces: creation via :manpage:`unshare(2)` / :manpage:`clone(2)` -/ :manpage:`clone3(2)`, entry via :manpage:`setns(2)`, and fd-reference -acquisition via :manpage:`open_tree(2)` / :manpage:`fsmount(2)`. Namespaces -the process is already a member of when the domain is enforced are implicitly -allowed (the process could not continue running otherwise); rules describe -which new namespace types the process may acquire. +``LANDLOCK_PERMISSION_NAMESPACE_USE`` restricts which namespace types a +process may create or reassociate with. It covers creation even when the +caller does not join the new namespace, but does not restrict opening an +existing namespace. Enforcing this permission does not revoke existing +namespace membership. + ``LANDLOCK_PERMISSION_CAPABILITY_USE`` gates the exercise of capabilities after the domain is enforced, regardless of how the capability was obtained (inherited credentials, ``CLONE_NEWUSER`` -grant, ``setuid``/file-cap-bearing :manpage:`execve(2)`, etc.). Configuring -both together restricts what privileges are available *and* the namespaces in -which they take effect, which matters because user namespace creation has no -capability check and grants all capabilities within the new namespace: gating -only one of the two leaves a kernel attack-surface widening path open. When a -domain handles both permissions, an operation is allowed only if each -independently allows it: :manpage:`unshare(2)` with ``CLONE_NEWNET`` then -requires both a rule allowing ``CLONE_NEWNET`` and a rule allowing -``CAP_SYS_ADMIN``. +grant, ``setuid``/file-cap-bearing :manpage:`execve(2)`, etc.). + +Together, the namespace and capability permissions limit reachable kernel code +by restricting namespace creation and reassociation separately from capability +exercise. An operation must be allowed by every handled permission that +applies to it. For example, when both of these permissions are handled, +:manpage:`unshare(2)` with ``CLONE_NEWNET`` requires rules allowing both +``CLONE_NEWNET`` and ``CAP_SYS_ADMIN``. ``LANDLOCK_PERMISSION_CAPABILITY_USE`` complements :manpage:`prctl(2)` ``PR_SET_NO_NEW_PRIVS`` but does not replace it. ``PR_SET_NO_NEW_PRIVS`` @@ -579,25 +576,21 @@ effect, so a rule compiled against future kernel headers loads without error on older kernels. Future kernels gain new members denied by default until a rule explicitly allows them. -The single ``LANDLOCK_PERMISSION_NAMESPACE_USE`` bit gates every kernel path -that grants the calling process access to a namespace of the controlled types, -whether by becoming a member of the namespace or by holding a file descriptor -that references it. The covered syscall paths are: - -* :manpage:`unshare(2)` with ``CLONE_NEW*``: the caller becomes a member of a - newly-created namespace. -* :manpage:`clone(2)` (or :manpage:`clone3(2)`) with ``CLONE_NEW*``: the - child becomes a member of a newly-created namespace. -* :manpage:`setns(2)`: the caller becomes a member of an existing namespace - referenced by file descriptor. +Examples of covered namespace creation and reassociation operations include: + +* :manpage:`unshare(2)` with ``CLONE_NEW*``: creates namespaces for the caller. +* :manpage:`clone(2)` (or :manpage:`clone3(2)`) with ``CLONE_NEW*``: creates + namespaces for the child. +* :manpage:`setns(2)`: requests reassociation with one or more existing + namespaces. * :manpage:`open_tree(2)` with ``OPEN_TREE_NAMESPACE``: the caller obtains a file descriptor referring to a newly-created mount namespace. * :manpage:`open_tree(2)` with ``OPEN_TREE_CLONE``: the caller obtains a file - descriptor referring to a newly-created anonymous mount namespace. + descriptor for a detached mount in a new anonymous mount namespace. * :manpage:`fsmount(2)` with ``FSMOUNT_NAMESPACE``: the caller obtains a file descriptor referring to a newly-created mount namespace. * :manpage:`fsmount(2)` (default): the caller obtains a file descriptor - referring to a newly-created anonymous mount namespace. + for a detached mount in a new anonymous mount namespace. Anonymous mount namespaces (created by ``open_tree(OPEN_TREE_CLONE)`` and the default :manpage:`fsmount(2)`) are intentionally covered by the bit even though @@ -1047,12 +1040,12 @@ permission flag and ``LANDLOCK_RULE_CAPABILITY`` rule type. Namespace (ABI < 12) -------------------- -Starting with the Landlock ABI version 12, it is possible to restrict namespace -use (see :manpage:`namespaces(7)`) across creation (:manpage:`unshare(2)`, -:manpage:`clone(2)`, :manpage:`clone3(2)`), entry (:manpage:`setns(2)`), and -fd-reference acquisition (:manpage:`open_tree(2)`, :manpage:`fsmount(2)`) with -the new ``LANDLOCK_PERMISSION_NAMESPACE_USE`` permission flag and -``LANDLOCK_RULE_NAMESPACE`` rule type. +Starting with the Landlock ABI version 12, the +``LANDLOCK_PERMISSION_NAMESPACE_USE`` permission flag and +``LANDLOCK_RULE_NAMESPACE`` rule type restrict namespace creation and +reassociation (:manpage:`setns(2)`) by namespace type (see +:manpage:`namespaces(7)`). Creation is covered even when it returns a file +descriptor without reassociating the caller. .. _kernel_support: diff --git a/include/uapi/linux/landlock.h b/include/uapi/linux/landlock.h index 8ce0406ba543..bab3f034a793 100644 --- a/include/uapi/linux/landlock.h +++ b/include/uapi/linux/landlock.h @@ -613,13 +613,11 @@ struct landlock_capability_attr { * operation is allowed only if each handled permission independently allows it. * See Documentation/userspace-api/landlock.rst. * - * - %LANDLOCK_PERMISSION_NAMESPACE_USE: Restrict the use of specific namespace - * types: creation (:manpage:`unshare(2)`, :manpage:`clone(2)`, - * :manpage:`clone3(2)`), joining (:manpage:`setns(2)`), and acquiring an fd - * reference (:manpage:`open_tree(2)`, :manpage:`fsmount(2)`). A process in a - * Landlock domain that handles this permission is denied from using namespace - * types that are not explicitly allowed by a %LANDLOCK_RULE_NAMESPACE rule. - * Support added in Landlock ABI version 12. + * - %LANDLOCK_PERMISSION_NAMESPACE_USE: Restrict namespace creation and + * reassociation (:manpage:`setns(2)`) by type. This covers creation that + * returns a file descriptor without reassociating the caller. A domain that + * handles this permission denies these operations for types not allowed by a + * %LANDLOCK_RULE_NAMESPACE rule. Support added in Landlock ABI version 12. * - %LANDLOCK_PERMISSION_CAPABILITY_USE: Restrict the use of specific Linux * capabilities. A process in a Landlock domain that handles this permission * is denied from exercising capabilities that are not explicitly allowed by a base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244 -- 2.56.1