[PATCH Next] copy_process(): Fixed jump logic error

Edward Adam Davis posted 1 patch 1 week ago
kernel/fork.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH Next] copy_process(): Fixed jump logic error
Posted by Edward Adam Davis 1 week ago
After futex_hash_allocate_default() fails, the logic should jump to
bad_fork_cancel_cgroup, not bad_fork_core_free.

Jumping to bad_fork_core_free would cause a siglock imbalance.

Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
 kernel/fork.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index e9a7fb5c3e49..a0b8eeeb1d27 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -2349,7 +2349,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
-- 
2.43.0
Re: [PATCH Next] copy_process(): Fixed jump logic error
Posted by Vlastimil Babka 5 days, 8 hours ago
On 9/24/25 14:06, Edward Adam Davis wrote:
> After futex_hash_allocate_default() fails, the logic should jump to
> bad_fork_cancel_cgroup, not bad_fork_core_free.
> 
> Jumping to bad_fork_core_free would cause a siglock imbalance.
> 
> Signed-off-by: Edward Adam Davis <eadavis@qq.com>

Sebastian already fixed this and it's in tip: locking/urgent

https://lore.kernel.org/all/20250918130945.-7SIRk8Z@linutronix.de/

> ---
>  kernel/fork.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/fork.c b/kernel/fork.c
> index e9a7fb5c3e49..a0b8eeeb1d27 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -2349,7 +2349,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
Re: [PATCH Next] copy_process(): Fixed jump logic error
Posted by Sebastian Andrzej Siewior 5 days, 8 hours ago
On 2025-09-26 17:11:12 [+0200], Vlastimil Babka wrote:
> On 9/24/25 14:06, Edward Adam Davis wrote:
> > After futex_hash_allocate_default() fails, the logic should jump to
> > bad_fork_cancel_cgroup, not bad_fork_core_free.
> > 
> > Jumping to bad_fork_core_free would cause a siglock imbalance.
> > 
> > Signed-off-by: Edward Adam Davis <eadavis@qq.com>
> 
> Sebastian already fixed this and it's in tip: locking/urgent

A pull request has been sent to Linus earlier today.

Sebastian
Re: [PATCH Next] copy_process(): Fixed jump logic error
Posted by David Hildenbrand 1 week ago
On 24.09.25 14:06, Edward Adam Davis wrote:
> After futex_hash_allocate_default() fails, the logic should jump to
> bad_fork_cancel_cgroup, not bad_fork_core_free.
> 
> Jumping to bad_fork_core_free would cause a siglock imbalance.
> 
> Signed-off-by: Edward Adam Davis <eadavis@qq.com>

If it's still only in -next (which I assume when looking at the Next 
tag), into which patch should this fixup get squashed?

Or is this already upstream and we want actually Fixes: and CC stable?

(staring at current master, this seems to be an upstream problem?)

> ---
>   kernel/fork.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/fork.c b/kernel/fork.c
> index e9a7fb5c3e49..a0b8eeeb1d27 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -2349,7 +2349,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

Makes me wonder whether we would have to undo anything the 
sched_cgroup_fork() did, or if that cleanup is implied in 
bad_fork_cancel_cgroup. Without digging too deep into the code, I assume 
the latter.

-- 
Cheers

David / dhildenb