From nobody Wed Feb 11 04:02:50 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770726285470532.2041876842898; Tue, 10 Feb 2026 04:24:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vpmim-0000tg-Pd; Tue, 10 Feb 2026 07:20:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vpmhJ-0005v0-JT; Tue, 10 Feb 2026 07:18:31 -0500 Received: from isrv.corpit.ru ([212.248.84.144]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vpmhG-0001JU-9G; Tue, 10 Feb 2026 07:18:28 -0500 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id A900D187DC6; Tue, 10 Feb 2026 15:14:47 +0300 (MSK) Received: from think4mjt.tls.msk.ru (mjtthink.wg.tls.msk.ru [192.168.177.146]) by tsrv.corpit.ru (Postfix) with ESMTP id 473CC360CEB; Tue, 10 Feb 2026 15:15:43 +0300 (MSK) From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Aleksandr Sergeev , Richard Henderson , Michael Tokarev Subject: [Stable-10.1.4 94/95] linux-user/syscall.c: Prevent acquiring clone_lock while fork() Date: Tue, 10 Feb 2026 15:15:16 +0300 Message-ID: <20260210121526.68598-20-mjt@tls.msk.ru> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=212.248.84.144; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1770726285742158500 Content-Type: text/plain; charset="utf-8" From: Aleksandr Sergeev By the spec, fork() copies only the thread which executes it. So it may happen, what while one thread is doing a fork, another thread is holding `clone_lock` mutex (e.g. doing a `fork()` or `exit()`). So the child process is born with the mutex being held, and there are nobody to release it. As the thread executing do_syscall() is not considered running, start_exclusive() does not protect us from the case. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3226 Signed-off-by: Aleksandr Sergeev Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson Message-ID: <20260126151612.2176451-1-sergeev0xef@gmail.com> (cherry picked from commit d22e9aec572396836782e993cb18d598e6012688) Signed-off-by: Michael Tokarev diff --git a/linux-user/main.c b/linux-user/main.c index 68972f00a1..7932f9f03b 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -146,6 +146,7 @@ unsigned long guest_stack_size =3D TARGET_DEFAULT_STACK= _SIZE; void fork_start(void) { start_exclusive(); + clone_fork_start(); mmap_fork_start(); cpu_list_lock(); qemu_plugin_user_prefork_lock(); @@ -175,6 +176,7 @@ void fork_end(pid_t pid) cpu_list_unlock(); } gdbserver_fork_end(thread_cpu, pid); + clone_fork_end(child); /* * qemu_init_cpu_list() reinitialized the child exclusive state, but we * also need to keep current_cpu consistent, so call end_exclusive() f= or diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 9c7a5837eb..37ff060e8b 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6736,6 +6736,20 @@ static void *clone_func(void *arg) return NULL; } =20 +void clone_fork_start(void) +{ + pthread_mutex_lock(&clone_lock); +} + +void clone_fork_end(bool child) +{ + if (child) { + pthread_mutex_init(&clone_lock, NULL); + } else { + pthread_mutex_unlock(&clone_lock); + } +} + /* do_fork() Must return host values and target errnos (unlike most do_*() functions). */ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, diff --git a/linux-user/user-internals.h b/linux-user/user-internals.h index 191e01c3a8..267c3930d7 100644 --- a/linux-user/user-internals.h +++ b/linux-user/user-internals.h @@ -67,6 +67,8 @@ abi_long get_errno(abi_long ret); const char *target_strerror(int err); int get_osversion(void); void init_qemu_uname_release(void); +void clone_fork_start(void); +void clone_fork_end(bool child); void fork_start(void); void fork_end(pid_t pid); =20 --=20 2.47.3