mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] fix deadlock in synccall after threaded fork
@ 2019-07-01  3:44 Samuel Holland
  2019-07-01 14:12 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Samuel Holland @ 2019-07-01  3:44 UTC (permalink / raw)
  To: musl; +Cc: Samuel Holland

synccall may be called by AS-safe functions such as setuid/setgid after
fork. although fork() resets libc.threads_minus_one, causing synccall to
take the single-threaded path, synccall still takes the thread list
lock. This lock may be held by another thread if for example fork()
races with pthread_create(). After fork(), the value of the lock is
meaningless, so clear it.
---
 src/process/fork.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/process/fork.c b/src/process/fork.c
index 11286ef4..fb42478a 100644
--- a/src/process/fork.c
+++ b/src/process/fork.c
@@ -28,6 +28,7 @@ pid_t fork(void)
 		self->robust_list.off = 0;
 		self->robust_list.pending = 0;
 		self->next = self->prev = self;
+		__thread_list_lock = 0;
 		libc.threads_minus_1 = 0;
 	}
 	__restore_sigs(&set);
-- 
2.21.0



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] fix deadlock in synccall after threaded fork
  2019-07-01  3:44 [PATCH] fix deadlock in synccall after threaded fork Samuel Holland
@ 2019-07-01 14:12 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2019-07-01 14:12 UTC (permalink / raw)
  To: musl

On Sun, Jun 30, 2019 at 10:44:28PM -0500, Samuel Holland wrote:
> synccall may be called by AS-safe functions such as setuid/setgid after
> fork. although fork() resets libc.threads_minus_one, causing synccall to
> take the single-threaded path, synccall still takes the thread list
> lock. This lock may be held by another thread if for example fork()
> races with pthread_create(). After fork(), the value of the lock is
> meaningless, so clear it.
> ---
>  src/process/fork.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/src/process/fork.c b/src/process/fork.c
> index 11286ef4..fb42478a 100644
> --- a/src/process/fork.c
> +++ b/src/process/fork.c
> @@ -28,6 +28,7 @@ pid_t fork(void)
>  		self->robust_list.off = 0;
>  		self->robust_list.pending = 0;
>  		self->next = self->prev = self;
> +		__thread_list_lock = 0;
>  		libc.threads_minus_1 = 0;
>  	}
>  	__restore_sigs(&set);
> -- 
> 2.21.0

Thanks! Committing this with a maintainer's note referencing the
commits that caused the regression and a further remark on why it's
safe/correct to make this change.

Rich


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-01 14:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-01  3:44 [PATCH] fix deadlock in synccall after threaded fork Samuel Holland
2019-07-01 14:12 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).