From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id D58253857830 for ; Tue, 13 Apr 2021 14:02:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D58253857830 Received: by mail-oi1-x22e.google.com with SMTP id b3so2306834oie.5 for ; Tue, 13 Apr 2021 07:02:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bZhmChckAn2os44VOEcHSuXHq4s4yAWuMcMGet9zU4w=; b=ALIVP/lKmttJhsKr+eVLCHezMr6UC3Q/eKWPQHmF0SJU8M51GBhylnnvm8KCFuqVq/ kbacb7lBxCSydvIAAzqdOC62iIqqBlkPN8WGuBiE/GuOFjkVU040H7ffYVU/5VnD5P38 vp1ozVqGHPXgGF6C6GslAkyHrx0rFoZZ8d/ydmk15tHKQFLsAKY+LqOBonJeNTE2ie2L oV45O1k1IhIshE+K9TSOiP3sWh2D+Bw8rKhwJOJFL5ZvkyWwfvEk0YqQe6xex4Pqk92P jpIKeu4mnNactPIjpLJVVlRz7tDzR1DRkyeB6E9EtuEN8JXWa5YssEWNLHUbY3f5qXew QArA== X-Gm-Message-State: AOAM53264Xlk17R/7uFKJN8WG0KtmgwUq14z8BXO6+eLxIGdxCJgU/WP 4TgvVW8fJNBTu23y6KQ266Bo3QpfOIWTl3aXj/99lnGqpSY= X-Google-Smtp-Source: ABdhPJxDDZ9rlOr3Uw8Cq9JnZMmpmlOlDlgmeAX6FmQWzsFPTN0qFEelLPlFQp+try6BwakAeURH7OyaFpyGt0iskMk= X-Received: by 2002:aca:d481:: with SMTP id l123mr117004oig.25.1618322560031; Tue, 13 Apr 2021 07:02:40 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: "H.J. Lu" Date: Tue, 13 Apr 2021 07:02:03 -0700 Message-ID: Subject: Re: [PATCH v2 09/14] x86_64: Avoid lazy relocation of tlsdesc [BZ #27137] To: Szabolcs Nagy Cc: GNU C Library Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3034.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Apr 2021 14:02:42 -0000 On Tue, Apr 13, 2021 at 2:31 AM Szabolcs Nagy via Libc-alpha wrote: > > Lazy tlsdesc relocation is racy because the static tls optimization and > tlsdesc management operations are done without holding the dlopen lock. > > This similar to the commit b7cf203b5c17dd6d9878537d41e0c7cc3d270a67 > for aarch64, but it fixes a different race: bug 27137. > > Another issue is that ld auditing ignores DT_BIND_NOW and thus tries to > relocate tlsdesc lazily, but that does not work in a BIND_NOW module > due to missing DT_TLSDESC_PLT. Unconditionally relocating tlsdesc at > load time fixes this bug 27721 too. > > -- > v2: > - mention the ldaudit issue with bindnow and tlsdesc. > --- > sysdeps/x86_64/dl-machine.h | 19 ++++++++++++++----- > 1 file changed, 14 insertions(+), 5 deletions(-) > > diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h > index 103eee6c3f..9a876a371e 100644 > --- a/sysdeps/x86_64/dl-machine.h > +++ b/sysdeps/x86_64/dl-machine.h > @@ -570,12 +570,21 @@ elf_machine_lazy_rel (struct link_map *map, > } > else if (__glibc_likely (r_type == R_X86_64_TLSDESC)) > { > - struct tlsdesc volatile * __attribute__((__unused__)) td = > - (struct tlsdesc volatile *)reloc_addr; > + const Elf_Symndx symndx = ELFW (R_SYM) (reloc->r_info); > + const ElfW (Sym) *symtab = (const void *)D_PTR (map, l_info[DT_SYMTAB]); > + const ElfW (Sym) *sym = &symtab[symndx]; > + const struct r_found_version *version = NULL; > > - td->arg = (void*)reloc; > - td->entry = (void*)(D_PTR (map, l_info[ADDRIDX (DT_TLSDESC_PLT)]) > - + map->l_addr); > + if (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL) > + { > + const ElfW (Half) *vernum = > + (const void *)D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]); > + version = &map->l_versions[vernum[symndx] & 0x7fff]; > + } > + > + /* Always initialize TLS descriptors completely at load time, in > + case static TLS is allocated for it that requires locking. */ > + elf_machine_rela (map, reloc, sym, version, reloc_addr, skip_ifunc); > } > else if (__glibc_unlikely (r_type == R_X86_64_IRELATIVE)) > { > -- > 2.17.1 > LGTM. Thanks. -- H.J.