From patchwork Thu Nov 30 08:11:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 81001 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com 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 6314C3858281 for ; Thu, 30 Nov 2023 08:11:57 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2061.outbound.protection.outlook.com [40.107.247.61]) by sourceware.org (Postfix) with ESMTPS id A8C693858C66 for ; Thu, 30 Nov 2023 08:11:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A8C693858C66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A8C693858C66 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.247.61 ARC-Seal: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1701331898; cv=pass; b=BSOX6T8vtjT6abyY2zUhQpEbMXlKrFicAk38MOg41Vhn4WaiRILYeAmxgfkJNzn7ytZZXEjspcvmMijCKTb16UbnWJ1MeW5MPffepkoK/OwsK8XqPK/SjiGwl1YKpGX3ChN4rglX/+Zo0X55WPFWcgEEQZ7dYkf03MDMPPSPCWc= ARC-Message-Signature: i=3; a=rsa-sha256; d=sourceware.org; s=key; t=1701331898; c=relaxed/simple; bh=hElT1ClFSqJszWSxiejo1himE+zzlrTQkTvg9rV3GzM=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=Eu65X9tI/eiIbRUS7MNwC4pOf2k9pjFlwYp/Ov7bbNCbCv8nFoXwur6JuTnoHnKELL4J+RSG9iipH4vo396Lwmi9ujcvypanxMjeL5Jkdb7MUQEcMgPNmO+/5NcqDD2PFon3omxyq/n2zMSpfHnchWgNNdV5lNTeiJH8ksxqmj8= ARC-Authentication-Results: i=3; server2.sourceware.org ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=FODgNzjAnQVOTDF6dYlftjGGOhZN2jH6e4Rftl8UeR2BFb9SMDioQiK3SjyuM3l2hbgv1rWCbE/Dkto3VVAZNBxDvAmeG+e1ZCanl1rBRLz54anTzBTJeTWz8nY7jIj8aSFOWY2GBD0Et7rgD3JBdacDm/LlASGKHtHkDjilX2426m3rz/OAoUPwdze7bt4slNJgqIDlsgUUw5xmxGdp0BIsTFAaRYO2Vv06nXKdJpaJkN/oqE4ET6LLlRgFrOEyuBAFRbvMzDnZsEUVEF+yOld7vdEfwxiNA+8TE8Kz9arhoDJylxKzVQUWxwk16slo9g45YIjDs7uB382OzGjDgA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=eboqaWJO6Qua1H8nBD335ACe/RIQRRFR4pyIY77jt6U=; b=gtt12JDg5zeZTv5WZKStTDNm1tKUnVTz99K5aT4k9gN5R342k1HxTYVCZ1/qzRKRdEOf9dAHtzQ5s8wh1FarrKzM+uKDiqVnI0qlisbTLLSCZfS5x8/DaFeLL8x3E89MqRbVaAcTUy8/I3+xbNL32Oqf1+f02c0tltGepmYDEpNPSbKCgiIPI5mgNAEZPVTbUBlkSXmvWGZdstnMHqr3CzYUfKR0hFExYvBtBf5QblKyggYDH+ockEkVQGmPcGsZxC5u+ZcJTVo2Uflw1pd1BqgxS+H9awFnoTNU9BGdsTcoz+znmRAP4K0mxWvaa4+sfWAp1zrvRv1+TD4zxwWXdw== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1, 1, smtp.mailfrom=arm.com] dmarc=[1, 1, header.from=arm.com]) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eboqaWJO6Qua1H8nBD335ACe/RIQRRFR4pyIY77jt6U=; b=2cCQUlLHTsQu1kiHkzPSeBJLJQnGcFCRxVoM5/91FYQtiwZgKJFJh/ksb8+EFrLW9LNxec7Uhj1Du/ZQjleXb5qhdOg3y9COgY61qtP/y5rzDRV6TrXsDilAjvDC2O1VVEx5MsyJmsS6kNhRVcH2XFeKEE0j6vzqm2bMl1pjyVY= Received: from DB9PR06CA0021.eurprd06.prod.outlook.com (2603:10a6:10:1db::26) by DB9PR08MB6345.eurprd08.prod.outlook.com (2603:10a6:10:252::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.22; Thu, 30 Nov 2023 08:11:31 +0000 Received: from DB1PEPF00039232.eurprd03.prod.outlook.com (2603:10a6:10:1db:cafe::3c) by DB9PR06CA0021.outlook.office365.com (2603:10a6:10:1db::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.22 via Frontend Transport; Thu, 30 Nov 2023 08:11:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;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; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB1PEPF00039232.mail.protection.outlook.com (10.167.8.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.17 via Frontend Transport; Thu, 30 Nov 2023 08:11:31 +0000 Received: ("Tessian outbound 8289ea11ec17:v228"); Thu, 30 Nov 2023 08:11:31 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: d872d0851db0b50e X-CR-MTA-TID: 64aa7808 Received: from c7962ecce92f.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 014FD1CD-1D06-4C46-BE1E-EC1704B7E638.1; Thu, 30 Nov 2023 08:11:24 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id c7962ecce92f.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 30 Nov 2023 08:11:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mKD1gZCAgxFaTMbqnQRgHuqVvM0xiI0QFmEi94OsI8aue+lQErRdBDd1mquJ4lrAPU7q0jWXTzUGROjk+fBjNEIYsF7UPYyqZMnjdUi21Wk6pvUWwgzohVvnpkguZLHK4Iwfzl4Mn3zFeQRV4a2VqCx+VnEkIfk5cTSl8KhyeTxiNRZcVycaIMiFteSldJ6HHT8U3A7GyyJOFZWBMQLPoidBDBpvJVEF4JXJPFq5V0UhOf7U2a5PnU0EZhFdUa3aHZUiX7BtuvIcgR4X7/PAG3tu46gx4m1jcUdSyphIoDCFADmuqQSFHM5zp790DXYJiBw1DdIgcfWhOPGLBcD7fA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=eboqaWJO6Qua1H8nBD335ACe/RIQRRFR4pyIY77jt6U=; b=KdtQqPQXSvvER6OBQ5PpAcb5z5MLdybygJwyViR5S3Wanw5I/O8iA39whGDeGzXZ0DscQCx9QLJUqsWfjwhv6iI2y8gg57MjMIJ00Cu1bvX8bdE7ge7d8vEVVFuchhP0CqN6s45z+a2Koy4aYnXtvdfhq8Oqrdp/sIg2M38YM6FyzE2/dK+3MwFnWi/iL5tiGM6Y6HMKJhcYS6GesC4Ay5uHIoHQCHaZwXTflHzVu0kuU/6h3fpoMS5VnNH77WYaAXmxpQl/OB4KFQ2xdfgpZVxsTCIRpZImQ342/BeNfdCwcAFQHEDfhBpigvS2gsVDi7SBKwk0dIY/oFqTlAeKcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eboqaWJO6Qua1H8nBD335ACe/RIQRRFR4pyIY77jt6U=; b=2cCQUlLHTsQu1kiHkzPSeBJLJQnGcFCRxVoM5/91FYQtiwZgKJFJh/ksb8+EFrLW9LNxec7Uhj1Du/ZQjleXb5qhdOg3y9COgY61qtP/y5rzDRV6TrXsDilAjvDC2O1VVEx5MsyJmsS6kNhRVcH2XFeKEE0j6vzqm2bMl1pjyVY= Received: from DB8P191CA0003.EURP191.PROD.OUTLOOK.COM (2603:10a6:10:130::13) by AS2PR08MB10035.eurprd08.prod.outlook.com (2603:10a6:20b:64a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.29; Thu, 30 Nov 2023 08:11:20 +0000 Received: from DB5PEPF00014B93.eurprd02.prod.outlook.com (2603:10a6:10:130:cafe::15) by DB8P191CA0003.outlook.office365.com (2603:10a6:10:130::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.23 via Frontend Transport; Thu, 30 Nov 2023 08:11:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by DB5PEPF00014B93.mail.protection.outlook.com (10.167.8.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7046.17 via Frontend Transport; Thu, 30 Nov 2023 08:11:20 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Thu, 30 Nov 2023 08:11:19 +0000 Received: from armchair.cambridge.arm.com (10.2.80.71) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2507.32 via Frontend Transport; Thu, 30 Nov 2023 08:11:19 +0000 From: Szabolcs Nagy To: Subject: [PATCH] elf: Add TLS modid reuse test for bug 29039 Date: Thu, 30 Nov 2023 08:11:19 +0000 Message-ID: <20231130081119.1252882-1-szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DB5PEPF00014B93:EE_|AS2PR08MB10035:EE_|DB1PEPF00039232:EE_|DB9PR08MB6345:EE_ X-MS-Office365-Filtering-Correlation-Id: ca17022c-93a0-4da3-d175-08dbf17bf5f7 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: OAEU8+zm+XdT55PK7M7qAnxcYX6X85nfhwcimaa4S7hpxo/rwhxNCaI74/pI/3ijYrViSeQbw+tTAXZuNz6zzF7Vlw5sGZRLjUD5Fz3OLTACezXR919cu7SJZfFIPu3GCxK3jQ17Xdvry94RXl84SUFcQk06GDd6CxMAQ0rjv0+e4NTdm1sLfvdT03P/wh9qVnuKefwSaD0CfTrx+FMgTEFLGGtVaaMxG67jGOqQo4/KbtALgejKnWJ4BzSnIPazAaSsTNrQakJdLtY15Ppuzl7MRaklCvwWWMnV7aasKMu+d6fu+i+mWYvCmmIo0kxuJzTaVlOt24nVmqvQ6cUNv5iPSG8VFVYiLDzqG5Mr/m3zpOorJDgV8ze3sONL4upXF/NZQAj2DZ1UPBNgfTqxsErIzwwxXsVMnHQZ3VLWUD7qgWoP/npOzjj/I4zi2IB9DCibt7GNP8z5BednlwVW2UMokVijt37n6vIuw//gpCtOwSdK8YBAzDvOqcIXLRQYFINCYK01XPf7VY5dZOaNd3983sTDx16RMZo6dQwaJhmyDvnI0MlDWHdEZ5cTf88f0NO+jy3I0PN0I8pPCeekRA1mEfl9fd+AgojQZEMNPzqqKTbzwk7vcGU4B9heh7WDIqXdYf7fNkERo5BzpAm1fcltmwn916OgwayWTfcz5bKrPMCr5A9MxQjWuc9pGBPuoD3HExZ2ZyaaUVlj0W233JFuKRJNpA9c4a8HypEo9/QfjtJ8wc7cs1qrlrFglPN+eiJLPZ2nRgqFQ5mv9gGI1b1MF25HuMlCCsPeC2YMTzbD/JHu5SCYjIGXkInvKzaK X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(39860400002)(136003)(376002)(346002)(396003)(230922051799003)(186009)(451199024)(1800799012)(82310400011)(64100799003)(40470700004)(46966006)(36840700001)(40480700001)(40460700003)(356005)(81166007)(36860700001)(41300700001)(47076005)(5660300002)(86362001)(336012)(83380400001)(202311291699003)(426003)(82740400003)(2616005)(26005)(36756003)(7696005)(44832011)(1076003)(2906002)(6916009)(478600001)(8676002)(316002)(70206006)(8936002)(70586007)(2004002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB10035 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB1PEPF00039232.eurprd03.prod.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 579cc1e3-3ce9-4d77-ca07-08dbf17bef4e X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S+qG4vR0HOYv8RsCsK5g44wHM+w3HxJx0Jb44dUQQkBItFb0/Dt40fMoL3ZZiGzfQT1xVJbntp/i5e7FLP1JEu5z1qhpGOZkYHm4xihOga24dJWKKeAMsGMY1w/Z1y0GtkhpMtDlt3QTW8sdCvj4BUsZeSj4C5hOS8BGD0D0gnLvjsGpYBkxKDl5l0xHbTlFt3XHWzDHzPx8gRVtGnXvzkpuAEf+teAca5uqSpJcWOKyNMHTf/F0V2GHpCByaflJOKn1p5JYHMUy9vqnPkzQwEXRPH89yajI6SnSTLeSwdxX7G0yO+KQfevOlgLE3ImSRlAd/Ir4MqdNRpQybkDYHp9meHxGdY2oVMCNBtBnyTHCxMNW+1VthXM8n9fJASt7waFzimBYWJv4MXfFv2j/XHCZHQZypAmZ2zDzjX7N3Y4ZjGh4WCclrcssCAjqmK4kmc9eztNVWeVhTdw+u+ofiXty7K8vHXr2dG1oNTdA74lMj7k7eJRHD9lFXcY1/elaf81KQQp4VxQkTCnqtiR1ONbmaQSz8rxGGXEvqwqByodd3d+SBAIeGTbbsQcKWEVdRI3zW1rJ67s5h0rSXPfmLx7ezc1VfrjpC+C2ywRAWZ9isbLgfXofPLCTnKAshWcx/8a+7MixgADgJ8HewvqORVG6MqYHd4tQ9zZ0iSSPitaFkT6fq/9qRqW/SZR2CMZO25oJ9ssknwRvXpjWEESTtlnWGr3d5qJhYi4R0u8BWDminN8oQOOvSzArrVz0LutTt4+KxiZi3xNm5/ulqsU3VxWyK8vw6ehnRpiJovOoq/Y= 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:(13230031)(4636009)(376002)(346002)(39860400002)(136003)(396003)(230922051799003)(451199024)(1800799012)(64100799003)(82310400011)(186009)(40470700004)(36840700001)(46966006)(316002)(83380400001)(7696005)(6916009)(40480700001)(336012)(86362001)(1076003)(26005)(426003)(70586007)(70206006)(36860700001)(47076005)(8676002)(44832011)(8936002)(478600001)(5660300002)(2616005)(81166007)(82740400003)(202311291699003)(41300700001)(40460700003)(2906002)(36756003)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2023 08:11:31.2831 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ca17022c-93a0-4da3-d175-08dbf17bf5f7 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: DB1PEPF00039232.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB6345 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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 This is a minimal regression test for bug 29039 which only affects targets with TLSDESC and a reproducer requires that 1) Have modid gaps (closed modules) with old generation. 2) Update a DTV to a newer generation (needs a newer dlopen). 3) But do not update the closed gap entry in that DTV. 4) Reuse the modid gap for a new module (another dlopen). 5) Use dynamic TLSDESC in that new module with old generation (bug). 6) Access TLS via this TLSDESC and the now outdated DTV. However step (3) in practice rarely happens: during DTV update the entries for closed modids are initialized to "unallocated" and then dynamic TLSDESC calls __tls_get_addr independently of its generation. The only exception to this is DTV setup at thread creation (gaps are initialized to NULL instead of unallocated) or DTV resize where the gap entries are outside the previous DTV array (again NULL instead of unallocated, and this requires loading > DTV_SURPLUS modules). So the bug can only cause NULL (+ offset) dereference, not use after free. And the easiest way to get (3) is via thread creation. Note that step (5) requires that the newly loaded module has larger TLS than the remaining optional static TLS. And for (6) there cannot be other TLS access or dlopen in the thread that updates the DTV. Tested on aarch64-linux-gnu. Reviewed-by: Adhemerval Zanella --- elf/Makefile | 15 +++++++ elf/tst-tlsgap-mod0.c | 2 + elf/tst-tlsgap-mod1.c | 2 + elf/tst-tlsgap-mod2.c | 2 + elf/tst-tlsgap.c | 92 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 elf/tst-tlsgap-mod0.c create mode 100644 elf/tst-tlsgap-mod1.c create mode 100644 elf/tst-tlsgap-mod2.c create mode 100644 elf/tst-tlsgap.c diff --git a/elf/Makefile b/elf/Makefile index afec7be084..22902c18f1 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -469,6 +469,7 @@ tests += \ tst-tls21 \ tst-tlsalign \ tst-tlsalign-extern \ + tst-tlsgap \ tst-unique1 \ tst-unique2 \ tst-unwind-ctor \ @@ -896,6 +897,9 @@ modules-names += \ tst-tls20mod-bad \ tst-tls21mod \ tst-tlsalign-lib \ + tst-tlsgap-mod0 \ + tst-tlsgap-mod1 \ + tst-tlsgap-mod2 \ tst-tlsmod1 \ tst-tlsmod10 \ tst-tlsmod11 \ @@ -3030,3 +3034,14 @@ $(objpfx)tst-nodeps2-mod.so: $(common-objpfx)libc.so \ $(LINK.o) -Wl,--no-as-needed -nostartfiles -nostdlib -shared -o $@ $^ $(objpfx)tst-nodeps2.out: \ $(objpfx)tst-nodeps1-mod.so $(objpfx)tst-nodeps2-mod.so + +$(objpfx)tst-tlsgap: $(shared-thread-library) +$(objpfx)tst-tlsgap.out: \ + $(objpfx)tst-tlsgap-mod0.so \ + $(objpfx)tst-tlsgap-mod1.so \ + $(objpfx)tst-tlsgap-mod2.so +ifeq (yes,$(have-mtls-dialect-gnu2)) +CFLAGS-tst-tlsgap-mod0.c += -mtls-dialect=gnu2 +CFLAGS-tst-tlsgap-mod1.c += -mtls-dialect=gnu2 +CFLAGS-tst-tlsgap-mod2.c += -mtls-dialect=gnu2 +endif diff --git a/elf/tst-tlsgap-mod0.c b/elf/tst-tlsgap-mod0.c new file mode 100644 index 0000000000..1478b0beac --- /dev/null +++ b/elf/tst-tlsgap-mod0.c @@ -0,0 +1,2 @@ +int __thread tls0; +int *f0(void) { return &tls0; } diff --git a/elf/tst-tlsgap-mod1.c b/elf/tst-tlsgap-mod1.c new file mode 100644 index 0000000000..b10fc3702c --- /dev/null +++ b/elf/tst-tlsgap-mod1.c @@ -0,0 +1,2 @@ +int __thread tls1[100]; /* Size > glibc.rtld.optional_static_tls / 2. */ +int *f1(void) { return tls1; } diff --git a/elf/tst-tlsgap-mod2.c b/elf/tst-tlsgap-mod2.c new file mode 100644 index 0000000000..166c27d7f3 --- /dev/null +++ b/elf/tst-tlsgap-mod2.c @@ -0,0 +1,2 @@ +int __thread tls2; +int *f2(void) { return &tls2; } diff --git a/elf/tst-tlsgap.c b/elf/tst-tlsgap.c new file mode 100644 index 0000000000..4932885076 --- /dev/null +++ b/elf/tst-tlsgap.c @@ -0,0 +1,92 @@ +/* TLS modid gap reuse regression test for bug 29039. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include + +static void *mod[3]; +#define MOD(i) "tst-tlsgap-mod" #i ".so" +static const char *modname[3] = { MOD(0), MOD(1), MOD(2) }; +#undef MOD + +static void +open_mod (int i) +{ + mod[i] = xdlopen (modname[i], RTLD_LAZY); + printf ("open %s\n", modname[i]); +} + +static void +close_mod (int i) +{ + xdlclose (mod[i]); + mod[i] = NULL; + printf ("close %s\n", modname[i]); +} + +static void +access_mod (int i, const char *sym) +{ + int *(*f) (void) = xdlsym (mod[i], sym); + int *p = f (); + printf ("access %s: %s() = %p\n", modname[i], sym, p); + TEST_VERIFY_EXIT (p != NULL); + ++*p; +} + +static void * +start (void *arg) +{ + /* The DTV generation is at the last dlopen of mod0 and the + entry for mod1 is NULL. */ + + open_mod (1); /* Reuse modid of mod1. Uses dynamic TLS. */ + + /* DTV is unchanged: dlopen only updates the DTV to the latest + generation if static TLS is allocated for a loaded module. + + With bug 29039, the TLSDESC relocation in mod1 uses the old + dlclose generation of mod1 instead of the new dlopen one so + DTV is not updated on TLS access. */ + + access_mod (1, "f1"); + + return arg; +} + +static int +do_test (void) +{ + open_mod (0); + open_mod (1); + open_mod (2); + close_mod (0); + close_mod (1); /* Create modid gap at mod1. */ + open_mod (0); /* Reuse modid of mod0, bump generation count. */ + + /* Create a thread where DTV of mod1 is NULL. */ + pthread_t t = xpthread_create (NULL, start, NULL); + xpthread_join (t); + return 0; +} + +#include