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=1796441292; b=1sbNA88tKFqxz9lg9zSaF4rhFWoug/InjKzZik9+YmEAIztoWNj8Hs1/6y3fD8Dk0B6l HBmqZi5pP99ADvhHtLntA4fpnfXvAx68igCv1AotJKs/59BMUCv2baDDKB8+Vs/ZqjLGN dv4f5BybLlKdyC7xHtl2zfTnrFMmka3Z8rfxJzatKiID0HXOdzQbcOcWPlJfaPO6NPcWp EGSodjkaRG5b0XZT5YlMAGXO97+WDpskM6Lr+rpTHisFJ6nnFc/1HRROVL+NG2pMFzgdI 0P0neiLOKHbCVMuGer8npkbEdoZuA8R8w7iyojYEgbf1Paagt+gpCrtGk7R7ewu1Jpg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796441292; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=JLHEUOZKskSL43OPPYeORQ0s4oQmjO5EJV2qDJF/wag=; b=fxnUIsvRtsdhD++CIS8oWaVL3tgYW0GBSuUnDl2VeHmFLnzSNeeb7J8hSPH7ZSnQjdl4 1ys+JGf76x8knAFua9MhKnX4MXaeFKff+FRJut3KsltmPwX3nI3ad5U6mI53fFHsfylbs TfbKK/KYgNjaTnYjrWb+FsgkacUks4v9kA3C+J0+Wj1QkpR3sgO3qUHPPu6W1MehNTmbV ROELQdI3c9Uy1XJDEVAOThtSViGLyoNIUmYu6OWQCLCJq7oqRoGSrqfUVf/LLwaKGe20w BLM5zkdOJhmJX1n3QypENhDkGPo0VpM4UPohmuy9DvOZdKWHMVddZ7+tFTBMzuL6zpQ== 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=BWVHP0f8; 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 13E7160A6F57; Sat, 5 Dec 2026 03:28: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=BWVHP0f8 Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id E371E1F00A17; Sat, 5 Dec 2026 03:28:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796441291; bh=JLHEUOZKskSL43OPPYeORQ0s4oQmjO5EJV2qDJF/wag=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BWVHP0f83DMYWTgrZxc5hm1dJIWXsC++J/QJNsJHZ8WOn70ef9Qpv2iCgfjSHRiHF RRgKrt181Kb2JfFUca+xJd6g8rsiZHoXjH3/EkxaCF2eOefQVEGr7Ow7xe/5G2aMeu 2ACHQSMeT/5CYQi4wiVI21zyXoIZ+HYiYzAooBvbyK3muDGtWnjOnnuheNMHzlxcvx Cu6muLlShwjJP4IpEo8rTxYYvmN+35xT8TCiqq1pkJxcPmlP7grIoo5AuBEdyeP0R8 KRDQMoBYKqvYGITHfGMNcnVR++gttOzKKmJoxHcWz8bdfapw+XagivMzhFo2d74Yux NpuDYIOl3QS6g== 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 21/28] ipc/mqueue: Implement ->set_run() fs_context operation Date: Sat, 5 Dec 2026 05:26:26 +0200 Message-ID: <20261205032633.1702772-22-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-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_RUN and leaving the context bound to the caller's IPC namespace. Wire up mqueue_set_run() to switch ctx->ipc_ns to the target run's IPC namespace, update fc->user_ns to match, and mark mqueue with FS_RUN_MOUNT. Co-developed-by: David Howells Signed-off-by: David Howells Signed-off-by: Jarkko Sakkinen --- ipc/mqueue.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/ipc/mqueue.c b/ipc/mqueue.c index 322c3dd98c44..f31df31c5053 100644 --- a/ipc/mqueue.c +++ b/ipc/mqueue.c @@ -30,6 +30,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_run(struct fs_context *fc, struct run *run) +{ + struct mqueue_fs_context *ctx = fc->fs_private; + struct ipc_namespace *ipc_ns; + + scoped_guard(spinlock, &run->lock) + ipc_ns = get_ipc_ns(run->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; @@ -453,9 +468,16 @@ static int mqueue_init_fs_context(struct fs_context *fc) if (!ctx) return -ENOMEM; - ctx->ipc_ns = get_ipc_ns(current->nsproxy->ipc_ns); - put_user_ns(fc->user_ns); - fc->user_ns = get_user_ns(ctx->ipc_ns->user_ns); + /* + * Reconfiguration keeps the superblock's user namespace and does not + * use ctx->ipc_ns, which put_ipc_ns() could be tearing down via + * sb->s_fs_info. + */ + if (fc->purpose != FS_CONTEXT_FOR_RECONFIGURE) { + ctx->ipc_ns = get_ipc_ns(current->nsproxy->ipc_ns); + put_user_ns(fc->user_ns); + fc->user_ns = get_user_ns(ctx->ipc_ns->user_ns); + } fc->fs_private = ctx; fc->ops = &mqueue_fs_context_ops; return 0; @@ -1613,6 +1635,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_run = mqueue_set_run, .get_tree = mqueue_get_tree, }; @@ -1620,7 +1643,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_RUN_MOUNT, }; int mq_init_ns(struct ipc_namespace *ns) -- 2.47.3