Message ID | 068770faf123b7c227f5f1e130812f7976e74cef.1613390045.git.szabolcs.nagy@arm.com |
---|---|
State | Superseded |
Delegated to: | Adhemerval Zanella Netto |
Headers |
Return-Path: <libc-alpha-bounces@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 035FA395043D; Mon, 15 Feb 2021 12:00:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 035FA395043D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1613390458; bh=wEMIeGlH1BROBxLoYkYFFMRujAl6eUUp+uFYrvgpUB4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=S6PpKBQVd2MnAqQfvDcE+I30eLkvPwWf/gYPSTVzPFaHhosgt6SyfO/q+0eLRLXFq 9jvPHm20TrzCPHtCENmY+lVVa97SYYHtmZoHTAjN+Et0nDaUUxt4WmqAoo6B3xV6ZG yW9RtigfvN7GXBTgW6N1JHkMwdUt7O28W3o3qmzI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2041.outbound.protection.outlook.com [40.107.20.41]) by sourceware.org (Postfix) with ESMTPS id 895DF3950433 for <libc-alpha@sourceware.org>; Mon, 15 Feb 2021 12:00:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 895DF3950433 Received: from AM6PR10CA0094.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:8c::35) by DBBPR08MB4902.eurprd08.prod.outlook.com (2603:10a6:10:db::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.26; Mon, 15 Feb 2021 12:00:53 +0000 Received: from AM5EUR03FT052.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8c:cafe::20) by AM6PR10CA0094.outlook.office365.com (2603:10a6:209:8c::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.25 via Frontend Transport; Mon, 15 Feb 2021 12:00:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;sourceware.org; dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT052.mail.protection.outlook.com (10.152.17.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.25 via Frontend Transport; Mon, 15 Feb 2021 12:00:53 +0000 Received: ("Tessian outbound 587c3d093005:v71"); Mon, 15 Feb 2021 12:00:52 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: e14dd9e20223431d X-CR-MTA-TID: 64aa7808 Received: from d5675ee776da.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 3AC2B46D-3BE6-4A49-B585-4262EBC33871.1; Mon, 15 Feb 2021 12:00:37 +0000 Received: from FRA01-PR2-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d5675ee776da.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 15 Feb 2021 12:00:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CCDkXF3fDxtlIZuBov2hlpMNPNYiSRMyHn+mT16HMjCIWrU5P86qgISR4koMrwjv77nKFrhgBflGTrnK8dELPC1AWmr1sX+WXzcD38RjT3Yjf7iSlMSeC1UKBm8I+jKCzqR/HQZduTCqa84WQBDPeEDhxWhuK8QUPet0jFcP+6qa4lB0IYNg4R1PlgNgp5Ksri1J0yHomXLoZo6B2cj70bM8jhT1rp5r2xm5f5Srnftv6ou3iWcD+7me3SH+5qaFbh93Xdwx88EO+ArJwQmGh0QrbDpHrkyEUJiOVN3OhG/Sw1j0ky9X7wnWiLo7VizrNrh7+X5DNOB6URlkWhZHQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wEMIeGlH1BROBxLoYkYFFMRujAl6eUUp+uFYrvgpUB4=; b=dsHR3wnWU1X1GWKK7DQr87EFSSe8Emdaa0IyaauPvFL8kJwtiVCjuOL5/pdGUZFwt9tMVIiH94J95dkmf6cRQLpbytRj0BRKa+/HQN5bWTIU9Ctm7vMrJg7E3DWGvOuJc7kvrmcrrXZgYtxUIW72+rtaJGT4J2xX7/qprH7KMWGh6mwAYg57F6xkLf5lx6Ov45M1huic3cJMa61THsNeFcJ4GN9Gei7WceEtlBxRFZYtGg+THfZ4sO5mehuVucq83dtuZbaM+Xq18dKKnbwAVysin9eAauIKDUs77oYBVOpwXOXd2WFW4kdV6bV1jc44O1rtYz8pyMWQpL+mXxMUEA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) by PR2PR08MB4874.eurprd08.prod.outlook.com (2603:10a6:101:1d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.38; Mon, 15 Feb 2021 12:00:35 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::60f0:3773:69b8:e336]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::60f0:3773:69b8:e336%2]) with mapi id 15.20.3846.042; Mon, 15 Feb 2021 12:00:35 +0000 To: libc-alpha@sourceware.org Subject: [PATCH 06/15] elf: Fix comments and logic in _dl_add_to_slotinfo Date: Mon, 15 Feb 2021 11:59:46 +0000 Message-Id: <068770faf123b7c227f5f1e130812f7976e74cef.1613390045.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <cover.1613390045.git.szabolcs.nagy@arm.com> References: <cover.1613390045.git.szabolcs.nagy@arm.com> Content-Type: text/plain X-Originating-IP: [217.140.106.49] X-ClientProxiedBy: LO2P265CA0333.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a4::33) To PA4PR08MB6320.eurprd08.prod.outlook.com (2603:10a6:102:e5::9) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.49) by LO2P265CA0333.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a4::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.36 via Frontend Transport; Mon, 15 Feb 2021 12:00:35 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 44a70f57-1dcc-463e-070e-08d8d1a95847 X-MS-TrafficTypeDiagnostic: PR2PR08MB4874:|DBBPR08MB4902: X-Microsoft-Antispam-PRVS: <DBBPR08MB49024E2E8CEDB66288AC6C61ED889@DBBPR08MB4902.eurprd08.prod.outlook.com> x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:3513;OLM:3513; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: UormEK6iwnCV3njYW41SDmLQS0cwI+k+xBX34gWg35kOlL6s0y7geyNWumfUSuW2eeMd+awCYKhgIJIPTydvCHNynIF36pqDPHFP7wWuJWyT7/3rA6KW3C7oud4JEh3UvLCoPsA611mSnZqpWxmefyS7UcrsHxZgZ7x0CpjoKQqnCIS4S+WZvcTba29NFITtWOYNJFFhUPk6NiZln4KO7/0ne1/SVWU11p+G2Zjh1HMeUjAnms/wS+2stY0H/WSqFGAh7qXV3KpZIyfSEqVvON2ss3TwxpKsI1bGZX4dPdt9L6johTI4HbbFOMNtHJQP3p7dQemdrfTWTOTPI9dq9Dcj7meuBNqSPTYn5ayu5/VS9eyz3SsaYDgfw7ccuhTNiKPjNiqWztsfZXxnC14jK/kohT1LSJraB87j+z0Rz9mcPN6L7g/D3qvGd90bMa9eUDLvE/kX5pdRgooWDpetZPzg58dIm8WKDE7HXCjIY7ipy60uscf4Bc+bCTIfxCf+1DqL8PCnIdUNSWIv7aY6QQZairwY8XPblUTWvPXCKRO4rucpYa88svQOHIBdqeoWlmgfcZhXyLGPVi+CK3Vg8g== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PA4PR08MB6320.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(136003)(346002)(366004)(39850400004)(376002)(2616005)(16526019)(6506007)(6486002)(83380400001)(956004)(66946007)(2906002)(26005)(186003)(44832011)(69590400012)(8676002)(6512007)(66476007)(478600001)(5660300002)(52116002)(36756003)(66556008)(6666004)(316002)(6916009)(8936002)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: uMjrinCyv7le9O5dENz1K9hk87jwHN1thEhoNUoHCcHfDukyNa6u8slxiQKKeH0sQ9mGgIjHrdaZUoG/uP25L3PM/JmfmZZ3V2XP11Gip7PaxENdoqDWwgNHuDYtzJoFptNbeeRhOgh3EW3FPJMftckyu/kHhnS0CN2AqBvgRSwFE65GuzTjagNo+UB+uoNLUMI1jJioQgV27YlLE+zgjXFCZg5k44QZQ13eELvprSl446k3HEAh222nujZzl9yMpWUoYh7IywbHyCgR7iRK+i2bAJQ8NdRCw5QOPcVj+n9stNlo6TkksM+WPev9rzCeeaqVAUd68R65e82m2wBYt3SVWTZwA5xTj27Zv37G1eAtbMHiXVhzqO8IZZ2AxxD09Ph5vNT8ufyTd8NLaIpT1B4CucnWM4byLLJI011B46gQa2zXy+tqVdCiZPy3HSgaouVirbegv4/oItDeRdWbNwkurci7imE6tEHZzmox/ThoayK6ZPZ2SDbOuUC+/h8rJwe2a+TfaHpttR/yAZFQEDdzjW0YfPmgoDtlAyKQj4uhgo2SSi6Cmf4sfwPk0cOUhergowBFTqZlYQNnWvLGfu3/2pq8KIwhqJFrzXThKAvlm2hHr0iJ5Pn3xEDi48HdxZ2drlIz15GdARCV9KVvhcSdcBt1LNPYFogjXOTLvRkSwt+1ROOwrCb4GHT9E+0d4XuQwwpKNOGDMoEz/642EVS4K/a0M77q3H3W5RjohUzRqoh45P8fRbY0OiFdwz9W4nQ7auyu+LGId9FyU2nFfliSyrBfIgy0YKF3UX94VoIxIlRdSWf3tSSwRAzdt2cLSAL6wvQ+NmEz44AaL8WsQAsjnoyXjt2FrzVneHY2Z7V+MRFGTwqmytzWeFc9Ju+X2oUFVSG6euMh2MuZc3bHnlOa7vzphIlPrYiNfNCj944uH+Ku4uXmKGCuhDH7Ni4QwMXXVaqKlyfP5TbB8KB0UBYYR1n/9ZiF6Ty1u2zGF6pTvJyynlVR9jek7vBrs8Zfsrjl7J7rmETwFIfWJSTAMt9A5VU+2e0Ct3zppTk4ktCBVlsSq9E2Vuhs7xXA+OSB1o+HSJMfQrOpejaCBtpWIyVy8doRrDIPOhln5IMhF4m3b+XzwwkbmBlXYHcriP630cX+qEWBF09YNC2JHrdB7ogmmSg9ixzk4q8/AOJ3C/GPsS5MHxjouZABKniLoH8zI35s8s3QUNAMv6yXwyiMxlOv/ieVeKig518hrU3H1G1zt7n90mlQR2q9r4UEdNO8+mfSRyUJ4Z9IvIb6Ut71eEmSjpXDncJFGtxvLYgclAqYXWV5zaaCfrEVY68DLnSB X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR2PR08MB4874 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT052.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 4966c90c-7ec2-4c2b-152b-08d8d1a94dbc X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: K/pkn/of14htd3ApfHwhfqbMEZ80Nt8TyhAn8jX/vRK8Ov3Tm5YXvK4Uuo0R54K1cEmmsCwFmMlmxr1hOdWMfBlEdfA+8MINlrobBqeSai0M14Hc4XjfOShI8rnSgemOsYei3pcb5zXUhJFDzrRkc//QgOSpQgV8W4EC0cyaMDfANuYlsTo1qAJmtoAOec3paZjwm9uYq2OFNvTl9GVJ/sv9IN+amsyrydgovLUVp7iObHa3hCYOo5Kv4P9I9VTGAZxzlTDbWYNdUB5bA8ynH1/Y2Vcc0UCpomuLUdvBzECSXm0pc4A/1XRH7O8rOGr4IUphHJ7yJ1WaoazND5lv0PtyjCkaA4I1afzr3jXF1ZOyTmM5Dwc5crp/+gpkq41Hk9y582MZ8dF0kfyiH0sPOokKKM45aiPzWPStwv1hvFDJ0LnI9qADzD+Jro3I6dCUZT/WYC+hz2OFxjgD1C5vne/f6GCGorCHtFmeesd2oStIZiMDNSodwjbgJEXiH1jWr3VB9/c7ZLXlXRoKx9Mxdh3NVHrIjGV8q+6fA16pT4oqb94IYsrdcIjiSIB52uxKgP7qGpD4o/TwOldbsljJSIRrI0sUu6OVrsmMC/qZe9glHkt2s9ytp1jL9XIfGqP5F0T8GqpJVmHB5VPFFAHXsGDpyop5XcayvL9Gkxn0s9xlpqEvgDaYfrEmg2ekhfGD X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(4636009)(136003)(346002)(376002)(396003)(39850400004)(46966006)(36840700001)(336012)(83380400001)(82310400003)(2616005)(2906002)(186003)(8936002)(6506007)(956004)(6916009)(16526019)(26005)(8676002)(86362001)(5660300002)(70586007)(36860700001)(70206006)(36756003)(478600001)(44832011)(6486002)(6666004)(6512007)(316002)(356005)(81166007)(69590400012)(47076005)(82740400003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Feb 2021 12:00:53.2923 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 44a70f57-1dcc-463e-070e-08d8d1a95847 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT052.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4902 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> From: Szabolcs Nagy via Libc-alpha <libc-alpha@sourceware.org> Reply-To: Szabolcs Nagy <szabolcs.nagy@arm.com> Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces@sourceware.org> |
Series |
Dynamic TLS related data race fixes
|
|
Commit Message
Szabolcs Nagy
Feb. 15, 2021, 11:59 a.m. UTC
From: Szabolcs Nagy <szabolcs dot nagy at arm dot com>
Since
commit a509eb117fac1d764b15eba64993f4bdb63d7f3c
Avoid late dlopen failure due to scope, TLS slotinfo updates [BZ #25112]
the generation counter update is not needed in the failure path.
---
elf/dl-tls.c | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
Comments
On 15/02/2021 08:59, Szabolcs Nagy via Libc-alpha wrote: > From: Szabolcs Nagy <szabolcs dot nagy at arm dot com> > > Since > > commit a509eb117fac1d764b15eba64993f4bdb63d7f3c > Avoid late dlopen failure due to scope, TLS slotinfo updates [BZ #25112] > > the generation counter update is not needed in the failure path. It is not clear to me from just the commit reference why it would be safe to remove the GL(dl_tls_generation) update on _dl_add_to_slotinfo. The dl_open_worker calls update_tls_slotinfo which in turn call might call _dl_add_to_slotinfo *after* the demarcation point. Will it terminate the process? > --- > elf/dl-tls.c | 11 +---------- > 1 file changed, 1 insertion(+), 10 deletions(-) > > diff --git a/elf/dl-tls.c b/elf/dl-tls.c > index 79b93ad91b..24d00c14ef 100644 > --- a/elf/dl-tls.c > +++ b/elf/dl-tls.c > @@ -998,16 +998,7 @@ _dl_add_to_slotinfo (struct link_map *l, bool do_add) > + TLS_SLOTINFO_SURPLUS * sizeof (struct dtv_slotinfo)); > if (listp == NULL) > { > - /* We ran out of memory. We will simply fail this > - call but don't undo anything we did so far. The > - application will crash or be terminated anyway very > - soon. */ > - > - /* We have to do this since some entries in the dtv > - slotinfo array might already point to this > - generation. */ > - ++GL(dl_tls_generation); > - > + /* We ran out of memory while resizing the dtv slotinfo list. */ > _dl_signal_error (ENOMEM, "dlopen", NULL, N_("\ > cannot create TLS data structures")); > } >
The 04/02/2021 17:50, Adhemerval Zanella via Libc-alpha wrote: > On 15/02/2021 08:59, Szabolcs Nagy via Libc-alpha wrote: > > From: Szabolcs Nagy <szabolcs dot nagy at arm dot com> > > > > Since > > > > commit a509eb117fac1d764b15eba64993f4bdb63d7f3c > > Avoid late dlopen failure due to scope, TLS slotinfo updates [BZ #25112] > > > > the generation counter update is not needed in the failure path. > > It is not clear to me from just the commit reference why it would > be safe to remove the GL(dl_tls_generation) update on > _dl_add_to_slotinfo. > > The dl_open_worker calls update_tls_slotinfo which in turn call > might call _dl_add_to_slotinfo *after* the demarcation point. Will > it terminate the process? in that commit the logic got changed such that allocations happen before the demarcation point in resize_tls_slotinfo. this is the reason for the do_add bool argument in _dl_add_to_slotinfo: it's called twice and the first call with do_add==false is only there to ensure everything is allocated before the demarcation point (so module loading can be reverted, no need to bump the generation count). i guess this is not visible by just looking at the _dl_add_to_slotinfo code. note that adding some asserts to ensure there is no allocation when do_add==true does not work: rtld uses the same api, but without the do_add==false preallocation step since at startup time allocation failure is fatal anyway. > > --- > > elf/dl-tls.c | 11 +---------- > > 1 file changed, 1 insertion(+), 10 deletions(-) > > > > diff --git a/elf/dl-tls.c b/elf/dl-tls.c > > index 79b93ad91b..24d00c14ef 100644 > > --- a/elf/dl-tls.c > > +++ b/elf/dl-tls.c > > @@ -998,16 +998,7 @@ _dl_add_to_slotinfo (struct link_map *l, bool do_add) > > + TLS_SLOTINFO_SURPLUS * sizeof (struct dtv_slotinfo)); > > if (listp == NULL) > > { > > - /* We ran out of memory. We will simply fail this > > - call but don't undo anything we did so far. The > > - application will crash or be terminated anyway very > > - soon. */ > > - > > - /* We have to do this since some entries in the dtv > > - slotinfo array might already point to this > > - generation. */ > > - ++GL(dl_tls_generation); > > - > > + /* We ran out of memory while resizing the dtv slotinfo list. */ > > _dl_signal_error (ENOMEM, "dlopen", NULL, N_("\ > > cannot create TLS data structures")); > > }
On 06/04/2021 12:48, Szabolcs Nagy wrote: > The 04/02/2021 17:50, Adhemerval Zanella via Libc-alpha wrote: >> On 15/02/2021 08:59, Szabolcs Nagy via Libc-alpha wrote: >>> From: Szabolcs Nagy <szabolcs dot nagy at arm dot com> >>> >>> Since >>> >>> commit a509eb117fac1d764b15eba64993f4bdb63d7f3c >>> Avoid late dlopen failure due to scope, TLS slotinfo updates [BZ #25112] >>> >>> the generation counter update is not needed in the failure path. >> >> It is not clear to me from just the commit reference why it would >> be safe to remove the GL(dl_tls_generation) update on >> _dl_add_to_slotinfo. >> >> The dl_open_worker calls update_tls_slotinfo which in turn call >> might call _dl_add_to_slotinfo *after* the demarcation point. Will >> it terminate the process? > > in that commit the logic got changed such that allocations > happen before the demarcation point in resize_tls_slotinfo. > > this is the reason for the do_add bool argument in > _dl_add_to_slotinfo: it's called twice and the first call > with do_add==false is only there to ensure everything is > allocated before the demarcation point (so module loading > can be reverted, no need to bump the generation count). > > i guess this is not visible by just looking at the > _dl_add_to_slotinfo code. Right, so if I reading correctly once _dl_add_to_slotinfo (..., true) is called by update_tls_slotinfo, the malloc that create a new dtv_slotinfo_list won't be called (since it was already allocated previously) since the entry was already pre-allocated and thus the search part at line 978-987 will find. Is that correct? > > note that adding some asserts to ensure there is no allocation > when do_add==true does not work: rtld uses the same api, but > without the do_add==false preallocation step since at startup > time allocation failure is fatal anyway. Right, the _dl_signal_error will trigger a fatal_error since lcatch won't be override yet. Thanks for the explanation. > >>> --- >>> elf/dl-tls.c | 11 +---------- >>> 1 file changed, 1 insertion(+), 10 deletions(-) >>> >>> diff --git a/elf/dl-tls.c b/elf/dl-tls.c >>> index 79b93ad91b..24d00c14ef 100644 >>> --- a/elf/dl-tls.c >>> +++ b/elf/dl-tls.c >>> @@ -998,16 +998,7 @@ _dl_add_to_slotinfo (struct link_map *l, bool do_add) >>> + TLS_SLOTINFO_SURPLUS * sizeof (struct dtv_slotinfo)); >>> if (listp == NULL) >>> { >>> - /* We ran out of memory. We will simply fail this >>> - call but don't undo anything we did so far. The >>> - application will crash or be terminated anyway very >>> - soon. */ >>> - >>> - /* We have to do this since some entries in the dtv >>> - slotinfo array might already point to this >>> - generation. */ >>> - ++GL(dl_tls_generation); >>> - >>> + /* We ran out of memory while resizing the dtv slotinfo list. */ >>> _dl_signal_error (ENOMEM, "dlopen", NULL, N_("\ >>> cannot create TLS data structures")); >>> }
The 04/06/2021 14:47, Adhemerval Zanella wrote: > On 06/04/2021 12:48, Szabolcs Nagy wrote: > > The 04/02/2021 17:50, Adhemerval Zanella via Libc-alpha wrote: > >> On 15/02/2021 08:59, Szabolcs Nagy via Libc-alpha wrote: > >>> From: Szabolcs Nagy <szabolcs dot nagy at arm dot com> > >>> > >>> Since > >>> > >>> commit a509eb117fac1d764b15eba64993f4bdb63d7f3c > >>> Avoid late dlopen failure due to scope, TLS slotinfo updates [BZ #25112] > >>> > >>> the generation counter update is not needed in the failure path. > >> > >> It is not clear to me from just the commit reference why it would > >> be safe to remove the GL(dl_tls_generation) update on > >> _dl_add_to_slotinfo. > >> > >> The dl_open_worker calls update_tls_slotinfo which in turn call > >> might call _dl_add_to_slotinfo *after* the demarcation point. Will > >> it terminate the process? > > > > in that commit the logic got changed such that allocations > > happen before the demarcation point in resize_tls_slotinfo. > > > > this is the reason for the do_add bool argument in > > _dl_add_to_slotinfo: it's called twice and the first call > > with do_add==false is only there to ensure everything is > > allocated before the demarcation point (so module loading > > can be reverted, no need to bump the generation count). > > > > i guess this is not visible by just looking at the > > _dl_add_to_slotinfo code. > > Right, so if I reading correctly once _dl_add_to_slotinfo (..., true) > is called by update_tls_slotinfo, the malloc that create a new > dtv_slotinfo_list won't be called (since it was already allocated > previously) since the entry was already pre-allocated and thus the > search part at line 978-987 will find. Is that correct? yes if you have an idea how to make things clearer let me know. > > > > note that adding some asserts to ensure there is no allocation > > when do_add==true does not work: rtld uses the same api, but > > without the do_add==false preallocation step since at startup > > time allocation failure is fatal anyway. > > Right, the _dl_signal_error will trigger a fatal_error since > lcatch won't be override yet. > > Thanks for the explanation. > > > > >>> --- > >>> elf/dl-tls.c | 11 +---------- > >>> 1 file changed, 1 insertion(+), 10 deletions(-) > >>> > >>> diff --git a/elf/dl-tls.c b/elf/dl-tls.c > >>> index 79b93ad91b..24d00c14ef 100644 > >>> --- a/elf/dl-tls.c > >>> +++ b/elf/dl-tls.c > >>> @@ -998,16 +998,7 @@ _dl_add_to_slotinfo (struct link_map *l, bool do_add) > >>> + TLS_SLOTINFO_SURPLUS * sizeof (struct dtv_slotinfo)); > >>> if (listp == NULL) > >>> { > >>> - /* We ran out of memory. We will simply fail this > >>> - call but don't undo anything we did so far. The > >>> - application will crash or be terminated anyway very > >>> - soon. */ > >>> - > >>> - /* We have to do this since some entries in the dtv > >>> - slotinfo array might already point to this > >>> - generation. */ > >>> - ++GL(dl_tls_generation); > >>> - > >>> + /* We ran out of memory while resizing the dtv slotinfo list. */ > >>> _dl_signal_error (ENOMEM, "dlopen", NULL, N_("\ > >>> cannot create TLS data structures")); > >>> } --
On 07/04/2021 04:57, Szabolcs Nagy wrote: > The 04/06/2021 14:47, Adhemerval Zanella wrote: >> On 06/04/2021 12:48, Szabolcs Nagy wrote: >>> The 04/02/2021 17:50, Adhemerval Zanella via Libc-alpha wrote: >>>> On 15/02/2021 08:59, Szabolcs Nagy via Libc-alpha wrote: >>>>> From: Szabolcs Nagy <szabolcs dot nagy at arm dot com> >>>>> >>>>> Since >>>>> >>>>> commit a509eb117fac1d764b15eba64993f4bdb63d7f3c >>>>> Avoid late dlopen failure due to scope, TLS slotinfo updates [BZ #25112] >>>>> >>>>> the generation counter update is not needed in the failure path. >>>> >>>> It is not clear to me from just the commit reference why it would >>>> be safe to remove the GL(dl_tls_generation) update on >>>> _dl_add_to_slotinfo. >>>> >>>> The dl_open_worker calls update_tls_slotinfo which in turn call >>>> might call _dl_add_to_slotinfo *after* the demarcation point. Will >>>> it terminate the process? >>> >>> in that commit the logic got changed such that allocations >>> happen before the demarcation point in resize_tls_slotinfo. >>> >>> this is the reason for the do_add bool argument in >>> _dl_add_to_slotinfo: it's called twice and the first call >>> with do_add==false is only there to ensure everything is >>> allocated before the demarcation point (so module loading >>> can be reverted, no need to bump the generation count). >>> >>> i guess this is not visible by just looking at the >>> _dl_add_to_slotinfo code. >> >> Right, so if I reading correctly once _dl_add_to_slotinfo (..., true) >> is called by update_tls_slotinfo, the malloc that create a new >> dtv_slotinfo_list won't be called (since it was already allocated >> previously) since the entry was already pre-allocated and thus the >> search part at line 978-987 will find. Is that correct? > > yes > > if you have an idea how to make things clearer let me know. > Maybe add it on the commit list. The patch looks ok to me thanks.
diff --git a/elf/dl-tls.c b/elf/dl-tls.c index 79b93ad91b..24d00c14ef 100644 --- a/elf/dl-tls.c +++ b/elf/dl-tls.c @@ -998,16 +998,7 @@ _dl_add_to_slotinfo (struct link_map *l, bool do_add) + TLS_SLOTINFO_SURPLUS * sizeof (struct dtv_slotinfo)); if (listp == NULL) { - /* We ran out of memory. We will simply fail this - call but don't undo anything we did so far. The - application will crash or be terminated anyway very - soon. */ - - /* We have to do this since some entries in the dtv - slotinfo array might already point to this - generation. */ - ++GL(dl_tls_generation); - + /* We ran out of memory while resizing the dtv slotinfo list. */ _dl_signal_error (ENOMEM, "dlopen", NULL, N_("\ cannot create TLS data structures")); }