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=1796094723; b=aDoJrZBvsceL8Ts52nywIeWCqtafjE7wIDkRRFofUaCwPyne9iUaiXA7SvB6XV/GFLrh MIs/1IHgGwpnjNehRQJySdxIfapk+xreXvi1o2aPsAZIzCnMJBlvTM5RkXquGo8iQ2opT Q35bm4aD+QNthMlePgoaSVAT5V2kee5drV8kQhHONSbiC4B32BeD4bpGVMEcx5jS3aqR7 WyrzE7VkCxyBfMA83QUtCcTymryxJ6vJ2fVpQErgq1EMd+rjVX7JjUCtXTC9GrzxGq+J/ 6WE9RQMKYRjaDSXjpBF4QiHpbr6lEmCWpG+bT1qChW8DEBoeI9+WGAjrCl2e0tXe1MQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796094723; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=6XRJ1vugxTogoOCEaPxpMco0K73jF/RSrYIybxZ4700=; b=pIC9QlYLNALo7B70sRJExhwC1We1lTqQIO6SWuafBzZgYl21vM75Qi3bz6Cf/SLtWJGY hpX7JKNQo+9/UayUkse6qwL0tivMJjtN7ev4TqW33McQusH9XjPFcLAR63riGnsC2kBLk ghzeyS6yNPeAOeEYLFrSutWg4dhHletrROE/FDVosr21KI49/Z6r+aGRWIIb8tnwFHzf7 0Pq8VloUEnm4S0VR5/qSj5FsWr/gvp26reipd4w4pSu3cYVi6goRF6iAGpDAnQp6zEoj+ P5Mk6naixsPFuYTbT7AC0b2XnOJRMcEBTjLc5Su7jU2Snu7DNw4tp/+BCf/7qzHT7Qw== 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=cNB6h9a5; 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 6886E606A333; Tue, 1 Dec 2026 03:12:02 +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=cNB6h9a5 Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 6F58C1F00899; Tue, 1 Dec 2026 03:12:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796094722; bh=6XRJ1vugxTogoOCEaPxpMco0K73jF/RSrYIybxZ4700=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cNB6h9a5c8Ehym7XOts5cXYJXR6C3KR0AgS1bBt6sMcLV1E1Z5oypKJDNO0apIOM5 pvBVmWHwOEb1DuhKQtjTpL+kbWksYxW3wSbyVtfUClPXZn18xE2RVsubHAxiF2dr+7 3HSGGepjU0tSwtUAD3wi4dGpLp4Ckz6vmSCJvqfKgm5gxn3WcXEkJHQ8PO68/UFsBJ 19lsMe9ggvvvwvtdbLlZ6cbbw0LNaElI2m1MPwI5MqrjcZ6fLYgn0TK2S6OSqkZVNY 9FM8vbCz/3s/LrI42TKgI0I6ZlNfrj41q7T+3sCK181FzSqejlSjtotrqLgFGVfxbj eklUzpEoc5yZg== 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 v9 22/29] ipc/mqueue: Implement ->set_nsexec() fs_context operation Date: Tue, 1 Dec 2026 05:09:54 +0200 Message-ID: <20261201031002.593830-23-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261201031002.593830-1-jarkko@kernel.org> References: <20261201031002.593830-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_NSEXEC and leaving the context bound to the caller's IPC namespace. Wire up mqueue_set_nsexec() to switch ctx->ipc_ns to the target nsexec's IPC namespace, update fc->user_ns to match, and mark mqueue with FS_NSEXEC_MOUNT. Co-developed-by: David Howells Signed-off-by: David Howells Signed-off-by: Jarkko Sakkinen --- ipc/mqueue.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/ipc/mqueue.c b/ipc/mqueue.c index 322c3dd98c44..026462d9b40f 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_nsexec(struct fs_context *fc, struct nsexec *nsexec) +{ + struct mqueue_fs_context *ctx = fc->fs_private; + struct ipc_namespace *ipc_ns; + + scoped_guard(spinlock, &nsexec->lock) + ipc_ns = get_ipc_ns(nsexec->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,13 @@ 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); + if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) { + ctx->ipc_ns = get_ipc_ns(fc->root->d_sb->s_fs_info); + } else { + 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 +1632,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_nsexec = mqueue_set_nsexec, .get_tree = mqueue_get_tree, }; @@ -1620,7 +1640,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_NSEXEC_MOUNT, }; int mq_init_ns(struct ipc_namespace *ns) -- 2.47.3