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=1795376242; b=Qdvr/EgPPIHlltZ4UMDqiqPNkn90g/S+Kf1hVGUuJs9URV0VTbLM6Zhozm9mHrrbIlXB OR0igX7cMxQic1w5EfZ0Z6DEySYtJ6GiItdrz7CPzgWl+E/y52XRLRDK4vGHUKukJWeF7 4DMkDBwZx3f/4gCssOy6jy5CFkGBt1B+RoKoGTC1gKL1UMvlj1D7QrM/qdQuqI9vBKS/B iLsEt/favmB6urf2AtlHfbUj6oAeZFtwqfAAFieDY+fX8RY4g3idBf3XtT4Q5qypEMCNg NOI4coU4dtGcGi4KSDWOGvyQN9bKhRG11Gn1c1F/jN9IYG3cuZQHxFXZZv9zjLF6lPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795376242; 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=zrV2bFvG9jt4qZM5j71SgPeubQ1druz6s8IGjvIjMmosq1cGbceDmLHnmZlsoTQVzQrC C4sg5VIEGhAFv/G4MMZA3Eww4ro15NGedUAZLncZjds5dYEJ6U3YKnCcRkEOxXai8ouGb zU69XDkzeFCOoUwU6OA++Honsjqg5ivAwz1tH9hrc/+k/cFNCse4/v1GprfMU5mHp5HLa dlK7RKUl3dmELFv8pOzdzmLf4bcLJExdbfuu9muvJhotGF9vd5740ECAYMjFfrkpUqSMq eSIVDs7mYVA4xmBb7zKYu7a3SAuPMESCR9997g9a0h3bQj11QD9eYFPsPIEZ/8E2XOA== 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=MFbZVX98; 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 C0E5F606A32C; Sun, 22 Nov 2026 19:37:22 +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=MFbZVX98 Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 5680E1F000F0; Sun, 22 Nov 2026 19:37:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795376242; bh=cgy8beB6sSd/m8AunHL+Exu9SqwXUH4jGUnQFpHNC2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MFbZVX98oz4AbJTw3EE+xuDLG3zdzugZzGHmoYc6hW7eDec0Blnfzxt5edluonBsu e0Ei3/23NPNyGX5cyvRmcFvoeLu1mEnHe0QrQdxIt9XFnxpQeXlfHbYCLtlnjnYWBz Nbcb3MXIwfKxt7e7V4rLH7H0AIyobdyn+16rXrNSmV7u5hbKxwQBPTXwAOWKS4xmiF H7qCkd/Gt3lIwdBEvC2huYCEAP63fMN+dpNDjqiAJDdVcF4aAkl4mObzlIXk8T0o8H ayCiozSV6G0LHbRgmoiRS5toCHJx8Wl+Cu6RyA4Z2dEfujWJDRWtHSGWP8nbnF4Pmx r2J26+nsXFzqg== From: Jarkko Sakkinen To: linux-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-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 , Giuseppe Scrivano , Hugh Dickins , Jan Kara , Jeff Layton , Jonathan Corbet , Josef Bacik , Kees Cook , KP Singh , Lennart Poettering , Neal Gompa , Oleg Nesterov , Paul Moore , Pavel Tikhomirov , Serge Hallyn , Shuah Khan , Zygmunt Krynicki Subject: [RFC PATCH v7 20/26] ipc/mqueue: Implement ->set_userland() fs_context operation Date: Sun, 22 Nov 2026 21:35:33 +0200 Message-ID: <20261122193539.3334213-21-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261122193539.3334213-1-jarkko@kernel.org> References: <20261122193539.3334213-1-jarkko@kernel.org> X-Mailing-List: linux-arch@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