From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796094732; b=5cCStbyN7FNHgPJLcLli02mfP6mz9b0P+M8HL+e2c6rsQLLdn5jcedN2m2qVeAL6n9AG aPqJ7rf9xviptXrlJYlsa4hp7Y9niW1PCLJA2Ee2BdX/EFeu+5Xvr6tqTeMB519hrj6eR 7nnJv0D615h9/aDf80z3xhoRNaSzEC1qhrdbg+q9MPzfYutNtsPWzKHKSyIja7INwUCXu iiHYn29ehj57gy5nlI/P6TFV3dspwZNqnxO3BH69tFew2Y18htRi7il+mMjCqpvaZqItg gaB/ACyXbHZ1eDYzAZX21mbEE1Mf5HSjAkNjW+byD2b8fKkdX9kY2R72i0+QcUXzJFg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796094732; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=7nuyiRFOSJE+MQavj0aymw72fW3qFHCBabIlY8TkG8A=; b=UweGUiW56J5FOvVtXGrPorvHdqYzEvK/fe0soegekSAI/XKbrk/lZ/gVgGknm8JADFm+ 2P7vYbeghByGywbYUPl2V2MZF0l/uaUtYnVeLjNhI8+3Dnf8Fn6VP8LawSMkKjRL2HIGE wXxtOREw2aez8wj+3Subvakh7Jz18Gq/+8tJIsBwUP7Gt06GI2HSEzvld8tnFBbCteM4f +87LjOgSg9hH+c5Usko+Mz0is3lxLsp5I5Z8j/aipq9OOdKhcZuQPs6CoJAThRS8Ve3LM 8B/ySxtFjx9eDlNs1CYv2FWSq62fAScXVRiW13j9bthW0t8HMebIq+lGkBnZS2dZtXw== 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=PYtQZ7Hg; 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 09695606A333; Tue, 1 Dec 2026 03:12:11 +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=PYtQZ7Hg Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 83D101F00A1E; Tue, 1 Dec 2026 03:12:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796094731; bh=7nuyiRFOSJE+MQavj0aymw72fW3qFHCBabIlY8TkG8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PYtQZ7Hg2f1yyr+XDKh1/BBk296E9vx6Cmui64zEgBiiPbe25CCvPon984DNyU8us ur8vfdtbjBmA5+TpRXQUSyx7tlTR1l3YGYG6uWYxjgSs1o/R5ohNSydraeWcsmnHnr GL3D+rFIdLqP+BSjuiSNbJLJxAAIPralDbVkNBl8UmoOTo2ZFD9zwkPIcT/NST3UH9 BRKSjKVpkscj0yI5W02P2aOi1OvB4blg/ZPe/1kcl5UTgp6efZpCCZuMOr9vF8hNg7 GaLOZHvfLu76lOGCh8pBzJRdeyjR2T4mfgBR2MOOcRnSrcddAiC9WE472iHaRgwQA1 qwn6deq5WhDKQ== 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-integrity@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 , Alexei Starovoitov , Andrew Morton , Andrii Nakryiko , Andy Lutomirski , Arnd Bergmann , Baolin Wang , Ben Segall , Christian Brauner , Daniel Borkmann , David Hildenbrand , David Howells , David Woodhouse , Davidlohr Bueso , Dietmar Eggemann , Eduard Zingerman , Emil Tsalapatis , Eric Biggers , Georgia Garcia , Giuseppe Scrivano , =?UTF-8?q?G=C3=BCnther=20Noack?= , Hugh Dickins , Ihor Solodrai , Ingo Molnar , James Morris , Jan Kara , Jason Gunthorpe , Jeff Layton , Jiri Olsa , John Johansen , Jonathan Corbet , Josef Bacik , Juri Lelli , Kees Cook , K Prateek Nayak , KP Singh , Kumar Kartikeya Dwivedi , Lennart Poettering , "Liam R. Howlett" , Manfred Spraul , Martin KaFai Lau , Matt Bobrowski , Mel Gorman , Michal Hocko , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Mike Rapoport , Neal Gompa , Oleg Nesterov , Paul Moore , Pavel Tikhomirov , Peter Zijlstra , Randy Dunlap , "Serge E. Hallyn" , Serge Hallyn , Shuah Khan , Song Liu , Stephen Smalley , Steven Rostedt , Valentin Schneider , Vincent Guittot , Yonghong Song , Zygmunt Krynicki Subject: [RFC PATCH v9 24/29] landlock: Enforce namespace use restrictions on nsexec Date: Tue, 1 Dec 2026 05:09:56 +0200 Message-ID: <20261201031002.593830-25-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201031002.593830-1-jarkko@kernel.org> References: <20261201031002.593830-1-jarkko@kernel.org> X-Mailing-List: linux-kselftest@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 nsexec file descriptor, sharing namespaces via NSEXEC_SHARE_NSFD or spawning a child via clone3(CLONE_INTO_NSEXEC) switches into existing namespaces without passing through security_namespace_install(). Wire nsexec_share and nsexec_clone in Landlock's namespace hooks so LANDLOCK_PERMISSION_NAMESPACE_USE mediates sharing a namespace into a nsexec and entering any nsexec 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..b5f0aa48a1d0 100644 --- a/security/landlock/ns.c +++ b/security/landlock/ns.c @@ -13,6 +13,17 @@ #include #include #include +#ifdef CONFIG_NSEXEC +#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 nsexec_open(2)), namespace_install (use via + * setns(2)), and nsexec_share / nsexec_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_NSEXEC +static int check_nsexec_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_nsexec_share(struct nsexec *const nsexec, + struct ns_common *const ns) +{ + return check_ns_type(ns, LANDLOCK_REQUEST_NAMESPACE_ENTER); +} + +static int hook_nsexec_clone(struct nsexec *const nsexec) +{ + struct ns_common *const namespaces[] = { + to_ns_common(nsexec->user_ns), + from_mnt_ns(nsexec->ns->mnt_ns), + to_ns_common(nsexec->ns->pid_ns_for_children), + to_ns_common(nsexec->ns->cgroup_ns), + to_ns_common(nsexec->ns->ipc_ns), + to_ns_common(nsexec->ns->uts_ns), + to_ns_common(nsexec->ns->net_ns), +#ifdef CONFIG_TIME_NS + to_ns_common(nsexec->ns->time_ns), +#endif + }; + size_t i; + + for (i = 0; i < ARRAY_SIZE(namespaces); i++) { + int err = check_nsexec_ns(namespaces[i]); + + if (err) + return err; + } + return 0; +} +#endif /* CONFIG_NSEXEC */ + 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_NSEXEC + LSM_HOOK_INIT(nsexec_share, hook_nsexec_share), + LSM_HOOK_INIT(nsexec_clone, hook_nsexec_clone), +#endif }; __init void landlock_add_ns_hooks(void) -- 2.47.3