Re: [PATCH] futex: Use correct exit on failure from futex_hash_allocate_default()
From: Steven Rostedt
Date: Thu Sep 18 2025 - 11:29:21 EST
On Thu, 18 Sep 2025 15:09:45 +0200
Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx> wrote:
> 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 previous 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().
if (need_futex_hash_allocate_default(clone_flags)) {
retval = futex_hash_allocate_default();
if (retval)
goto bad_fork_core_free;
[..]
}
[..]
write_lock_irq(&tasklist_lock);
[..]
klp_copy_process(p);
sched_core_fork(p);
spin_lock(¤t->sighand->siglock);
[..]
bad_fork_core_free:
sched_core_free(p);
spin_unlock(¤t->sighand->siglock);
write_unlock_irq(&tasklist_lock);
bad_fork_cancel_cgroup:
cgroup_cancel_fork(p, args);
Yep, looks bad to me!
Reviewed-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
-- Steve
>
> Fixes: 7c4f75a21f636 ("futex: Allow automatic allocation of process wide futex hash")
> Reported-by: syzbot+80cb3cc5c14fad191a10@xxxxxxxxxxxxxxxxxxxxxxxxx
> Closes: https://lore.kernel.org/all/68cb1cbd.050a0220.2ff435.0599.GAE@xxxxxxxxxx
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
>