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=1795910390; b=yqDrfrGq4tLLN550xedB3LPXoHxuBZYJNKurTRcRYtipwoIpD8DoISbVd/xGXJpzh0cv hz8dryOa1FAwWY7sAKIs+K6Iu7VElyiwwuoOL28yULbQt3eROzbp2LVueDEUo5o8e1kQR NDYg5d8+XK+5L6umuSgZNd32EiJChrvzuvWoIQMWukf5e+3mWuf51uSX0mEi0ltvoPM0I pg2LGfUUp5mOHmBpax3AD+UFNFkXj4XHwtv1tkgxuvjJWZWibVJIePr8Geb+FcA0ctSYU pPxxrm1wMwqd5j4tqi96NcTU9JougotIfEPNWLLUFHgG5wRyG+hsvrEfRyFBVjLI/IA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795910390; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=cgy8beB6sSd/m8AunHL+Exu9SqwXUH4jGUnQFpHNC2g=; b=fKNr033Yy/lWRTXe24vucrkGiar/ZDUKnH/A9LQ4QeYyGOy9se8XRnb9KDGx/DuxiJ2V GkHiCxqj1F4LDuZqcT27EwuFZMxTQlFhOnUavWoWvGCFlDANO/fVR2d9OQBCE7MaG6Umv Psz8eq6jiSWKXC8hr7ltCuc/tIwyT/UU+ynuY6mxRURp0bJj8w3dVOidmIHN9LoF+Lgg7 eW0+s3tBD6/4WoBnWDjvJRpRl4Z6rs9c9SPH1ZKeXOj3ji3QFp5ViUzTCAcBd+xmUJe1c y8Dc+hQun0fZzxOgWZxKsMBqiZYCpGyGt/ylwdIyS2Cin4Wam8rDXRPn9Ig38CIhe7g== 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=PXN3oaYK; 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 2319F606A6AE; Sat, 28 Nov 2026 23:59:49 +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=PXN3oaYK Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 029711F00933; Sat, 28 Nov 2026 23:59:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795910389; bh=cgy8beB6sSd/m8AunHL+Exu9SqwXUH4jGUnQFpHNC2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PXN3oaYKI07VcNlkMO6lKW+1OGPtw0N4zd93burg39b5pnDgsAYAkYVTGyNOzrjfs FzlYDSp4eZfXoctUrI8/KihdVDTC1S98VbxPjUMe++S3XX0TpECzjg8lPOHfTQOihH jNr6p2mzV+E2TATCzquddLPsfqTKONjU6duhZaffxMyVBxyub0cH3hg/rTTUJAvbpS VXBDPOTnMJygcCh4f9XxN655oTmjHsWMCDzOpneizzC2rTrZGp3mm1gRhqNjdzWHpA AHWwFdxm7Ine6lrhKaRK9gR7h+SitifXTl8/lRtGJ5CaJg5laoejXqY+ReYjInKf1c bWyrQhv3THx/A== 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 22/29] ipc/mqueue: Implement ->set_userland() fs_context operation Date: Sun, 29 Nov 2026 01:58:01 +0200 Message-ID: <20261128235808.2369970-23-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: linux-api@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 mqueue_init_fs_context() captures current->nsproxy->ipc_ns and resets fc->user_ns to ctx->ipc_ns->user_ns, overriding the user namespace delegated by FSCONFIG_SET_USERLAND and leaving the context bound to the caller's IPC namespace. Wire up mqueue_set_userland() to switch ctx->ipc_ns to the target userland's IPC namespace, update fc->user_ns to match, and mark mqueue with FS_USERLAND_MOUNT. Co-developed-by: David Howells Signed-off-by: David Howells Signed-off-by: Jarkko Sakkinen --- ipc/mqueue.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ipc/mqueue.c b/ipc/mqueue.c index 322c3dd98c44..f3079f7d888b 100644 --- a/ipc/mqueue.c +++ b/ipc/mqueue.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -400,6 +401,20 @@ static struct inode *mqueue_get_inode(struct super_block *sb, return ERR_PTR(ret); } +static int mqueue_set_userland(struct fs_context *fc, struct userland *userland) +{ + struct mqueue_fs_context *ctx = fc->fs_private; + struct ipc_namespace *ipc_ns; + + scoped_guard(spinlock, &userland->lock) + ipc_ns = get_ipc_ns(userland->ns->ipc_ns); + put_ipc_ns(ctx->ipc_ns); + ctx->ipc_ns = ipc_ns; + put_user_ns(fc->user_ns); + fc->user_ns = get_user_ns(ipc_ns->user_ns); + return 0; +} + static int mqueue_fill_super(struct super_block *sb, struct fs_context *fc) { struct inode *inode; @@ -1613,6 +1628,7 @@ static const struct super_operations mqueue_super_ops = { static const struct fs_context_operations mqueue_fs_context_ops = { .free = mqueue_fs_context_free, + .set_userland = mqueue_set_userland, .get_tree = mqueue_get_tree, }; @@ -1620,7 +1636,7 @@ static struct file_system_type mqueue_fs_type = { .name = "mqueue", .init_fs_context = mqueue_init_fs_context, .kill_sb = kill_anon_super, - .fs_flags = FS_USERNS_MOUNT, + .fs_flags = FS_USERNS_MOUNT | FS_USERLAND_MOUNT, }; int mq_init_ns(struct ipc_namespace *ns) -- 2.47.3