]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
futex: Pass in task to futex_queue()
authorJens Axboe <axboe@kernel.dk>
Wed, 15 Jan 2025 16:05:15 +0000 (09:05 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 22 Mar 2025 19:54:14 +0000 (12:54 -0700)
commitaa189c394168ad53d8eacb82a1cc258d2cd90129
treeb70783bae8b809079285536bdc4a809eaf177bed
parentfb51a7209398054c88b8750937ebbac4931bb0d2
futex: Pass in task to futex_queue()

[ Upstream commit 5e0e02f0d7e52cfc8b1adfc778dd02181d8b47b4 ]

futex_queue() -> __futex_queue() uses 'current' as the task to store in
the struct futex_q->task field. This is fine for synchronous usage of
the futex infrastructure, but it's not always correct when used by
io_uring where the task doing the initial futex_queue() might not be
available later on. This doesn't lead to any issues currently, as the
io_uring side doesn't support PI futexes, but it does leave a
potentially dangling pointer which is never a good idea.

Have futex_queue() take a task_struct argument, and have the regular
callers pass in 'current' for that. Meanwhile io_uring can just pass in
NULL, as the task should never be used off that path. In theory
req->tctx->task could be used here, but there's no point populating it
with a task field that will never be used anyway.

Reported-by: Jann Horn <jannh@google.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/22484a23-542c-4003-b721-400688a0d055@kernel.dk
Signed-off-by: Sasha Levin <sashal@kernel.org>
io_uring/futex.c
kernel/futex/core.c
kernel/futex/futex.h
kernel/futex/pi.c
kernel/futex/waitwake.c