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=1796441299; b=TnE49atlFHjclXoJnwN/eIdB9fANFDC34wEb0RheW5TX3ewc8r1NXJkiZ3kUbXZiZ5fm PTTpNH0DjXVQPUdxJVNPAy285gqQH9gPDD1+noDx5uCcST4V+hks1fv2w7quFxl41adhb cpCAm8M0zeaDx5YQo3TQ5D37LdYekgYk2A5oUQMJEKuPEzv17p8z+rIp4u+aiMifE6kF3 99P0X8eulvwOG8vmMI7s4uc1M5JtSXerWtrY08ylBLE9xtKDip7N4fgV7oqhojLySYARQ n2sqyYXWBVXqGTp+hTanVlJQeD0HKBOZBRyQbpJBx3AJrDkMLhBq/+nsdfUUYdglDGg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796441299; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=kWqp3VTb0MLF3FJyKNP713srnxvpacsV/m/BoRWwxMg=; b=cSUVX/5gMgUjLgPngpIiQdANBI8AmOUtwwBM1ylui7JO+IVDlMUhIzR/pWni3GJOEzjL ZqeCqk3tHe/LwFHz4v0m1EtexnBZnF7oP1IjJvl6F8orzz6ZWqWPu4wzAFLJky0wttEnV K/gjFOQDRdJRFU2Lw37aEG82tIjUS5Lp80tqb5N9bSy/Mra05heAr2RY1r0TpweczVrLr A1Zpq03fnmk8IaJ4Agn48UxasVGfEypU088aaW9Wu4JJG0Su3IN7NLKzPcRmCOyeIYqcn teWSKfxtWzZbv4exIwSVk8asmC236Ksu1H+oB6MqtwLqDuvWeN0ssdXSoOPxvPh3vTA== 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=UdYP13bA; 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 CFBE0606A68A; Sat, 5 Dec 2026 03:28:19 +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=UdYP13bA Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id ABCEE1F00936; Sat, 5 Dec 2026 03:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796441299; bh=kWqp3VTb0MLF3FJyKNP713srnxvpacsV/m/BoRWwxMg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UdYP13bA5cJku2JzN9lZ2cMS1vXljONVYUTs+HPj4PMqIqIh/dS8YkKn7m6eGw9Tn 0gHbDTHTMR7HLxRIaa1eR4U6AQiL2HM4YCimKTwSB15rSlFJMaJmqH37tFQ0AcbSQp jl6lPM4LYeUdPqvAe4ntKUoDiau051ZuTcPeCpXDzI9qdvA0JhMc1IeeWlvYf2LJqY e5HPpFEjprnRbypL6jvoX5AklcSHGSGFu4h7OIIPqIIOpnhxcEppAwmihWTdc9KaSA 3ltcRYQ4mlIsXir0QcwIowGIC6O/IbBM2rIF74sNSWYsBzC5AmQWN4OWF+o+0HQfEW Z4JXapY7s/49w== 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 v10 23/28] landlock: Enforce namespace use restrictions on run Date: Sat, 5 Dec 2026 05:26:28 +0200 Message-ID: <20261205032633.1702772-24-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261205032633.1702772-1-jarkko@kernel.org> References: <20261205032633.1702772-1-jarkko@kernel.org> X-Mailing-List: linux-integrity@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 run file descriptor, sharing namespaces via RUNFD_SHARE_NSFD or spawning a child via clone3(CLONE_INTO_RUN) switches into existing namespaces without passing through security_namespace_install(). Wire runfd_share and runfd_clone in Landlock's namespace hooks so LANDLOCK_PERMISSION_NAMESPACE_USE mediates sharing a namespace into a run and entering any run 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..5851195e31f0 100644 --- a/security/landlock/ns.c +++ b/security/landlock/ns.c @@ -13,6 +13,17 @@ #include #include #include +#ifdef CONFIG_RUNFD +#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 run(2)), namespace_install (use via + * setns(2)), and runfd_share / runfd_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_RUNFD +static int check_runfd_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_runfd_share(struct run *const run, + struct ns_common *const ns) +{ + return check_ns_type(ns, LANDLOCK_REQUEST_NAMESPACE_ENTER); +} + +static int hook_runfd_clone(struct run *const run) +{ + struct ns_common *const namespaces[] = { + to_ns_common(run->user_ns), + from_mnt_ns(run->ns->mnt_ns), + to_ns_common(run->ns->pid_ns_for_children), + to_ns_common(run->ns->cgroup_ns), + to_ns_common(run->ns->ipc_ns), + to_ns_common(run->ns->uts_ns), + to_ns_common(run->ns->net_ns), +#ifdef CONFIG_TIME_NS + to_ns_common(run->ns->time_ns), +#endif + }; + size_t i; + + for (i = 0; i < ARRAY_SIZE(namespaces); i++) { + int err = check_runfd_ns(namespaces[i]); + + if (err) + return err; + } + return 0; +} +#endif /* CONFIG_RUNFD */ + 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_RUNFD + LSM_HOOK_INIT(runfd_share, hook_runfd_share), + LSM_HOOK_INIT(runfd_clone, hook_runfd_clone), +#endif }; __init void landlock_add_ns_hooks(void) -- 2.47.3