From nobody Fri Nov 22 15:42:14 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 4Xvzqp72lSz5f2SV; Fri, 22 Nov 2024 15:42:14 +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 4Xvzqp6V24z3y5s; Fri, 22 Nov 2024 15:42:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732290134; 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=+r9di2uGoX99aJmsL/QeLbG6+1mOewfDaWtb2m+2FC8=; b=czjRDtgYD1HGoQ4MFd/chYjawyjAl8pzQTCkc35A6+6avQzrRp5nAZ7B3TS5E38K7vVaqO sWVZ4l0fVNrNhIc1IJ8F/BDNARSLWrLqdwaGd5K9NFnkQvAcMbgqaX8X/gOZeP3yDdq/NH ojQmWfnYCbv9Ti14cWOZuxXO0Mg0KN2GNooXxIkPtXVAz0ozU9PZUX68XynuLX966Q4S+B 92zP2T+CC2mTiLJby73UuYkmtpj6yS6wgSxrkAniqyttV7FTNKCsAjcYp1GBXIABZsiNZO HD6OQLAunKrGauB7ADDJyUfo1K6hteeN5mqBO+5BQFGz6o5QMoJxVszU/HzM6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732290134; 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=+r9di2uGoX99aJmsL/QeLbG6+1mOewfDaWtb2m+2FC8=; b=XA1sn9coZokFXTnU3t27t1Zut+tX11JWeYpfOkXloh4+yaixbId9WIDT+VIh/kvyj4HqCJ E2G7e735Cw/NWOTUYUsH3vOS5/LNaumw0tuip0Y4aai5I4xMzmY+KoZ5LWUdNeSYym6Yhh Bl0QbrHsjD9DGA1LX0/Uu2syrPHEiBithJgYtbka1E2P5PTnJcA0+qUFrSXUB8cZW3TXhI a3MKw+cRWKhbhhwYscjD1h+rmilkIpzOz6tzc4Xisflx3S64/mLnyG/qWRoxoaglhgUpAw toZu9xuez0XElmgLi32zBiZZCjutEkN56BFCh7Z6ELqFdnZBD8T2G0yDzWZsCg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732290134; a=rsa-sha256; cv=none; b=qdmWBXV4FDi54kuzeM5LPJ4HqsjXw7NaZccyOLBylZ4M8+A37WyVds1MnrmEq2/gkiKZy8 hJj+kbfrQVF3yzyHuk0BAdptYsLkiatF1g4rJcAERPUlsUModPqR3Y6UV+so4qOaK+yAx5 MyLAAe2XM8yLWj/AFz/zKHG5QIf0rISkMCBjTbLTZrUzmkNfC+7lJ9S1BoUUz6zlbx91ss 0ui2BWEzozhjHfOITIZhfLeg4MLLEAA+dKaGun6LgPOVeamcCypVjDp3EZEZ05ATWwUlCy cbY7XJ7dwgjZiRfg0GHeQa19hjNonPdX0fOK1OcBWmat4S7hj+L518737rpYog== 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 4Xvzqp5pFszWZ7; Fri, 22 Nov 2024 15:42:14 +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 4AMFgEUl052384; Fri, 22 Nov 2024 15:42:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AMFgEl9052381; Fri, 22 Nov 2024 15:42:14 GMT (envelope-from git) Date: Fri, 22 Nov 2024 15:42:14 GMT Message-Id: <202411221542.4AMFgEl9052381@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: e10cca68cf34 - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: e10cca68cf349d11bc5c6474b792529bffc789cf Auto-Submitted: auto-generated The branch stable/13 has been updated by rcm: URL: https://cgit.FreeBSD.org/src/commit/?id=e10cca68cf349d11bc5c6474b792529bffc789cf commit e10cca68cf349d11bc5c6474b792529bffc789cf Author: R. Christian McDonald AuthorDate: 2023-11-03 12:56:58 +0000 Commit: R. Christian McDonald CommitDate: 2024-11-22 15:41:10 +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 e2dc7f8c9eb9..b62a62c5b116 100644 --- a/libexec/rtld-elf/arm/reloc.c +++ b/libexec/rtld-elf/arm/reloc.c @@ -322,10 +322,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);