From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 63DB73858432; Wed, 24 Jan 2024 03:19:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 63DB73858432 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1706066359; bh=raL+niLgecpzTNc31o1W8tyfPB9bpL3Wxx1iagwJy+A=; h=From:To:Subject:Date:From; b=EBqSUnS05Eef0ArhbJrfBsa9smrNxcQSLx49vNLDBJn5IVUpmZOJ2ueAZ5dABlIg7 yH2T+NF5sOIgNW9w6qMYEccwz1tKxXsSc8v6mbnR4+j+gW7QQi7zs0zVbwQMJ8Y6Mj YG+VDbFHBI3SX8LJv24vagnR97IL5AF92G6fIqKg= From: "jimb@red-bean.com" To: glibc-bugs@sourceware.org Subject: [Bug dynamic-link/31285] New: Segfault when returning from main while a thread calls dlclose Date: Wed, 24 Jan 2024 03:19:18 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: dynamic-link X-Bugzilla-Version: 2.38 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jimb@red-bean.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31285 Bug ID: 31285 Summary: Segfault when returning from main while a thread calls dlclose Product: glibc Version: 2.38 Status: UNCONFIRMED Severity: normal Priority: P2 Component: dynamic-link Assignee: unassigned at sourceware dot org Reporter: jimb@red-bean.com Target Milestone: --- If the program's main thread returns while another thread calls dlclose on a shared library that has a static variable with a destructor, dlclose may un= map the shared library's code while the main thread is still executing the destructor, causing a crash. This can manifest as intermittent crashes at exit, as in this issue: https://github.com/gfx-rs/wgpu/issues/5084 The bug is that if the main thread calls `__run_exit_handlers` and finds the shared library's destructor's entry in __exit_funcs` first, changes its fla= vor to `ef_free`, releases `__exit_funcs_lock`, and then calls the entry's function, that function is arbitrary code which may take a long time to run. While it does so, another thread may `dlclose` the shared library, skip past the entry in `__exit_funcs` since it is marked as `ef_free`, and proceed to unmap the shared library's code while the main thread is still working. The attached test case reproduces the bug reliably. To reproduce, download = the attached test case as `dlclose-crash.tar.gz`, and then: ``` $ tar xf dlclose-crash.tar.gz=20 $ cd dlclose-crash/ $ make g++ -g -export-dynamic main.cpp -o main g++ -g -shared -fPIC solib.cpp -o solib.so $ ./main Segmentation fault (core dumped) $=20 ``` --=20 You are receiving this mail because: You are on the CC list for the bug.=