From nobody Fri Nov 22 15:38:06 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Xvzl2662Nz5f2dY; Fri, 22 Nov 2024 15:38:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xvzl25b0Lz3x7x; Fri, 22 Nov 2024 15:38:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732289886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iwtp0PXRvxMR+acIooIIwuWGH86blRZLdREZKI8/PNg=; b=xXNIBxKMVN4vmOr92Nzy1AccpkmlKcfDNpl7S8Zaz/3EveAnts9DOb6V7PpolWtay3uyOo PZh4Ry1e48zWin17yj60QZOYjjLfBOppN3jcvstUvD5uMxcdXnlZeZzN4fL3UQm8xC1dPV Pg7P6UbZw13HyapNUGsADtVthPEYyT6hu3nT5LW3wcJEtELRFE66g7iZoJQ7LEPvWfowN7 5obEuekq2WVRevOkMUkPk5teUp5pcfl4KnLzU2xRNUCfAfmJJLbnaUESPzeoCpDKkB/L67 J+R1V4BZVGhLbn1KZoPyiKZj+FTs1v8PwsI9O/d3usGC6AOPYXQ9yXVA7nwAOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732289886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iwtp0PXRvxMR+acIooIIwuWGH86blRZLdREZKI8/PNg=; b=n5ty648iCkEFFmGJoyJHa1h5+eOHuLm/jnKmqLlhM92gPsgXiTUVk20x4NPrppERixubvV H1GpokecPS1Bur6Gr6vGuFzmelMewYaqgXZm0Zmpq0Ts1iFepG6rx2fDJoJhR736REd61u rMx2X4eHCpn8Nm1Ez/tZ41w6Kb3qPiwiViCfRyoRnXaB1LRx8KFD+k0r91+LCFM3scNbi0 q2FQAm+riG6a1vomnJF3ABqwfWybF65GOqpRH71q24bsL1UKi/Ba6uubvTXIVAJrM14UQo jDwoFUzg289XofQrbmMuVgW/LHR4eI7RJyqzTwUaMLBMS88JS0YEoHz7SX7TiA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732289886; a=rsa-sha256; cv=none; b=CEzQZmlKup5tgqSP8sN4v2wLCepC3ES0VhyaJoWI9wh03WRYPw+AsovS8LB6TXUxG/qdfp Mxvfg5+y9Wbjq90746yKv+SNWIDvMhsPJruH1K87IGTgiQdVgIwLKU6SN6Y6hLIecaoPa2 ACt2ZCosVlUUo0PFDLzAwkunKBrlL9wgQIKDXUkFg3tBGj6wvXpPnfyAelcNpSe89oK6dn FUwCf7BfBcvAms71BdM7K1DDSV2EKkbDXy60jcn7skUb/yQ9hmFAwf1+kSD8HgvXPXDMDJ fRf/eDzvMiRI+nZNbEcBe4nFGZ79xoAmaR2p1owB/IXzeEdGq9WiBbnYt+LoUg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Xvzl24nH2zW3p; Fri, 22 Nov 2024 15:38:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4AMFc6Ef035992; Fri, 22 Nov 2024 15:38:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AMFc6Cf035989; Fri, 22 Nov 2024 15:38:06 GMT (envelope-from git) Date: Fri, 22 Nov 2024 15:38:06 GMT Message-Id: <202411221538.4AMFc6Cf035989@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "R. Christian McDonald" Subject: git: d39e0bdc6b76 - stable/14 - rtld/arm: fix initial-exec (IE) thread-local storage relocation List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rcm X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: d39e0bdc6b765f9b2fca24fb67951b12ec47348e Auto-Submitted: auto-generated The branch stable/14 has been updated by rcm: URL: https://cgit.FreeBSD.org/src/commit/?id=d39e0bdc6b765f9b2fca24fb67951b12ec47348e commit d39e0bdc6b765f9b2fca24fb67951b12ec47348e Author: R. Christian McDonald AuthorDate: 2023-11-03 12:56:58 +0000 Commit: R. Christian McDonald CommitDate: 2024-11-22 15:35:06 +0000 rtld/arm: fix initial-exec (IE) thread-local storage relocation net/frr[89] revealed an interesting edge-case on arm when dynamically linking a shared library that declares more than one static TLS variable with at least one using the "initial-exec" TLS model. In the case of frr[89], this library was libfrr.so which essentially does the following: #include #include "lib.h" static __thread int *a __attribute__((tls_model("initial-exec"))); void lib_test() { static __thread int b = -1; printf("&a = %p\n", &a); printf(" a = %p\n", a); printf("\n"); printf("&b = %p\n", &b); printf(" b = %d\n", b); } Allocates a file scoped `static __thread` pointer with tls_model("initial-exec") and later a block scoped TLS int. Notice in the above minimal reproducer, `b == -1`. The relocation process does the wrong thing and ends up pointing both `a` and `b` at the same place in memory. The output of the above in the broken state is: &a = 0x4009c018 a = 0xffffffff &b = 0x4009c018 b = -1 With the patch applied, the output becomes: &a = 0x4009c01c a = 0x0 &b = 0x4009c018 b = -1 Reviewed by: kib Approved by: kp (mentor) Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D42415/ (cherry picked from commit 98fd69f0090da73d9d0451bd769d7752468284c6) --- libexec/rtld-elf/arm/reloc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libexec/rtld-elf/arm/reloc.c b/libexec/rtld-elf/arm/reloc.c index c3e95940be74..6efc9f499761 100644 --- a/libexec/rtld-elf/arm/reloc.c +++ b/libexec/rtld-elf/arm/reloc.c @@ -280,10 +280,13 @@ reloc_nonplt_object(Obj_Entry *obj, const Elf_Rel *rel, SymCache *cache, return -1; tmp = (Elf_Addr)def->st_value + defobj->tlsoffset; - if (__predict_true(RELOC_ALIGNED_P(where))) + if (__predict_true(RELOC_ALIGNED_P(where))) { + tmp += *where; *where = tmp; - else + } else { + tmp += load_ptr(where); store_ptr(where, tmp); + } dbg("TLS_TPOFF32 %s in %s --> %p", obj->strtab + obj->symtab[symnum].st_name, obj->path, (void *)tmp);