From nobody Mon Jun 05 19:33:52 2023 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 4QZkLT2sgmz4b2lc; Mon, 5 Jun 2023 19:33:53 +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 4QZkLT0Wvtz3ttG; Mon, 5 Jun 2023 19:33:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685993633; 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=u18ZHq5JDUNec4jbUjtDulCMZygzKovC/Ch8DjbZ4KU=; b=v7gWFkbx7nJz8vCX/xQqAFsKjXoNXDgb7g6m3v9pBrueoE3iPZchllBzGZfbBLGTtD6kzy CjCevvAymR9Q6pyIjULDJKukrSG4xRdLVBXyafaMDZIhah+rBF/J/TflxS+Xs+dGsm5lhI EnSTFcKthFVX2wgITEATYXZvBiwoR6J+m4a5+Zx0LiHDjH7AKRfYu2BP1KOI0ZVr5F28Y1 QAx5ZqwCS9nRic/YOr11+fsbflq34fPTi2F40IbbktaIfsE5aQClr1LDKdrKafulhH40SW qnNimhNRVB9nVtw+XC5Gq1WbmX1GdnOZpditqvv18Cm4e9TMdDI8Xy63StIItQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685993633; 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=u18ZHq5JDUNec4jbUjtDulCMZygzKovC/Ch8DjbZ4KU=; b=HQpPIxI4TGxgJaaD12E4soUD/3dNp8i6n+qOcus5pqB8mGzRJ5t7Dfq2s/ZL3sCx+isWef cSi7K1ASJ1qWd+Fxt8/jRaPfRN/HHroeFzZWXxh8xMXbbowQyetpITpJh4sV19Kq4yyO04 +uaT4CmIkPPxuPpLsMuLtkHblAAtThCNaGwgXicYJxHlDNH6a9qXu7XIxbZugG/K9Oh8GO tzLVtGcdCpoDXAowPoBOUYVcnsH0Ygn5Xy08MNvvtzpHQU7w/gnYGsewuZK7wmFcOppobm BwbAEaPWixNsNrtA7ebBUWNDhx8z1/nq+94fB8IU3HYNJXzSjYA0q+WpOqgc9Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685993633; a=rsa-sha256; cv=none; b=T93MrKkFfX6y4cTncQXEBowFHYM3PcxMqRG71zz2QsMH3M2UPzS8VH8Fa74NTU1TfUsvF4 /XpTOjQBBjKA9ps66kG7650GERaKCyUMXjlgHkBk+FwO6vR92FzB88T+GmuCK00UEPm7CM 4Nor+IDbFNUO0s2NgVI8GI/uAelnKu7Spx+l2Hq6GF3GyZ6ktYcj2CNOTb8o3cOz6qfdV3 mmzyC1w81PcaUIH1p57TZAkB9bkzS2av/VGa5EK9EvTFFK2nt2h9vOY1vkZ2RBOTcQrkh3 aWGJyuoXx0sK0oP/hjcNMRE93Bk99rczhgAcWhBnPg5NxvbBsnLAFG/iZFsinw== 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 4QZkLS6jMmz11FY; Mon, 5 Jun 2023 19:33:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 355JXqDZ034280; Mon, 5 Jun 2023 19:33:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 355JXqQ0034279; Mon, 5 Jun 2023 19:33:52 GMT (envelope-from git) Date: Mon, 5 Jun 2023 19:33:52 GMT Message-Id: <202306051933.355JXqQ0034279@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 91880e07f605 - main - rtld: do not allow both dynamic DTV index and static TLS offset 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 91880e07f605edb90339685bc934699a4344de3b Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=91880e07f605edb90339685bc934699a4344de3b commit 91880e07f605edb90339685bc934699a4344de3b Author: Konstantin Belousov AuthorDate: 2023-06-05 00:54:46 +0000 Commit: Konstantin Belousov CommitDate: 2023-06-05 19:33:18 +0000 rtld: do not allow both dynamic DTV index and static TLS offset If we are allocating static offset for an object with dynamic index, return failure. In the opposite case, if dynamic index is requested for statically allocated TLS area, directly use the offset instead of setting the index. Taken from NetBSD Joerg Sonnenberger change for src/libexec/ld.elf_so/tls.c rev. 1.18. Sponsored by: The FreeBSD Foundation MFC after: 1 week --- libexec/rtld-elf/rtld.c | 14 ++++++++++++++ libexec/rtld-elf/rtld.h | 1 + 2 files changed, 15 insertions(+) diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 9ed9a4aed4bb..72a128ccbb81 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -5463,6 +5463,17 @@ allocate_module_tls(int index) rtld_die(); } + if (obj->tls_static) { +#ifdef TLS_VARIANT_I + p = (char *)_tcb_get() + obj->tlsoffset; +#else + p = (char *)_tcb_get() - obj->tlsoffset; +#endif + return (p); + } + + obj->tls_dynamic = true; + p = malloc_aligned(obj->tlssize, obj->tlsalign, obj->tlspoffset); memcpy(p, obj->tlsinit, obj->tlsinitsize); memset(p + obj->tlsinitsize, 0, obj->tlssize - obj->tlsinitsize); @@ -5474,6 +5485,9 @@ allocate_tls_offset(Obj_Entry *obj) { size_t off; + if (obj->tls_dynamic) + return (false); + if (obj->tls_static) return (true); diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h index 025bf4ff0670..b8b0d67bd05d 100644 --- a/libexec/rtld-elf/rtld.h +++ b/libexec/rtld-elf/rtld.h @@ -246,6 +246,7 @@ typedef struct Struct_Obj_Entry { bool jmpslots_done : 1; /* Already have relocated the jump slots */ bool init_done : 1; /* Already have added object to init list */ bool tls_static : 1; /* Already allocated offset for static TLS */ + bool tls_dynamic : 1; /* A non-static DTV entry has been allocated */ bool phdr_alloc : 1; /* Phdr is allocated and needs to be freed. */ bool z_origin : 1; /* Process rpath and soname tokens */ bool z_nodelete : 1; /* Do not unload the object and dependencies */