From nobody Fri Nov 3 21:44:14 2023 X-Original-To: dev-commits-src-main@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 4SMZ5C17nQz50VkM; Fri, 3 Nov 2023 21:44:15 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SMZ5C0dHjz3bTy; Fri, 3 Nov 2023 21:44:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699047855; 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=+p2CVdc3iR2w2qe2B8sk0Xdggx9yooYwP+cW41OHu7Y=; b=OVMDEskb0QXcOijEwESxpY7kDRvnqahUZgpXlrG5Lt8doX3E/453sRW1fAlbkMjCU2WgTU MpTXSWOb9f9olNuHwP20DACKIyfyrYoKXQW+d2KhRJr9AwhO314GwbZz4ydYBCsXugluop MuIDS6LglEwYQKMQMQ1jjkKUgwGkmOinWbcaSv2zSo0QXoMz/56crXc6ENlcRql7LsTmiL YtqW+cexiAtDwnhW0TylyUtYPGE0Yjj2SaCQZh6D4cgMOMmWQYZpNT6P0QAqULggVukmkH ICbRXGD7mFzTd3diBPGUZ1Is437MhvBwJqDgSau42nbohOWiGp1nWpazheXXsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699047855; 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=+p2CVdc3iR2w2qe2B8sk0Xdggx9yooYwP+cW41OHu7Y=; b=IZqzfftKJrjwu9bBYIprQWEZ/S7nFGI0t8QF9W7Be0dEBQyOkdbsE8biTPXvQqOlnk/izq TRmS5wsH/+3G4wb1yFOyW637HnCY/ElUB21zLi1rMyRZtCmQd4HD3Pzg6nORq0aRODKjUo 4LaYAM3gogaHme/74keUm/9mVmoJcQMz1ky+rUTrO+arP4iLZCtmAXA58OAQ9UA8eoDOtX 7ylYR5CPoiAY1V06T/kpkIs1W3HMRAqip3Hgnwcax7pNo7j5hln4yr/zB9WCsnGUpVklqH vsCCdtCCsJS53497oQsM8W9Qg6WaJT+MY+Scny2vN0hrQZSbxjy/aRj/9jGJyA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1699047855; a=rsa-sha256; cv=none; b=yXUFc6CTrouKrmCuc6LwohPQgNyGOSkMJtBmz+q9CVz7jwKmCFFEv3pK3ReweUBhzbNcKB t3HXUH3SAZpTnaMT9zxvyJBpjGDRdeb3BrQSpO4ZrrkfanLHhyYmlTCZlUaVqGxfh7y9gX tyrdYbPBP5Iigt+7JFvrlVEgrtK5KRTQCWTTpDGSL8egEtVDm00yDDFGQxKrbtMrXglRg2 BC4K6HqWgWzIQFmGLkfgo3yaxiTTi21F0DUmkpIzXJ1+c5Ke6Z/+Nd/DWh+0opUq0eQ54X 3/66D+IC8eRUiKHRb0kw9jGb/7WRI+H/JYwcjH2mc9R8IU8op5hUl7TZ2S1oOg== 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 4SMZ5B6qf1zXYd; Fri, 3 Nov 2023 21:44:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3A3LiEVd049269; Fri, 3 Nov 2023 21:44:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3A3LiEF3049266; Fri, 3 Nov 2023 21:44:14 GMT (envelope-from git) Date: Fri, 3 Nov 2023 21:44:14 GMT Message-Id: <202311032144.3A3LiEF3049266@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 98fd69f0090d - main - rtld/arm: fix initial-exec (IE) thread-local storage relocation List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 98fd69f0090da73d9d0451bd769d7752468284c6 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=98fd69f0090da73d9d0451bd769d7752468284c6 commit 98fd69f0090da73d9d0451bd769d7752468284c6 Author: R. Christian McDonald AuthorDate: 2023-11-03 12:56:58 +0000 Commit: Kristof Provost CommitDate: 2023-11-03 21:43:40 +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 Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D42415/ --- 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);