From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=45.157.188.11 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796154600; b=kmqR8zefLrB3ELAGyakn8r7PaBzluifSdRV9g6MJe71HAGZA79IpReSa8m/vHMNtiu82 QRN4zWrUhiHZDWrWPktshDm7IiMj/HcRdyuInpps341hwAkthNI2MeOoJucqMY6+yYZ1H ex4hfkkdOY/YSomC7/MXI7jle2LQkmOPhYwpHnlBNygObeKKCZLkJ6snjW4eyOWdQyNW+ M/PpOhx8r3QSKleep94tDaUEcpkhS2QV8ms5IiYTaCOhpkCkClPAh1xiIAIk0pU9c74+S WBRfehl8S2AA9R05YEd0UlHcKxyaInO85PE7L2Q75AA+vIhGJZQpmNdn88dsgbxg8WQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796154600; h=DMARC-Filter:Received:DKIM-Signature:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:Content-Transfer-Encoding:In-Reply-To: X-Infomaniak-Routing; bh=ONnGrQePVqFtqNEnqeO7GAdlnNP8gwF+gHAh2KEpI4Q=; b=uHpDzCZgN4OYGSYydgUgZIrggoXxYO6978/cAiq3kUKwYUmTDVpOlQikH0yYgUH1XJo0 9COYkHO5FgFKn/SPUx/b0+/76h4YmAu2sIvD/ljexkAYgqk90eVJeu1P/xW3hCjaGbbNO fID8f88EHRGifwsNZtvw50DBzsfrT4R27A57M+jpvG7atDTGdb/2vJM7mp66H9OBtxNyJ zy0xV5UH3VKPWzTPPaVqeUuURwqDbEfymp9hDcLCu+2UFXeo4M5A5o1Y2O0qLT3LcQDnL 8WPLm/s/Yuw5E6ZVBC+QZQ25nPoRVbskpnqqhKn+vNF/HW97bhdxxZBR9vG5HBWqY4A== 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=wESxg5r4; arc=none smtp.remote-ip=45.157.188.11 Received: from smtp-bc0b.mail.infomaniak.ch (smtp-bc0b.mail.infomaniak.ch [45.157.188.11]) (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 ESMTPS id 9E53E606A31A for ; Tue, 1 Dec 2026 19:49:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9E53E606A31A 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=wESxg5r4 Received: from smtp-4-0001 (smtp-4-0001.mail.infomaniak.ch [10.7.10.108]) by smtp-4-3000 (Postfix) with ESMTPS id 4jfBLW4ccLzZYV; Tue, 1 Dec 2026 20:49:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digikod.net; s=20191114; t=1796154595; bh=ONnGrQePVqFtqNEnqeO7GAdlnNP8gwF+gHAh2KEpI4Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=wESxg5r4eEnws8OAk6evlKBwn8pLHqGLxY0BsxyPLy0iILngoe36RqPPI0epKJuam uYpLa/v5aOBWhMR/LodWHESOASbs091hG+tVVdKxgOF85Lw4PmXYl0EIwgS205WZC5 s0ymZz4pp1jHp2G1dADjc4CSUeQtz5R2vwrO1Gms= Received: from unknown by smtp-4-0001 (Postfix) with ESMTPA id 4jfBLT1KhSzxJG; Tue, 1 Dec 2026 20:49:53 +0100 (CET) Date: Tue, 1 Dec 2026 20:49:52 +0100 From: =?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?= To: shaos Cc: =?utf-8?Q?G=C3=BCnther?= Noack , Jonathan Corbet , Shuah Khan , Randy Dunlap , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Paul Moore , James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] landlock: restrict opening namespace file descriptors Message-ID: <20261201.iev0mael5Ead@digikod.net> References: <179566442733.1993761.8053687674090289362@163.com> X-Mailing-List: linux-trace-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-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <179566442733.1993761.8053687674090289362@163.com> X-Infomaniak-Routing: alpha Hi, Thanks for the report and the patch. This is not a bypass of LANDLOCK_PERMISSION_NAMESPACE_USE but it highlights a potential misleading doc. The goal of this permission is to reduce the kernel attack surface exposed by creating a namespace or reassociating with one. Creation is covered even when it only returns a handle. For example, creating a user namespace and a network namespace it owns can make privileged networking code reachable. An important point is that opening an existing namespace to identify or compare it is intentionally allowed (when the other access checks pass). I've prepared a documentation patch to clarify the overly broad "every kernel path" wording: https://patch.msgid.link/20261201193814.760891-1-mic@digikod.net Moving a network interface neither creates a namespace nor reassociates the caller with one. The network stack checks CAP_NET_ADMIN on both sides; the FD identify the destination but grants no authority over it, and Landlock can deny the exercise of CAP_NET_ADMIN with LANDLOCK_PERMISSION_CAPABILITY_USE. Moreover, blocking nsfs opens would change an intentional behavior without mediating the move itself. Regards, Mickaƫl On Thu, Nov 26, 2026 at 03:40:27AM +0000, shaos wrote: > Hello, > > Landlock checks NAMESPACE_USE when a task creates a namespace or > installs one with setns(), but does not check acquisition of a file > descriptor for an existing namespace. A sandboxed task can use > SIOCGSKNS on a retained socket to obtain a descriptor for a network > namespace denied by its Landlock rules, then pass that descriptor to > RTM_SETLINK to move an interface into that namespace. > > The reproducer uses a task with CAP_NET_ADMIN in its own user namespace > and a retained socket reference to the target namespace. It demonstrates > a Landlock namespace-use policy bypass; it does not demonstrate > privilege escalation beyond that capability. > > This change checks nsfs file opens from Landlock's file_open hook. It > covers proc namespace links and namespace ioctls that create an nsfs > file. It keeps the current namespace implicitly accessible, consistent > with the documented behavior, and records fd acquisition distinctly in > audit and trace events. > > HEAD commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc > Git tree: fe970b05333fb8e41da21e9e289f652abcc7cba7 > Source version: Linux 7.4.0-rc4 > Compiler: gcc 11.4.0, GNU ld 2.38 > Test runtime: QEMU 6.2.0, x86-64 TCG > > The PoC, complete configuration, console logs, and initramfs helpers > are in this unlisted Gist: > > https://gist.github.com/shaos26/b2c0b1e1951692b79d2bc2f9421abfbc > > Console output: > https://gist.githubusercontent.com/shaos26/b2c0b1e1951692b79d2bc2f9421abfbc/raw/d2278bbd001f2c62b611fc0a5325cc4c8f7451b0/console-output.txt > Kernel config: > https://gist.githubusercontent.com/shaos26/b2c0b1e1951692b79d2bc2f9421abfbc/raw/d2278bbd001f2c62b611fc0a5325cc4c8f7451b0/kernel-config.txt > PoC source: > https://gist.githubusercontent.com/shaos26/b2c0b1e1951692b79d2bc2f9421abfbc/raw/d2278bbd001f2c62b611fc0a5325cc4c8f7451b0/poc.c > > The reproduction script builds the specified kernel, builds the PoC and > initramfs, and runs the baseline, deny, allow, and invalid-fd cases: > > git clone https://gist.github.com/b2c0b1e1951692b79d2bc2f9421abfbc.git repro > git -C repro checkout d2278bbd001f2c62b611fc0a5325cc4c8f7451b0 > chmod +x repro/*.sh > ./repro/reproduce.sh > > Two vulnerable boots allowed SIOCGSKNS and RTM_SETLINK despite the deny > rule: the move request was acknowledged and the interface appeared in > the denied namespace. With this patch, opening the current namespace > still succeeds, setns() and unshare() remain denied, SIOCGSKNS returns > EPERM, and the interface remains in its original namespace. Baseline, > explicit allow-rule, and invalid-fd controls pass. > > Fixes: 15dd86021b57 ("landlock: Enforce namespace use restrictions") > Cc: stable@vger.kernel.org > Signed-off-by: shaos > > --- > Documentation/userspace-api/landlock.rst | 3 +++ > include/trace/events/landlock.h | 12 ++++++---- > security/landlock/audit.c | 4 ++++ > security/landlock/fs.c | 11 +++++++++ > security/landlock/log.c | 2 ++ > security/landlock/log.h | 1 + > security/landlock/ns.c | 30 ++++++++++++++++-------- > security/landlock/ns.h | 4 ++++ > security/landlock/trace.c | 1 + > 9 files changed, 54 insertions(+), 14 deletions(-) > > diff --git a/Documentation/userspace-api/landlock.rst b/Documentation/userspace-api/landlock.rst > index 7cc5fde482623..b1e78eef17bac 100644 > --- a/Documentation/userspace-api/landlock.rst > +++ b/Documentation/userspace-api/landlock.rst > @@ -598,6 +598,9 @@ that references it. The covered syscall paths are: > 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. > +* Opening an nsfs file descriptor, including through :manpage:`open(2)` on > + ``/proc//ns/`` or :manpage:`ioctl(2)` operations such as ``SIOCGSKNS`` > + and ``NS_GET_USERNS``. > > Anonymous mount namespaces (created by ``open_tree(OPEN_TREE_CLONE)`` and the > default :manpage:`fsmount(2)`) are intentionally covered by the bit even though > diff --git a/include/trace/events/landlock.h b/include/trace/events/landlock.h > index 09e90e4a9cd7b..ae385ffb3a360 100644 > --- a/include/trace/events/landlock.h > +++ b/include/trace/events/landlock.h > @@ -40,6 +40,7 @@ TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_FS_ACCESS); > TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_NET_ACCESS); > TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_NAMESPACE_CREATE); > TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_NAMESPACE_ENTER); > +TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_NAMESPACE_ACQUIRE); > TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_CAPABILITY); > > #ifdef CREATE_TRACE_POINTS > @@ -993,8 +994,8 @@ TRACE_EVENT(landlock_deny_access_net, > * @namespace_id: Namespace ID, not directly visible from user space when > * creation was denied. > * > - * Emitted when a Landlock domain denies namespace creation or entry. The > - * namespace_op field distinguishes these operations. > + * Emitted when a Landlock domain denies namespace creation, entry, or fd > + * acquisition. The namespace_op field distinguishes these operations. > */ > TRACE_EVENT(landlock_deny_permission_namespace, > > @@ -1028,14 +1029,17 @@ TRACE_EVENT(landlock_deny_permission_namespace, > TP_printk("domain=%llx same_exec=%d logged=%d blockers=%s namespace_op=%s namespace_type=0x%x namespace_id=%llu", > __entry->domain_id, __entry->same_exec, __entry->logged, > (__entry->blockers_type == LANDLOCK_REQUEST_NAMESPACE_CREATE || > - __entry->blockers_type == LANDLOCK_REQUEST_NAMESPACE_ENTER) ? > + __entry->blockers_type == LANDLOCK_REQUEST_NAMESPACE_ENTER || > + __entry->blockers_type == LANDLOCK_REQUEST_NAMESPACE_ACQUIRE) ? > __print_flags(__entry->blockers_access, "|", > _LANDLOCK_PERMISSION_BLOCKER_NAMES) : > "unknown", > __entry->blockers_type == LANDLOCK_REQUEST_NAMESPACE_CREATE ? > "create" : > __entry->blockers_type == LANDLOCK_REQUEST_NAMESPACE_ENTER ? > - "enter" : "unknown", > + "enter" : > + __entry->blockers_type == LANDLOCK_REQUEST_NAMESPACE_ACQUIRE ? > + "acquire" : "unknown", > __entry->namespace_type, __entry->namespace_id) > ); > > diff --git a/security/landlock/audit.c b/security/landlock/audit.c > index 6d9e54f5deedf..ddd653b686d72 100644 > --- a/security/landlock/audit.c > +++ b/security/landlock/audit.c > @@ -82,6 +82,7 @@ get_blocker(const enum landlock_request_type type, > > case LANDLOCK_REQUEST_NAMESPACE_CREATE: > case LANDLOCK_REQUEST_NAMESPACE_ENTER: > + case LANDLOCK_REQUEST_NAMESPACE_ACQUIRE: > case LANDLOCK_REQUEST_CAPABILITY: > if (WARN_ON_ONCE(access_bit >= ARRAY_SIZE(permission_strings))) > return "unknown"; > @@ -118,6 +119,7 @@ blocker_prefix(const enum landlock_request_type type) > > case LANDLOCK_REQUEST_NAMESPACE_CREATE: > case LANDLOCK_REQUEST_NAMESPACE_ENTER: > + case LANDLOCK_REQUEST_NAMESPACE_ACQUIRE: > return _LANDLOCK_PERMISSION_NAMESPACE_NAME "."; > > case LANDLOCK_REQUEST_CAPABILITY: > @@ -218,6 +220,8 @@ void landlock_audit_denial(const struct landlock_request *const request, > audit_log_format(ab, " namespace_op=create"); > else if (request->type == LANDLOCK_REQUEST_NAMESPACE_ENTER) > audit_log_format(ab, " namespace_op=enter"); > + else if (request->type == LANDLOCK_REQUEST_NAMESPACE_ACQUIRE) > + audit_log_format(ab, " namespace_op=acquire"); > audit_log_lsm_data(ab, &request->audit); > audit_log_end(ab); > > diff --git a/security/landlock/fs.c b/security/landlock/fs.c > index 2ab67bcad1983..97b30fbffa48e 100644 > --- a/security/landlock/fs.c > +++ b/security/landlock/fs.c > @@ -31,6 +31,8 @@ > #include > #include > #include > +#include > +#include > #include > #include > #include > @@ -49,6 +51,7 @@ > #include "fs.h" > #include "limits.h" > #include "log.h" > +#include "ns.h" > #include "object.h" > #include "ruleset.h" > #include "setup.h" > @@ -1861,6 +1864,14 @@ static int hook_file_open(struct file *const file) > const struct landlock_cred_security *const subject = > landlock_get_applicable_subject(file->f_cred, any_fs, NULL); > struct landlock_request request = {}; > + int err; > + > + if (proc_ns_file(file)) { > + err = landlock_check_namespace_fd(file->f_cred, > + get_proc_ns(file_inode(file))); > + if (err) > + return err; > + } > > if (!subject) > return 0; > diff --git a/security/landlock/log.c b/security/landlock/log.c > index c132b343f0ee0..fbcfa962cca32 100644 > --- a/security/landlock/log.c > +++ b/security/landlock/log.c > @@ -390,6 +390,7 @@ static bool is_valid_request(const struct landlock_request *const request) > switch (request->type) { > case LANDLOCK_REQUEST_NAMESPACE_CREATE: > case LANDLOCK_REQUEST_NAMESPACE_ENTER: > + case LANDLOCK_REQUEST_NAMESPACE_ACQUIRE: > if (WARN_ON_ONCE(request->permission != > LANDLOCK_PERMISSION_NAMESPACE_USE) || > WARN_ON_ONCE(request->audit.type != LSM_AUDIT_DATA_NS)) > @@ -488,6 +489,7 @@ is_denial_quieted(const struct landlock_request *const request, > LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET); > case LANDLOCK_REQUEST_NAMESPACE_CREATE: > case LANDLOCK_REQUEST_NAMESPACE_ENTER: > + case LANDLOCK_REQUEST_NAMESPACE_ACQUIRE: > return !!(youngest_denied->quiet_permission.ns_types & > landlock_ns_type_to_bit(request->audit.u.ns.ns_type)); > case LANDLOCK_REQUEST_CAPABILITY: > diff --git a/security/landlock/log.h b/security/landlock/log.h > index 5ca87870c7b78..dee55270a7b89 100644 > --- a/security/landlock/log.h > +++ b/security/landlock/log.h > @@ -29,6 +29,7 @@ enum landlock_request_type { > LANDLOCK_REQUEST_SCOPE_SIGNAL, > LANDLOCK_REQUEST_NAMESPACE_CREATE, > LANDLOCK_REQUEST_NAMESPACE_ENTER, > + LANDLOCK_REQUEST_NAMESPACE_ACQUIRE, > LANDLOCK_REQUEST_CAPABILITY, > }; > > diff --git a/security/landlock/ns.c b/security/landlock/ns.c > index 3d443599b16f4..1ef41ac4f977b 100644 > --- a/security/landlock/ns.c > +++ b/security/landlock/ns.c > @@ -89,25 +89,28 @@ static const struct access_masks ns_permission = { > /** > * check_ns_type - Check namespace use permission > * > - * @ns: The namespace being allocated or installed. > + * @ns: The namespace being created, installed, or opened. > + * @cred: Credentials whose Landlock domain is checked. > * @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. > + * Shared check for namespace creation, installation, and nsfs file opening. > + * Namespaces in which the current task is already a member remain accessible. > + * 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. > */ > static int check_ns_type(struct ns_common *const ns, > + const struct cred *const cred, > const enum landlock_request_type request_type) > { > const struct landlock_cred_security *subject; > size_t denied_layer; > > - subject = landlock_get_applicable_subject(current_cred(), ns_permission, > - NULL); > + if (is_current_namespace(ns)) > + return 0; > + > + subject = landlock_get_applicable_subject(cred, ns_permission, NULL); > if (!subject) > return 0; > > @@ -132,13 +135,20 @@ static int check_ns_type(struct ns_common *const ns, > > static int hook_namespace_init(struct ns_common *const ns) > { > - return check_ns_type(ns, LANDLOCK_REQUEST_NAMESPACE_CREATE); > + return check_ns_type(ns, current_cred(), > + LANDLOCK_REQUEST_NAMESPACE_CREATE); > } > > static int hook_namespace_install(const struct nsset *const nsset, > struct ns_common *const ns) > { > - return check_ns_type(ns, LANDLOCK_REQUEST_NAMESPACE_ENTER); > + return check_ns_type(ns, current_cred(), > + LANDLOCK_REQUEST_NAMESPACE_ENTER); > +} > + > +int landlock_check_namespace_fd(const struct cred *cred, struct ns_common *ns) > +{ > + return check_ns_type(ns, cred, LANDLOCK_REQUEST_NAMESPACE_ACQUIRE); > } > > static struct security_hook_list landlock_hooks[] __ro_after_init = { > diff --git a/security/landlock/ns.h b/security/landlock/ns.h > index 46d3bd17479d2..cdf6dc2f7326e 100644 > --- a/security/landlock/ns.h > +++ b/security/landlock/ns.h > @@ -10,8 +10,12 @@ > > #include > > +struct cred; > +struct ns_common; > + > u64 landlock_ns_type_to_bit(u32 ns_type); > u64 landlock_ns_types_to_bits(u64 ns_types); > +int landlock_check_namespace_fd(const struct cred *cred, struct ns_common *ns); > > __init void landlock_add_ns_hooks(void); > > diff --git a/security/landlock/trace.c b/security/landlock/trace.c > index a47fb10dec459..9d71b31e9c27a 100644 > --- a/security/landlock/trace.c > +++ b/security/landlock/trace.c > @@ -83,6 +83,7 @@ void landlock_trace_denial( > switch (request->type) { > case LANDLOCK_REQUEST_NAMESPACE_CREATE: > case LANDLOCK_REQUEST_NAMESPACE_ENTER: > + case LANDLOCK_REQUEST_NAMESPACE_ACQUIRE: > if (trace_landlock_deny_permission_namespace_enabled()) { > const struct landlock_blockers blockers = { > .access = missing, > -- > 2.34.1 > >