Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795910399; b=DzOxB5BtftooeFeN7NuP7ZF2q3L7hISRn8o0LyLtmuby2Z5uOlvPIcXghEKS6hW/fJOm 0BBty0KD6pPwTsQBIn5QL33SPLFdYTXpVR//ubBhjALKQK2hZ5gdDPT+7becKXZCBsdba 7DdTa8ZhfmaskAqYZNA6w1ZAPHZlegLnjttN8YjWTSRDIgc/cyqKDSnnvRGPwiJ4YbRoP Va4sgPzRCv3UijvMMlPYfwEVukohRibhwUFV0ezNez3W9hPH0SLf+LqqppPIUXnsrOXzC 01/i3kWSKPeIf+OACEeGNBCVsVB+geELjQu0BmBjWCCLd/Fa71qjEc+v810z2OCU6og== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795910399; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=eUxxDZvlD93tWfPMt7l7bmtaAGsvGUglZR1plC31G7k=; b=to0jPDo+J9oAkBTnw/qHlcKa6Z6oys4OhULhVDX4sVT1nG25ZSjj+jqqx8DpaMqiGBBR IewJc22prA2EI8vfICsvT4GsB0bnJvENJdAQ9PDWQsuZRiLcFoHR3rFkrJ5TaWeL7+fqC COAosSENKHBZ/o/SuW8NcLSc4e+u4SiS8/ueT7Y5MMlWUOChRA8jydK1hbzPBqWGu3QQo 1JBX9lhFv9lB/SKlf7QXKUf6IrjG4lQ8rCW1PF3tSqJPWsEGvhLXrG5C7587ExQNZWVP/ xPF373auBdnQ3vlawZsd8mJLGx/HHPUSUmg/zJuCRpEv/RmzFJpgz18UMH+KJjpVO3A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Qhaby52L; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with UTF8SMTPS id C49DE606A326; Sat, 28 Nov 2026 23:59:58 +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 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-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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