From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CBF6C606A69E for ; Sun, 29 Nov 2026 00:00:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Qhaby52L Received: by kanga.kvack.org (Postfix) id D50D06B05D5; Sat, 28 Nov 2026 19:00:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CAB686B05D6; Sat, 28 Nov 2026 19:00:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B25336B05D7; Sat, 28 Nov 2026 19:00:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6A5BD6B05D5 for ; Sat, 28 Nov 2026 19:00:01 -0500 (EST) Received: from smtpin26.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DD96F1A0748 for ; Sun, 29 Nov 2026 00:00:00 +0000 (UTC) X-FDA: 85486198560.26.9B6B9F6 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf22.hostedemail.com (Postfix) with ESMTP id 37550C0005 for ; Sat, 28 Nov 2026 23:59:59 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=Qhaby52L; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of jarkko@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=jarkko@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1795910399; b=eumajZAasljHejhHGj9nFWQrZN0YW4ROr9KaEFIoUIMFJugWmzX5f+T/6hTbGa70dZtuWx z0y1OU4rdDCXfF/luscOdR2jGgz8R/P9t83W8n+jwiw7zRFlPeeCH/9KHBy+/nyl+Q37m3 Y4iDayN4umoOQqK9ke96CnLEE2YvzlM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1795910399; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eUxxDZvlD93tWfPMt7l7bmtaAGsvGUglZR1plC31G7k=; b=MFvQTNgyEEIKIIRKq+4fkLbuOPCyydKsCCh2ayeJ4xOocX3ETCgBwJyJujFHsOykTxuQ+U 3A560SiJoHJ40zMDh+tZsGu59XRw3OMTqrdE1iSK5KZnQ9G1c9cjkAa5UkQkpgs4EGl+CY ODVa9NX3Q38lIfNdSBMoQ8hR8gRtnk0= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=Qhaby52L; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of jarkko@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=jarkko@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with UTF8SMTP id 88BDA40290; Sat, 28 Nov 2026 23:59:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id A4C0B1F0092A; Sat, 28 Nov 2026 23:59:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795910398; bh=eUxxDZvlD93tWfPMt7l7bmtaAGsvGUglZR1plC31G7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Qhaby52LZidC42AqDDED9YCNalZt6fZFbfe97MhNePSFQ5TbzX1BJlfv4DRJPa6/A QQC0g5Xc8Y06r0lOiKS4ICrBHCsznAhEPPbdlJhEXUOdqxmcL5bA/4/z6t7yHs6tVe 5iqpcavVZumnHdqYpKBPHYlz+87s7WuMzkQju9jm03d7PFgvgqJ8IqQ8oZpPMpjJol ipToNBUoQwtfBybcfrr/EBJiok1OEmGIH4nXYjPBlJ803kx/0jjDREyxLXQrhqsGve ZNijydb1DQBPzTrJGxCTIw+D+/CF9XD6za9fKRjitZuZOBcPfzpNu7QtKmcxjc6JK2 +sPpLqRmfzTzA== From: Jarkko Sakkinen To: fsdevel@vger.kernel.org Cc: Jarkko Sakkinen , bpf@vger.kernel.org, containers@lists.linux.dev, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, Aleksa Sarai , Alexander Mikhalitsyn , Alexander Viro , Andy Lutomirski , Arnd Bergmann , Christian Brauner , David Howells , Eric Biggers , Georgia Garcia , Giuseppe Scrivano , Hugh Dickins , James Morris , Jan Kara , Jeff Layton , John Johansen , Jonathan Corbet , Josef Bacik , Kees Cook , KP Singh , Lennart Poettering , Matt Bobrowski , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Neal Gompa , Oleg Nesterov , Paul Moore , Pavel Tikhomirov , Serge Hallyn , Shuah Khan , Stephen Smalley , Zygmunt Krynicki Subject: [RFC PATCH v8 24/29] landlock: Enforce namespace use restrictions on userland Date: Sun, 29 Nov 2026 01:58:03 +0200 Message-ID: <20261128235808.2369970-25-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261128235808.2369970-1-jarkko@kernel.org> References: <20261128235808.2369970-1-jarkko@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: 3jetcs5giy31ouc5pgf9t3nozfhzj946 X-Rspamd-Queue-Id: 37550C0005 X-Rspam-User: X-Rspamd-Server: rspam03 X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1795910399-104410 X-HE-Meta: U2FsdGVkX1/QOHYzSv4mMcPR40fXXYBTslhVR0AiJnfoGP8j4ytPFMOSv80PeUfOF7NkB83MRspTouCd2dDX8iuE73Cp9ExQGi8XSt9iwejvcvjh5xMgpaTcv0nLvvi+KCy6g8wQr1w0UJGuJvZfbIHDLCGyncp7NStbAAt1OBvDx+l0gl+KsBzPiCH5wPdeU2wP2sMx1XCBjNSnSbesCf79a6KFgJ1q9LVKRUSs6VSVW7m92YBALlt7j2qSKUQJ+y/PsLpFs6J9IkuAguN/qedOVgk/7QmxRISXoNTMiQanmRMK3DAVyPhMq4pYvHpWcy40ejTwIvVQ4BlVrQk4RBkAq9BEOGa2GNcqbM5YzTCaNDyILFX4R3rrdnSN2afWb9O7kwzKuriwkbeGi/Lm4kKYmPeeIO1G/TC3tq8RYnOySBWp96Rd9GZexYUYd/GPhxbW2pkTHuvsn06muCnZGueGu0/eLD3dbqdOrIRRmH+I28N1d9Lc9fQSbhhcAPClU+G/Gt3C+aadgh3Vxhbkfgr9yEixtddDROQzxCdvqc8nlY9BBwqCKwFw5WPyqktQQ4dD5HM2S0uBJhnU7k3ZYOXiNNA1KVgru3nRfUsfGF1xxpggLJ8vULC+8YShKQiPzC59eLoZN6pugL+zPYcxmrWVQZkw/HsYy+YBBldHG2Jl0oq/mkJxAxueCEJ48GX58NdAmp4s/VTgead/nRluYRhPcxjOD4reR6LyOdVsNczVbGQT2/Q5ZfBc/dWiaAJKT43wkPmNAbPf1g+dx7Z+eMnIEBvJehAOTcBOs0PcYu/9WL92HHcpn4YAKGd6ELL6kP2Lc4cryspPyu9IDqUw/LfIZHIp+4gDuM16rLdYYCLr7gx3Xu/Ezf3R2ekuaG8hwMbfhTNiNVXfNGvJQ3ASSCFZ7mGyMEGbhv2KUa1Iw4DVGoKvCZB7Gj+piKk4F8v9YjP4YkpBG5//beu8SoH Vs+BFvEa jnp/pbhEnAStl1As0U4FoUMPSPUaknlrhNxxvS0P8dB7QDFzloc2cj/uYnwRJkM3acs3qpbIppz5ZMWeONT41lcY/LPJhi32eUNZb77iu33vcTtrJB5RXlreZk0N7yF1H9DQMx3WKc2euTNgpIZJqoJ0/x6bFbQsgpr4FcoleApWjWXPqAG6l/b6lpsCdMHJylGLOwWsN7Lw3nRrLYJMFtlQ83odaDt6t1zYgPNF8gCV7adJ+yujHi+hWFIY5njOu36f5MMY5LtNjumCf6PBFes1OI8SscXaXPGMsn9wZsTzzPEtJWHdqhYv5YDsNVk/ZO2ZIuv5tliliaZqL3Rtchpc68gfYzqrZWd+NhQpCVKLhf42Km6wwYlQRrAsAduQWZFIXkjipnKC6XFBy5pKcCWjOjGUru6N7xD+4OKcpGcrBrUMIWW9+yRRAr1EBy/kolWFkZn68pxtMGR8y2GOvtLhOhvGAEgmysRQBMrCQYmZwG6KgVMzpYver+w== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 When a Landlock-sandboxed task holds a pre-opened userland file descriptor, sharing namespaces via USERLAND_SHARE_NSFD or spawning a child via clone3(CLONE_INTO_USERLAND) switches into existing namespaces without passing through security_namespace_install(). Wire userland_share and userland_clone in Landlock's namespace hooks so LANDLOCK_PERMISSION_NAMESPACE_USE mediates sharing a namespace into a userland and entering any userland namespace that differs from the caller's current namespaces. Signed-off-by: Jarkko Sakkinen --- security/landlock/ns.c | 63 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/security/landlock/ns.c b/security/landlock/ns.c index 3d443599b16f..9ef7c9bc8447 100644 --- a/security/landlock/ns.c +++ b/security/landlock/ns.c @@ -13,6 +13,17 @@ #include #include #include +#ifdef CONFIG_USERLAND +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif #include "cred.h" #include "domain.h" @@ -93,10 +104,10 @@ static const struct access_masks ns_permission = { * @request_type: Namespace operation reported on denial. * * 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 already set even though the namespace is not reachable - * from user space yet. + * open_tree(2), fsmount(2), or userland_open(2)), namespace_install (use via + * setns(2)), and userland_share / userland_clone: denies when the namespace + * type is not in the domain's allowed set. At allocation time @ns->ns_id is + * already set even though the namespace is not reachable from user space yet. * * Return: 0 if allowed, -EPERM if denied. */ @@ -141,9 +152,53 @@ static int hook_namespace_install(const struct nsset *const nsset, return check_ns_type(ns, LANDLOCK_REQUEST_NAMESPACE_ENTER); } +#ifdef CONFIG_USERLAND +static int check_userland_ns(struct ns_common *const ns) +{ + if (is_current_namespace(ns)) + return 0; + return check_ns_type(ns, LANDLOCK_REQUEST_NAMESPACE_ENTER); +} + +static int hook_userland_share(struct userland *const userland, + struct ns_common *const ns) +{ + return check_ns_type(ns, LANDLOCK_REQUEST_NAMESPACE_ENTER); +} + +static int hook_userland_clone(struct userland *const userland) +{ + struct ns_common *const namespaces[] = { + to_ns_common(userland->user_ns), + from_mnt_ns(userland->ns->mnt_ns), + to_ns_common(userland->ns->pid_ns_for_children), + to_ns_common(userland->ns->cgroup_ns), + to_ns_common(userland->ns->ipc_ns), + to_ns_common(userland->ns->uts_ns), + to_ns_common(userland->ns->net_ns), +#ifdef CONFIG_TIME_NS + to_ns_common(userland->ns->time_ns), +#endif + }; + size_t i; + + for (i = 0; i < ARRAY_SIZE(namespaces); i++) { + int err = check_userland_ns(namespaces[i]); + + if (err) + return err; + } + return 0; +} +#endif /* CONFIG_USERLAND */ + static struct security_hook_list landlock_hooks[] __ro_after_init = { LSM_HOOK_INIT(namespace_init, hook_namespace_init), LSM_HOOK_INIT(namespace_install, hook_namespace_install), +#ifdef CONFIG_USERLAND + LSM_HOOK_INIT(userland_share, hook_userland_share), + LSM_HOOK_INIT(userland_clone, hook_userland_clone), +#endif }; __init void landlock_add_ns_hooks(void) -- 2.47.3