]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
futex: Use correct exit on failure from futex_hash_allocate_default()
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Thu, 18 Sep 2025 13:09:45 +0000 (15:09 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 2 Oct 2025 11:48:33 +0000 (13:48 +0200)
[ Upstream commit 4ec3c15462b9f44562f45723a92e2807746ba7d1 ]

copy_process() uses the wrong error exit path from futex_hash_allocate_default().
After exiting from futex_hash_allocate_default(), neither tasklist_lock
nor siglock has been acquired. The exit label bad_fork_core_free unlocks
both of these locks which is wrong.

The next exit label, bad_fork_cancel_cgroup, is the correct exit.
sched_cgroup_fork() did not allocate any resources that need to freed.

Use bad_fork_cancel_cgroup on error exit from futex_hash_allocate_default().

Fixes: 7c4f75a21f636 ("futex: Allow automatic allocation of process wide futex hash")
Reported-by: syzbot+80cb3cc5c14fad191a10@syzkaller.appspotmail.com
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Closes: https://lore.kernel.org/all/68cb1cbd.050a0220.2ff435.0599.GAE@google.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/fork.c

index 1ee8eb11f38bae1d2eb6de9494aea94b7a19e6c3..0cbc174da76acea7ed29ee04c6277a7e0987a76c 100644 (file)
@@ -2289,7 +2289,7 @@ __latent_entropy struct task_struct *copy_process(
        if (need_futex_hash_allocate_default(clone_flags)) {
                retval = futex_hash_allocate_default();
                if (retval)
-                       goto bad_fork_core_free;
+                       goto bad_fork_cancel_cgroup;
                /*
                 * If we fail beyond this point we don't free the allocated
                 * futex hash map. We assume that another thread will be created