[RFC PATCH v9 22/29] ipc/mqueue: Implement ->set_nsexec() fs_context operation
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Tue Dec 1 03:26:24 UTC 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Critical] ipc/mqueue: unlocked s_fs_info access in
mqueue_init_fs_context()
--
commit 067998e02a49b9e15984753bd84467279b66c72f
Author: Jarkko Sakkinen <jarkko at kernel.org>
ipc/mqueue: Implement ->set_nsexec() fs_context operation
This commit implements the ->set_nsexec() fs_context operation for mqueue
so that FSCONFIG_SET_NSEXEC binds the mount context to the target nsexec's
IPC and user namespaces, and marks mqueue with FS_NSEXEC_MOUNT.
> diff --git a/ipc/mqueue.c b/ipc/mqueue.c
> index 322c3dd98c447..026462d9b40f9 100644
> --- a/ipc/mqueue.c
> +++ b/ipc/mqueue.c
[ ... ]
> @@ -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);
[Severity: Critical]
Can this race with put_ipc_ns() and cause a use-after-free on struct
ipc_namespace?
An mqueue superblock does not hold a reference to the ipc_namespace in
sb->s_fs_info; instead, put_ipc_ns() drops the last reference and clears
sb->s_fs_info under mq_lock (which is why get_ns_from_inode() takes
mq_lock around get_ipc_ns(inode->i_sb->s_fs_info)). Without mq_lock, a
reconfiguration context created via fspick() can read s_fs_info as the
last reference is dropped:
CPU0 CPU1
mqueue_init_fs_context() put_ipc_ns(ns)
ns = fc->root->d_sb->s_fs_info
ns_ref_put_and_lock(ns, &mq_lock)
mq_clear_sbinfo(ns)
spin_unlock(&mq_lock)
schedule_work(&free_ipc_work)
get_ipc_ns(ns) <-- refcount inc on 0
free_ipc()
free_ipc_ns(ns) <-- frees ns
mqueue_fs_context_free()
put_ipc_ns(ctx->ipc_ns) <-- use-after-free
Acquiring ctx->ipc_ns under spin_lock(&mq_lock) (or leaving ctx->ipc_ns as
NULL for FS_CONTEXT_FOR_RECONFIGURE, since mqueue does not use it during
reconfiguration) would avoid this race.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201031002.593830-1-jarkko@kernel.org?part=22
More information about the Linux-security-module-archive
mailing list