From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14319 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Samuel Holland Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] fix deadlock in synccall after threaded fork Date: Sun, 30 Jun 2019 22:44:28 -0500 Message-ID: <20190701034428.62764-1-samuel@sholland.org> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="136181"; mail-complaints-to="usenet@blaine.gmane.org" Cc: Samuel Holland To: musl@lists.openwall.com Original-X-From: musl-return-14335-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jul 01 05:44:47 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1hhnFG-000ZKZ-6P for gllmg-musl@m.gmane.org; Mon, 01 Jul 2019 05:44:46 +0200 Original-Received: (qmail 24399 invoked by uid 550); 1 Jul 2019 03:44:43 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 24365 invoked from network); 1 Jul 2019 03:44:42 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm3; bh=8i75rKaafCzBCeghm30UpNfVcJ 9EUzC6sgE+6mtQaa0=; b=doy1H45zM77/rTJKlswKPgJh2BkRBuQnWouJP+hTKS UiFZnidFwAnpbYx+ipnvDh7YY9S4+93yylWg6WyKE6p9IZjh37x03VmEIVq3+DLE 4rQfo+6kEJ17A3koQyPH3RIsCdW2RcCcIbfEcCXGdxh/+VlMRLqCVAH5dpW3VuNc +6My1uesp09RyF3xdEQ7EU1F1414kinOcnaaE9egj+YRI7pTeUrkym6tw/eGm8ER +WoZtlwumfcHY0iQR7SbEZZ7F2JmQL0s/ndJZrIPL4z1q+y9iujduwhurGjufQlb tzTxAKbKn3RtauB0jGrqos8jpzjQ1sL8XHMIUAiPSfPA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=8i75rKaafCzBCeghm 30UpNfVcJ9EUzC6sgE+6mtQaa0=; b=LX5huRBE3c5GpjsJ3ywm3gjmzrtm974E+ X8GoMtkOuVPUTvtzsLwXeE4c9PRd9LbJdfgAYqlvDYqmDutALdNH+V8217OkVcFM d75hqK7YZsHGwZmgpxjJIfD6jtxx8pEMwE2CtiG+k6aYS5VamcP5k0trrv+6cKOI rimsTdXVyqOzMhVnjQ0AXQPxjJ1iNalznJGBo//dbnPKj5uQiZTTJdrvP/ENMqKh bj7fxpPgWh+mAIdyKlTMLbSkdqSsL+0+D8EROmn3hDtdU5Ero0WhTkAXvXTpINIV THklUtR6kD1FqAugeWlFBlaBJgVgPwgGu1f5HbVPQa3O+908JzzKg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrvdehgdejgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffoggfgsedtkeertdertd dtnecuhfhrohhmpefurghmuhgvlhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhl lhgrnhgurdhorhhgqeenucfkphepjedtrddufeehrddugeekrdduhedunecurfgrrhgrmh epmhgrihhlfhhrohhmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgnecuvehluhhs thgvrhfuihiivgeptd X-ME-Proxy: X-Mailer: git-send-email 2.21.0 Xref: news.gmane.org gmane.linux.lib.musl.general:14319 Archived-At: 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