]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
linux-user: Hold the fd-trans lock across fork
authorGeoffrey Thomas <geofft@ldpreload.com>
Fri, 14 Mar 2025 12:47:42 +0000 (08:47 -0400)
committerRichard Henderson <richard.henderson@linaro.org>
Thu, 10 Jul 2025 19:49:03 +0000 (13:49 -0600)
If another thread is holding target_fd_trans_lock during a fork,
then the lock becomes permanently locked in the child and the
emulator deadlocks at the next interaction with the fd-trans table.
As with other locks, acquire the lock in fork_start() and release
it in fork_end().

Cc: qemu-stable@nongnu.org
Signed-off-by: Geoffrey Thomas <geofft@ldpreload.com>
Fixes: c093364f4d91 "fd-trans: Fix race condition on reallocation of the translation table."
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2846
Buglink: https://github.com/astral-sh/uv/issues/6105
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250314124742.4965-1-geofft@ldpreload.com>

linux-user/fd-trans.h
linux-user/main.c

index 910faaf237cca2a6c02d9715369acfbc9d31c311..e14f96059c513caa62d396c5269246f2ccb15f9e 100644 (file)
@@ -36,6 +36,16 @@ static inline void fd_trans_init(void)
     qemu_mutex_init(&target_fd_trans_lock);
 }
 
+static inline void fd_trans_prefork(void)
+{
+    qemu_mutex_lock(&target_fd_trans_lock);
+}
+
+static inline void fd_trans_postfork(void)
+{
+    qemu_mutex_unlock(&target_fd_trans_lock);
+}
+
 static inline TargetFdDataFunc fd_trans_target_to_host_data(int fd)
 {
     if (fd < 0) {
index a9142ee726896ca0f746d981827f4d4167e5fb0c..f4f20074396201ddde7d38cd833975b8d064a1c0 100644 (file)
@@ -149,12 +149,14 @@ void fork_start(void)
     cpu_list_lock();
     qemu_plugin_user_prefork_lock();
     gdbserver_fork_start();
+    fd_trans_prefork();
 }
 
 void fork_end(pid_t pid)
 {
     bool child = pid == 0;
 
+    fd_trans_postfork();
     qemu_plugin_user_postfork(child);
     mmap_fork_end(child);
     if (child) {