From patchwork Mon May 11 06:24:30 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Cuishuangjin X-Patchwork-Id: 134768 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E47294BA79A8 for ; Mon, 11 May 2026 06:25:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E47294BA79A8 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from h3cspam02-ex.h3c.com (smtp.h3c.com [60.191.123.50]) by sourceware.org (Postfix) with ESMTPS id 229074BA799D for ; Mon, 11 May 2026 06:24:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 229074BA799D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=h3c.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=h3c.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 229074BA799D Authentication-Results: sourceware.org; arc=none smtp.remote-ip=60.191.123.50 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778480700; cv=none; b=BDCV3oHZzyka7gCl04bypd+PgMs9VTjEr/sjqYKhNqPr6vi0riSseGoXlHnLC5eKWg3eRhuAM9qr/ff+Hu/xyDHarCnqQo/BgF0QLGCS2NPBuVjVLNwP2pbbcUs+KK8TbNQyZ3E4zdi6FkzrnhhhmUUQpf7+LX+6CJz3bDpQQtY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778480700; c=relaxed/simple; bh=k0yJqavHQMN8oOP89GWHiSiTwK9hS6ZngsWL43vH088=; h=From:To:Subject:Date:Message-ID:MIME-Version:DKIM-Signature; b=M5ypHJKuFn17qnwHc9n7Nza9hbntGVDXoOIgS0KMzZ3mPlw0s8Sj/r9zTP/XK52+CItD3al1VkiNQYupiES4ThHkFL533UDfmfg7Lorpi+49LOPUHfGlZwDuj5wCtAjmKES0A1I+z1w1J2IfM2OvUtxvB0BhxnDaim+e6GxelRE= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 229074BA799D Received: from mail.maildlp.com ([172.25.15.154]) by h3cspam02-ex.h3c.com with ESMTP id 64B6Ofeg080134; Mon, 11 May 2026 14:24:41 +0800 (+08) (envelope-from YS.cuishuangjin@h3c.com) Received: from DAG6EX09-BJD.srv.huawei-3com.com (unknown [10.153.34.11]) by mail.maildlp.com (Postfix) with ESMTP id E043A20045BA; Mon, 11 May 2026 14:36:30 +0800 (CST) Received: from DAG6EX11-BJD.srv.huawei-3com.com (10.153.34.13) by DAG6EX09-BJD.srv.huawei-3com.com (10.153.34.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.27; Mon, 11 May 2026 14:24:31 +0800 Received: from DAG6EX11-BJD.srv.huawei-3com.com ([fe80::d89c:ca51:f097:35ef]) by DAG6EX11-BJD.srv.huawei-3com.com ([fe80::d89c:ca51:f097:35ef%17]) with mapi id 15.02.1258.027; Mon, 11 May 2026 14:24:31 +0800 From: Cuishuangjin To: "libc-alpha@sourceware.org" CC: "glibc@sourceware.org" , Zhangchun Subject: [PATCH] malloc: Fix ABBA deadlock in fork handlers Thread-Topic: [PATCH] malloc: Fix ABBA deadlock in fork handlers Thread-Index: AdzhDqvJ0G8JZWmkSvClpoevWu65SA== Date: Mon, 11 May 2026 06:24:30 +0000 Message-ID: Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.142.32.138] x-sender-location: DAG2 MIME-Version: 1.0 X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: h3cspam02-ex.h3c.com 64B6Ofeg080134 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=h3c.com; s=default; t=1778480693; bh=k0yJqavHQMN8oOP89GWHiSiTwK9hS6ZngsWL43vH088=; h=From:To:CC:Subject:Date; b=ASU20PPFCMwsGZPvNHdgRECAouUW7pDKnTJNG5u+5CkwNEU7Ga9xH29W8YYLl9v0J PIhAovzPbbmGHNPYAWE5v2F6GT9yvdQiIMuMVIZIsFDsi3o8ebBKiZweS3Ld2EUFdt tKu5Dyh/q07ab9a5TTwXWRK5OHozCbGavVHlzbxtavgoEN3Ebiz6kupl5pJzAwjVD6 rhgwyXYoJhoBIyc1odIA4Vx7OhAdtJhJFDJDRvcf8f2/f0YHIOzuDt4CuIUKpo3Rrs 4T8jsvzArsw88LKWv5mxTkHXvzjBEUgit30YntsbBt+EXQ64xBs7XRUONdL/SkLjH/ tzLysLeM++Biw== X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_50, BODY_8BITS, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, HTML_MESSAGE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, T_MIME_MALF, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From 7b2df68f726741d2e39df9933a9044290e6f5a2e Mon Sep 17 00:00:00 2001 From: cys43405 Date: Sat, 9 May 2026 20:30:09 +0800 Subject: [PATCH] glibc: Fix ABBA deadlock between fork handlers and atfork registration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Detailed description: - Problem analysis: glibc 2.38-50 has an ABBA deadlock issue. When thread A executes prepare_handler during fork phase while thread B concurrently registers pthread_atfork handlers, a deadlock occurs where thread A holds malloc_lock and waits for atfork_lock, while thread B holds atfork_lock and waits for malloc_lock. - Timeline: Timeline │ Thread A (__run_prefork_handlers) │ Thread B (__register_atfork) ────────────┼──────────────────────────────────────────┼────────────────────────────── T1 │ Holds atfork_lock │ T2 │ lll_unlock(atfork_lock) ────────────► │ T3 │ Executes prepare_handler() │ lll_lock(atfork_lock) T4 │ └─► ptmalloc_lock_all() │ Holds atfork_lock T5 │ Holds malloc_lock │ fork_handler_list_emplace() T6 │ lll_lock(atfork_lock) ◄──── Blocked ── │ └─► malloc() ◄──── Blocked ─┐ - Solution: Weaken definitions of __malloc_fork_lock_parent, __malloc_fork_unlock_parent, and __malloc_fork_unlock_child in glibc 2.38-50 to prevent hard-linking inconsistencies. Strengthen malloc_lock management in __register_atfork prepare_handler functions for ptmalloc and tcmalloc libraries. - Testing method: Use unmodified .so library with one process continuously forking while another registers pthread_atfork handlers to verify deadlock occurrence. Compare with modified .so to confirm issue resolution. Signed-off-by: shuangjin cui --- malloc/Versions | 5 +++++ malloc/arena.c | 6 +++--- malloc/malloc-internal.h | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) 如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from New H3C, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it! diff --git a/malloc/Versions b/malloc/Versions index a9ce4a035f..40532c89dc 100644 --- a/malloc/Versions +++ b/malloc/Versions @@ -43,6 +43,11 @@ libc { # v* valloc; + + # weak malloc fork lock/unlock + __malloc_fork_lock_parent; + __malloc_fork_unlock_parent; + __malloc_fork_unlock_child; } GLIBC_2.1 { # Special functions. diff --git a/malloc/arena.c b/malloc/arena.c index ddde32c712..032e0dd69d 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -162,7 +162,7 @@ arena_for_chunk (mchunkptr ptr) called, so that other fork handlers can use the malloc subsystem. */ -void +void __attribute__((weak)) __malloc_fork_lock_parent (void) { /* We do not acquire free_list_lock here because we completely @@ -179,7 +179,7 @@ __malloc_fork_lock_parent (void) } } -void +void __attribute__((weak)) __malloc_fork_unlock_parent (void) { for (mstate ar_ptr = &main_arena;; ) @@ -192,7 +192,7 @@ __malloc_fork_unlock_parent (void) __libc_lock_unlock (list_lock); } -void +void __attribute__((weak)) __malloc_fork_unlock_child (void) { /* Push all arenas to the free list, except thread_arena, which is diff --git a/malloc/malloc-internal.h b/malloc/malloc-internal.h index a6340bfd88..978d6bb1d4 100644 --- a/malloc/malloc-internal.h +++ b/malloc/malloc-internal.h @@ -26,13 +26,13 @@ #include /* Called in the parent process before a fork. */ -void __malloc_fork_lock_parent (void) attribute_hidden; +void __attribute__((weak)) __malloc_fork_lock_parent (void) ; /* Called in the parent process after a fork. */ -void __malloc_fork_unlock_parent (void) attribute_hidden; +void __attribute__((weak)) __malloc_fork_unlock_parent (void) ; /* Called in the child process after a fork. */ -void __malloc_fork_unlock_child (void) attribute_hidden; +void __attribute__((weak)) __malloc_fork_unlock_child (void) ; /* Called as part of the thread shutdown sequence. */ void __malloc_arena_thread_freeres (void) attribute_hidden; -- 2.33.0 ------------------------------------------------------------------------------------------------------------------------------------- 本邮件及其附件含有新华三集团的保密信息,仅限于发送给上面地址中列出的个人或群组。 禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。