From patchwork Tue Apr 13 08:17:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 42961 Return-Path: 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 29F4D393C858; Tue, 13 Apr 2021 08:18:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 29F4D393C858 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1618301886; bh=3NKy1NqtwUUQS1bMOUk2ZkZ87Ndp35gcJ2dyhhw3SeA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=IahVw7WbvC6OfS6evevwhWAyH3tuuv6KK5VCbrOeVtYwcwxPSk4hFX41xHUzjlPz8 kH6SyCO5ygXTvJ2KZodAoQN0ZnskVKwP8HtWD3qDglY2Jj4OMC9m//6Pn+B0H96ilF xL2Sm4JpE40l7FaIHtjAgW3DXTUK7k/sVvpivhrc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60044.outbound.protection.outlook.com [40.107.6.44]) by sourceware.org (Postfix) with ESMTPS id 0FA76393C854 for ; Tue, 13 Apr 2021 08:18:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0FA76393C854 Received: from AM6PR05CA0015.eurprd05.prod.outlook.com (2603:10a6:20b:2e::28) by PAXPR08MB6448.eurprd08.prod.outlook.com (2603:10a6:102:152::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Tue, 13 Apr 2021 08:18:00 +0000 Received: from VE1EUR03FT014.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:2e:cafe::4b) by AM6PR05CA0015.outlook.office365.com (2603:10a6:20b:2e::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:18:00 +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 VE1EUR03FT014.mail.protection.outlook.com (10.152.19.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Tue, 13 Apr 2021 08:18:00 +0000 Received: ("Tessian outbound 47ca92dabae7:v90"); Tue, 13 Apr 2021 08:17:59 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 8646a7a4ba0f23c6 X-CR-MTA-TID: 64aa7808 Received: from c6f85eaf9dd2.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 9A113A85-8E73-4A72-AA39-2C4002A36C70.1; Tue, 13 Apr 2021 08:17:52 +0000 Received: from FRA01-MR2-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id c6f85eaf9dd2.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 13 Apr 2021 08:17:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dgJ9wT1qYgysn+B8Yyt0XuVrp2T9BzEZhLNbUYVzfclUUngsVSJFTnqOvz1iKQjnB/xb+6sy1iQZLytWEpb48hrR2YNjCGiq01z0vWbhPn5dYna1RyxwoZ7rygu0c9lALGH9iShMhEG3uL4/hNqMOXKLT0ybbHQEth6Ow2aONai2QsztwI3/ZlwImQ5jqdGybtoUoNmI3SSB4tbHHiS9PcuprHG1EjW7HqcU/0gp/ws3XE9WOweB7oxjU+lPxoMiCmClUTB4uXPb8O4hvw4FHb6RKnig2nHJx+xhk8MVwQIPW0eBOrs9ddWAKfV5qeGgTls6bbB/PN7a+U2pgdzaXA== 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=3NKy1NqtwUUQS1bMOUk2ZkZ87Ndp35gcJ2dyhhw3SeA=; b=WGYzM+yqtl5hHr6GyihQKCq8MxytpPq7/QbxIM3ELRrm8hSR3DoWXmq3/YT8XefdXNfmW+RKW05hIrRM+QVT6wRHYiCLZBSuEEb9bKdyge1UxbI6bB4Ii8wXdKrWgooiwa8CTlCRYVpFUwlDuBCURMa9YsFNGqd8+fd7jPbKkIPKDwYLeMVJnTof7Utn3OuRUEOl/Ej/8F+t6PVBSRDWaBSmyDyVNDTP+LSd9vhyS5aB7eDIl5VqnAh3d6J0NpG0UskgcSGRT/LKuO5f1Z+N0sJg/EbnUmsc+D9QoW6JT8hWq7J1TtOXueVLm2xmThI/DRHLdG7QQj2CcSly7+9ZIQ== 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 PR2PR08MB4778.eurprd08.prod.outlook.com (2603:10a6:101:21::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.22; Tue, 13 Apr 2021 08:17:49 +0000 Received: from PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b]) by PA4PR08MB6320.eurprd08.prod.outlook.com ([fe80::c99f:671d:bb2c:f20b%7]) with mapi id 15.20.4020.022; Tue, 13 Apr 2021 08:17:49 +0000 To: libc-alpha@sourceware.org Subject: [PATCH v2 00/14] Dynamic TLS related data race fixes Date: Tue, 13 Apr 2021 09:17:42 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 X-Originating-IP: [217.140.106.55] X-ClientProxiedBy: LO2P123CA0048.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600::36) 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.55) by LO2P123CA0048.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.22 via Frontend Transport; Tue, 13 Apr 2021 08:17:48 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 857e487e-8052-4f7a-910b-08d8fe54a6df X-MS-TrafficTypeDiagnostic: PR2PR08MB4778:|PAXPR08MB6448: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: yWoORfqF5S3e7lNRl6G+DpJ0GXH/lcEmlBX5sFD/ogy9zksuhonHFJjQ+hyRQQvSLy+ELOjRRYlJkKYa0im2a8+SBiwgZsCAjHJrcyNdyFagO5bH+GF1N6IMdVWhuTSLNhqeAxijsUeuoOKHqhaUjEV4GITUbNgsFavksZa5WDDJ/UWZ7h4BGvj9LHla3WNu6EWD55FH/tyYxWBfNC9tL0aCUxmQO5XnEZ1afngFQlVvmX0VY6REZC1QooEFQKwZZNKmTuKBxUyNyhQYY53XKNQesozsri+AXzwqFEwcrrt7F8h+vj4VeG6VAAAPTRb3vQraq1VSPkkdSFx2G1vyJKO0tnqpZ4XioAjoQ4i6i8QNIWymedF7tPGN4jES85d/NzvkVDS/rg2I/oRs11wxoGP1OOzwqUbykR6lkk5ePXmNSFLvFPvthgLDMBltp5NQem7MzY9JSm5rwvRpwPFQfGSvPkWZXl9B90RvQYsJ7MFJ3s+pxWwspFERG/rtcNwn9TdGSIEoqZvbGlVcPZgh2QtvYTOzk0pikTLmO4dYeeIAk6Eo3urbl9qem9N7CxlB6PqH8lAQSqpgCrN/dSdxI3C8rQmL7YTeHqf29nVQSPY3z292vUFl/S8M7dVVfHoYsJUpLLW21ZEgd7DzC3ES/60l9bel+RaOtIHmVD31AZZVCuYJgeeu3T5Kp1degUPV 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)(39860400002)(396003)(366004)(346002)(376002)(136003)(38350700002)(6916009)(26005)(38100700002)(83380400001)(2906002)(8936002)(5660300002)(8676002)(186003)(66946007)(66556008)(66476007)(6506007)(86362001)(36756003)(52116002)(6666004)(2616005)(956004)(44832011)(316002)(6512007)(69590400012)(478600001)(16526019)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: B0+tEetqgoGiXrAjI4HvvgnhWzhJjPK042k+OvlPzFHHkOg1rYMghs0gWXmEY/Tr8KBCg9mN1beCeLBtW99eLpkhDbpNGBoCvVJ+fvBZqatJeUt40tlFwg0Od1vacPtmDWmitS9FJ9n75vTOnJm6V+1iA1NjcRWGpV+JFsSaJuM4G4aiP6TGiqbh8Xi250A1jyMl73LcinQPo43Qsh82MOkyogVs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aQGbGey+VTmyVBH/dBu02yTe0dQnIWWYY1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR2PR08MB4778 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: VE1EUR03FT014.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 06ab07cb-5a64-4f2b-3f2c-08d8fe54a012 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NqgrFCs+jNUu98d3Q6K7pxVWBTByXQ2XCGzZ3W/IBw58O8BUnS8UcjZyL3291AvLPDMAXXrFy0+5hEV79jojX4zDsiJ5+GEWdFJXshJd+vIIHZoYnpr7S1avMgBQImYw9dzK7XvJQRnkl/0ETCeIPsb9clVbk2/O4OVRGqdiJ6b1uQ+jYl5/xwfHyNm8a+BEDp3uLuP9YPLxSgxmhfWUwh9zRUpuYRIzb94sz+QY5qwdfVg5ER9oPPPG0ATuyqb90TKbcHtfrrCjO3dsCvv2jcQkmyFdsmZgydSz6SmUCw29BZtS3uJNkd/EKXaVCFiyqUuDykGv8AQOMsQmY06+b3U7MxJDZF69Vcs1gL2dAxIzfVxU2SiOBwGpkoLB1BN9SkqnVq1dQtH5/ShpPU8rbiVkrfY+U/TUlnJZlstMylP0ueCe/Chw/G5qR9tOaKr8U8pZc1E7y0Z/eaokwG34huUB8lMfcFBJwPBnovHaA2hD4ULL3xmGqopU1uY56di+0w4qxKkyHlZdzK7jzklgg+9tMGT5dApLKsOALmAF4N8DINjZVTftF3jSslqO/qkfBj5qpMerULJZMnE/jheUOLe+nzA07lz4LG0LkdHdZgXaafSXbHYqX9w8cxR7yt7gQFoxJCMaGJdSJ8c13PWV3WdXO40ahGorK/+J9o29uLEG83d1k07kXZskRLut5GJR 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)(376002)(39860400002)(346002)(136003)(396003)(36840700001)(46966006)(36756003)(356005)(316002)(70206006)(81166007)(2616005)(6916009)(8936002)(82310400003)(6486002)(8676002)(6666004)(186003)(478600001)(956004)(44832011)(83380400001)(16526019)(70586007)(36860700001)(6512007)(86362001)(69590400012)(336012)(47076005)(26005)(5660300002)(82740400003)(6506007)(2906002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Apr 2021 08:18:00.2013 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 857e487e-8052-4f7a-910b-08d8fe54a6df 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: VE1EUR03FT014.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6448 X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Szabolcs Nagy via Libc-alpha From: Szabolcs Nagy Reply-To: Szabolcs Nagy Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" This series is trying to address some long standing dynamic linker races: 19329 - race between tls access, pthread_create and dlopen 27111 - race between tls access, pthread_create and dlclose 27137 - x86: lazy tlsdesc relocation is racy and there are a number of related issues fixed: 27135 - dtv gaps are not reused 27136 - dtv off-by-1 error 19924 - slow tls access after dlopen 27721 - x86: ld audit does not work with bind now tlsdesc there are related issues that are not fixed, but tried to not make the situation worse: 16133 - tls access is not as-safe 16134 - tls allocation aborts on oom 27112 - generation count may overflow on 32 bit targets some of the patches can be handled independently. The set is also available in the nsz/bug19329-v2 branch. A common theme between the races is that the GL(dl_load_lock) lock protects various dynamic linker shared global state that are written under that lock, but in various situations (lazy binding, tls access, thread creation) they are read without the lock. There seems to be consensus to not require relaxed atomic loads for non-racy reads of objects that may be accessed atomically elsewhere. The wiki with the concurrency rules have not been updated yet. In this patch relaxed atomics is used if an access is racy but synchronization is only missing when that is not relied on (e.g. tls access must be synchronized with dlopen by the user so unsynchronized dtv updates are not relied on). I ran the glibc tests on x86_64, i386 and aarch64 linux (but this may not cover the x86 tlsdesc changes completely). v2: - committed the fix for bug 27403 (arch64 memleak on dlclose) - committed the fix for bug 21349 (a lazy symbol binding race) - added an RFC fix for bug 19924 (slow tls after dlopen) - reordered test patches after bug fixes. - addressed previous review comments (see individual patches). Szabolcs Nagy (14): elf: Fix a DTV setup issue [BZ #27136] elf: Add a DTV setup test [BZ #27136] elf: Fix comments and logic in _dl_add_to_slotinfo elf: Refactor _dl_update_slotinfo to avoid use after free elf: Fix data races in pthread_create and TLS access [BZ #19329] elf: Use relaxed atomics for racy accesses [BZ #19329] elf: Add test case for [BZ #19329] elf: Fix DTV gap reuse logic [BZ #27135] x86_64: Avoid lazy relocation of tlsdesc [BZ #27137] i386: Avoid lazy relocation of tlsdesc [BZ #27137] x86_64: Remove lazy tlsdesc relocation related code i386: Remove lazy tlsdesc relocation related code elf: Remove lazy tlsdesc relocation related code RFC elf: Fix slow tls access after dlopen [BZ #19924] elf/Makefile | 15 ++- elf/dl-close.c | 26 ++-- elf/dl-open.c | 21 ++-- elf/dl-reloc.c | 5 +- elf/dl-tls.c | 161 ++++++++++++++----------- elf/tlsdeschtab.h | 53 +-------- elf/tst-tls20.c | 98 +++++++++++++++ elf/tst-tls20mod-bad.c | 2 + elf/tst-tls21.c | 68 +++++++++++ elf/tst-tls21mod.c | 1 + sysdeps/aarch64/tlsdesc.c | 1 - sysdeps/arm/tlsdesc.c | 1 - sysdeps/generic/ldsodefs.h | 3 +- sysdeps/i386/dl-machine.h | 76 ++++++------ sysdeps/i386/dl-tlsdesc.S | 156 ------------------------ sysdeps/i386/dl-tlsdesc.h | 6 +- sysdeps/i386/tlsdesc.c | 230 ------------------------------------ sysdeps/x86_64/dl-machine.h | 23 ++-- sysdeps/x86_64/dl-tls.c | 5 +- sysdeps/x86_64/dl-tlsdesc.S | 104 ---------------- sysdeps/x86_64/dl-tlsdesc.h | 4 +- sysdeps/x86_64/tlsdesc.c | 108 ----------------- 22 files changed, 361 insertions(+), 806 deletions(-) create mode 100644 elf/tst-tls20.c create mode 100644 elf/tst-tls20mod-bad.c create mode 100644 elf/tst-tls21.c create mode 100644 elf/tst-tls21mod.c