From patchwork Mon Feb 15 11:56:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 42029 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 E76463950424; Mon, 15 Feb 2021 11:56:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E76463950424 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1613390190; bh=TbYJIy+BWxuRR30xiVjRMvbei5b4KivXhjwKmLqpcnU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=bHY3js4ckekSwLbvwdVaJi+3jaIKEX99bV1HjlTBa5AvmRWCwt7DT4vc6VsularZB uPcIDSJOtWoYtCJ4OZMgdnQTugeNE/to5j57KcK0NAiNcDfPSyo7biiV4Cusv8DpWk dsd6NzWE691kdygJjIHl9n+73Xe6stpMmEv95DHA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2083.outbound.protection.outlook.com [40.107.20.83]) by sourceware.org (Postfix) with ESMTPS id 197D3394D8B0 for ; Mon, 15 Feb 2021 11:56:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 197D3394D8B0 Received: from AM5PR1001CA0066.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:206:15::43) by AM9PR08MB6228.eurprd08.prod.outlook.com (2603:10a6:20b:281::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.25; Mon, 15 Feb 2021 11:56:24 +0000 Received: from VE1EUR03FT061.eop-EUR03.prod.protection.outlook.com (2603:10a6:206:15:cafe::29) by AM5PR1001CA0066.outlook.office365.com (2603:10a6:206:15::43) 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 11:56:24 +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 VE1EUR03FT061.mail.protection.outlook.com (10.152.19.220) 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 11:56:24 +0000 Received: ("Tessian outbound 4d8113405d55:v71"); Mon, 15 Feb 2021 11:56:23 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: afae7add203d5cbd X-CR-MTA-TID: 64aa7808 Received: from b754cab5da99.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id F31EC101-46B7-4D8D-B7B9-6533A6BEF859.1; Mon, 15 Feb 2021 11:56:17 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b754cab5da99.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 15 Feb 2021 11:56:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LxQAfhM4h/FPsByrVMIFUPqK4FnV22KF6qxrlzFR67WlzuEsaek1PvEN0S/65EXkQ1U6iSBoaiUbommZC6Z8vGOb/dDUvlPyHPc9g9qVQpOtlI9YJ2s4efL5q7YcmuYvEOMZKlsm84TevkEKzDqMpW0SwGs5ACNdyied4lEaexR48pfEWRrjGlRvHU4DlEtKL2xQgzUGtcWyKiAkb1MoMp1iCFXWyjDW2I6G67NvCOweqvvgci+UkFtHrBk54Lkx1Lv5w9at0ZbS3/1zbp6JE/o4JgTxw7XLzECkv+Mzyh9dL+s3tlVCm8YkNJ9ykvQJudL2J7XVlYbQNiDsInHBkA== 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=TbYJIy+BWxuRR30xiVjRMvbei5b4KivXhjwKmLqpcnU=; b=OpDKeYRNOPTovGtqL0kapg2vPSYMPt4wKLUx3iSVkhCQjfAEJdG7htyU0jhbvfppIhh6yjpBV0ivvCmblsAS6SfXQ4WLv5cKXOwLfHg38HVXzBsb+PBqFD5phQrQthYbOjhsGNsG0McpQ220m1tiDzxQfvJ7NAknqHLj/TaWgj+koKXfOsRUt/EX4MFvly3aXu+aKjpjAMNPUbwItlxHoCFnoVcbqDqf2Pd2tDWHMBhbtIDKnXQZLFmDjKkOj6TuyJuly4tqtD0cZHTvmfN55voCQQAGwiKNVB6VChbujtNNaMJx23Hlg2TIAI6jRFwa6A00tqh3G61B6JXhQsDR+Q== 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 PAXPR08MB6432.eurprd08.prod.outlook.com (2603:10a6:102:154::12) 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 11:56:16 +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 11:56:16 +0000 To: libc-alpha@sourceware.org Subject: [PATCH 00/15] Dynamic TLS related data race fixes Date: Mon, 15 Feb 2021 11:56:07 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 X-Originating-IP: [217.140.106.49] X-ClientProxiedBy: LO4P123CA0391.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18f::18) 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 LO4P123CA0391.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18f::18) 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 11:56:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 2f0d4dc7-395d-4c3f-6498-08d8d1a8b7e1 X-MS-TrafficTypeDiagnostic: PAXPR08MB6432:|AM9PR08MB6228: 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: CAuipfWjaPbzQpg/lVSqO1fTt3iUaaIKqwMXXDk1JZe93YFm3GeYbJHcEssHGSPHryT0TMebydjc6DvlFTf62daXGvNbcIp0AyE0KkJzzkqAD/E7sB9rofvnmrhSBCMdi+etLJ9V2QxkwOhWez7+ouoEOU3gJwM4xnkN68qI7H6U88123xnL0jQa5d03Qdu9hbLuMyYCd/7Q/UM4x+c8bmDlrVLVUU4dmyh1ISpnqwmtwtVtaDdSe9xWlErocDKfp6m7BtMrq6besZubpE0Q1n1cBV1UcgK6mU+o+Op+iPhL9XmSOKbfo5VdGb7RcQHxtPKaOWV4ZNTdi9OQsczPVRmXGUifd7HgLojdYM6b+dmigz2tRAp7WSS6JafarGGJoZooHdsCw/PSz8xpyMCoS/S/rwOA8v5b/MoBp6BCxlVn6YEFqsNLvtbTCpGBH0+9Xp2IXv1bnIvgKRek/aWuwm3rMhOr47SnB2Bwtr/f6v6gDfSVFAhIP/t3LicA9jWstCmbEgIZQcckSg4AVunHdRKOWiPaFzm3SwDbsZL+vUCkvN/64jYW/ZI5kQHV0xNkRPAECrnAwTPxEOIs6iM1ZNu7shE5KnbMjCLoh2R5iItc4xFvj4BcU44MdmS4EkVJVP471waATEdWhj51wGr0p9Jh94IDQ5Wyu/OZ8W7i+H0= 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)(376002)(39840400004)(136003)(346002)(366004)(69590400012)(83380400001)(6512007)(6916009)(66946007)(66476007)(316002)(66556008)(966005)(186003)(52116002)(86362001)(8936002)(36756003)(6486002)(5660300002)(478600001)(26005)(6506007)(956004)(6666004)(16526019)(2616005)(8676002)(2906002)(44832011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: wnDnpRv+xC3qKdej4KJbMbts7EvrTPKMrrafINGtmvlpvnFA192oS0Wly7GFNdICXv8dhD4nHyLv/LXnTHLjH2O1Ed11/rRVckFzMMSyBGKqGGEHNczDQAHWPSoUAe8TQGZbxXo264l8VDwxSKLrC90dB7lXHW/j5ORWKyLHvvEaNurzz2XXUvGAWZT2k2xtBBrhsoG9y3H9d2NImo3+DFZWLHFzRvWHLkksuXdLQ+VLKOa5YHmlTtp0Rln0qH+yfMwyh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Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6432 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: VE1EUR03FT061.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: cd4060c0-ed70-4579-82bd-08d8d1a8b302 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0s2nfkI1+nQ4dy7iqX5EBTb/dhYXYcthlDSR4+iEaCjfDTqcVK1uZEcbceQVvyhFYEv644vYHTSSz2vw/FMRA/Mdk7/nVrR2Zs72NexNJCibCvq8abWnprYRDGu52DZfZKyTScCRylaGBsMFAb/FriqfzgS6g0JHe5TvNab9f4ZAEwHcvjeiZx8QxEs7aVUT4EskLs+67ktLcj0kMOnOPpPgRyccromckj5Tn8yIAK7S7Z1DOZE17CzMvfhWgJSKxk9zPKZ2La/ddZRbFqGbMw4bkHzoEV2kS1vYo8kGDE+8Rc2JN4w3i380tjLSrdNw0CUM+mLCZyPZDfJe04nn7N0R8Pi2JLBZUFBmny7R1dbIAatv9s+lWqYz97p9LOASghNqkLbTf6Qbrk0bcZi/Fu7+YWbGUdtZcAfy9Dgvlz3iNX+F/0Z8n6zML6gD0vJgqElw8HDtromuc5sN4F1tkhJXtEaQ2CW5JXVuGju3GGZIWV/37A2+kdAtl18GqwAQSJ8NPjhRPaM9DzG3zqbhirkPs0bVdtUCrl2kw9XqeJGbjGtc0LK3hbT6IZJwOP79iI9CX6jTNlO37VG2sNWfKhDCAK+m1gbEAOBst8V6AeoanCtr61qE9aMFseLHE31EW+Lre0d0faOPJy5XT8RJuqJoNzcuPiopRGXKt16+x0uR7v6wGjdXL+7na3LvTMgagV3saOEspaDbVuI2IH/49K5tPUfqMo4zXTnrPqNDVJ1kPzRz/kHRO6O0GK5dHh0tpDDlQ88dygnu1kAhFu4msQ== 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)(39840400004)(136003)(376002)(396003)(346002)(46966006)(36840700001)(356005)(47076005)(956004)(81166007)(36860700001)(36756003)(44832011)(5660300002)(2616005)(8936002)(966005)(8676002)(82310400003)(6666004)(478600001)(83380400001)(6486002)(6512007)(2906002)(336012)(70586007)(70206006)(316002)(6506007)(16526019)(186003)(69590400012)(86362001)(26005)(6916009); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Feb 2021 11:56:24.1308 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2f0d4dc7-395d-4c3f-6498-08d8d1a8b7e1 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: VE1EUR03FT061.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB6228 X-Spam-Status: No, score=-7.9 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 21349 - a lazy symbol binding race (not related to TLS) 27137 - lazy tlsdesc relocation on x86 is racy and there were a number of minor issues uncovered: 27135 - dtv gaps are not reused 27136 - dtv off-by-1 error, 27403 - aarch64 memleak on dlclose 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 branch. There are new test cases that are early in the series for now so they can be run before the fixes. 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. An earlier analysis about bug 19329 https://sourceware.org/pipermail/libc-alpha/2020-December/121090.html In some cases atomics is used for synchronization, this means all accesses to that object has to be atomic even if that's behind a lock. I think this is unnecessary and can be confusing: https://sourceware.org/pipermail/libc-alpha/2020-December/121200.html This patchset does not try to turn non-racy read into relaxed atomic read. The removal of lazy tlsdesc relocation may allow further changes at the end. The x86 changes were not excessively tested. I ran the glibc tests on x86_64, i386 and aarch64 linux. Maninder Singh (1): elf: Fix data race in _dl_name_match_p [BZ #21349] Szabolcs Nagy (14): aarch64: free tlsdesc data on dlclose [BZ #27403] Add test case for [BZ #19329] Add a DTV setup test [BZ #27136] elf: Fix a DTV setup issue [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: 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 elf/dl-close.c | 26 ++-- elf/dl-load.c | 18 ++- elf/dl-misc.c | 4 +- elf/dl-open.c | 15 +-- elf/dl-tls.c | 133 +++++++++++-------- elf/tlsdeschtab.h | 53 +------- nptl/Makefile | 25 +++- nptl/tst-tls7.c | 69 ++++++++++ nptl/tst-tls7mod-dep.c | 1 + nptl/tst-tls7mod.c | 1 + nptl/tst-tls8.c | 96 ++++++++++++++ nptl/tst-tls8mod-bad.c | 2 + sysdeps/aarch64/dl-lookupcfg.h | 27 ++++ sysdeps/aarch64/tlsdesc.c | 1 - sysdeps/arm/tlsdesc.c | 1 - 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 | 19 ++- sysdeps/x86_64/dl-tlsdesc.S | 104 --------------- sysdeps/x86_64/dl-tlsdesc.h | 4 +- sysdeps/x86_64/tlsdesc.c | 108 ---------------- 23 files changed, 393 insertions(+), 782 deletions(-) create mode 100644 nptl/tst-tls7.c create mode 100644 nptl/tst-tls7mod-dep.c create mode 100644 nptl/tst-tls7mod.c create mode 100644 nptl/tst-tls8.c create mode 100644 nptl/tst-tls8mod-bad.c create mode 100644 sysdeps/aarch64/dl-lookupcfg.h