From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 649103858D3C for ; Fri, 16 Feb 2024 02:03:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 649103858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 649103858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708049001; cv=none; b=hTwsat0Xhw6RLluLTJWjQT+Lpmv6EsRYuQKtuLan9OwdHfs1AE+OLGX90XbhhLKEN7O297sUu9g9yZ69p2Estxo2jqeLIxMl35nZSIdvbqUTfhs3Uesi/wXjeFSif0RgJa93ZWlsMxmRnNJWF83R8m1cLdyO9wifK6FPoneVSGw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708049001; c=relaxed/simple; bh=lDXpAfBU/wP1triwwecALTNSVb1A8P6u4IJzoViKXXM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gVEVb7r4V7KuMl/llp3ztyJ2wmor4w7U3XZTXTdyevVLJKr3Q2k2PxxZbmqzzsXXXrPu8ql07PjeaEfhFUPCwehHx69N7+BUxyQUyQH0hYYS/uCOZMe5/s2HdWFFdbfiSo128FZh4Cd37MhpSAT4t176mIqXsdZcLnIBNYcD+1w= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708048990; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=Z/WabyzyNC6TwmmnwFZaoQUnDI1yRavloX/CnHPwIjE=; b=LB2c8pBdBzCXcTboLtWDVwtFVxP+fC5YjAohL3gvJ4/ij251oU1GheXo6rkXUpALhpdqQU mKd12/RA8bv/uJkMVRpNg9+Xmgyw/91PKvJTZnUMqkpXsVchEBw18i0+JHi9fKoRsHDfjV hdSRC5QPty5G4Y3tbDwwHOdxvyrRvB4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-cUyPgZXHOh-3Dwtk6LKJZg-1; Thu, 15 Feb 2024 21:03:06 -0500 X-MC-Unique: cUyPgZXHOh-3Dwtk6LKJZg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DC79285A596; Fri, 16 Feb 2024 02:02:57 +0000 (UTC) Received: from greed.delorie.com (unknown [10.22.8.101]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C4B49492BC6; Fri, 16 Feb 2024 02:02:57 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.15.2/8.15.2) with ESMTP id 41G22u57290764; Thu, 15 Feb 2024 21:02:57 -0500 From: DJ Delorie To: Michael Jeanson Cc: libc-alpha@sourceware.org, mathieu.desnoyers@efficios.com Subject: Re: [PATCH v8 1/8] nptl: fix potential merge of __rseq_* relro symbols In-Reply-To: <20240206162801.882585-2-mjeanson@efficios.com> Date: Thu, 15 Feb 2024 21:02:56 -0500 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Michael Jeanson writes: > We tracked this to the use of '-fmerge-all-constants' which allows the > compiler to merge identical constant variables. I assume the linker's constant (string?) merging won't affect this because the section is marked as writable to the linker? > diff --git a/csu/Makefile b/csu/Makefile > # Put it here to generate it earlier. > -gen-as-const-headers += rtld-sizes.sym > +gen-as-const-headers += rtld-sizes.sym rseq-sizes.sym Ok. > diff --git a/csu/rseq-sizes.sym b/csu/rseq-sizes.sym > new file mode 100644 > index 0000000000..c959758ff0 > --- /dev/null > +++ b/csu/rseq-sizes.sym > @@ -0,0 +1,8 @@ > +#include > + > +-- > +RSEQ_SIZE_SIZE sizeof (unsigned int) > +RSEQ_SIZE_ALIGN __alignof (unsigned int) > + > +RSEQ_OFFSET_SIZE sizeof (ptrdiff_t) > +RSEQ_OFFSET_ALIGN __alignof (ptrdiff_t) Looks like rtld-sizes.sym, so OK. > diff --git a/elf/Makefile b/elf/Makefile > + dl-rseq-symbols \ Ok. > diff --git a/elf/dl-rseq-symbols.S b/elf/dl-rseq-symbols.S > +#include > +#include Ok > +/* Some targets define a macro to denote the zero register. */ > +#undef zero Ok. > +/* Define 2 symbols, __rseq_size is public const and _rseq_size, which is an > + alias of __rseq_size, but hidden and writable for internal use. */ > + > + .globl __rseq_size > + .type __rseq_size, %object > + .size __rseq_size, RSEQ_SIZE_SIZE > + .hidden _rseq_size > + .globl _rseq_size > + .type _rseq_size, %object > + .size _rseq_size, RSEQ_SIZE_SIZE > + .section .data.rel.ro > + .balign RSEQ_SIZE_ALIGN > +__rseq_size: > +_rseq_size: > + .zero RSEQ_SIZE_SIZE Ok. > +/* Define 2 symbols, __rseq_offset is public const and _rseq_offset, which is an > + alias of __rseq_offset, but hidden and writable for internal use. */ > + > + .globl __rseq_offset > + .type __rseq_offset, %object > + .size __rseq_offset, RSEQ_OFFSET_SIZE > + .hidden _rseq_offset > + .globl _rseq_offset > + .type _rseq_offset, %object > + .size _rseq_offset, RSEQ_OFFSET_SIZE > + .section .data.rel.ro > + .balign RSEQ_OFFSET_ALIGN > +__rseq_offset: > +_rseq_offset: > + .zero RSEQ_OFFSET_SIZE Ok. > diff --git a/sysdeps/nptl/dl-tls_init_tp.c b/sysdeps/nptl/dl-tls_init_tp.c > index 092c274f36..80eb0107b5 100644 > --- a/sysdeps/nptl/dl-tls_init_tp.c > +++ b/sysdeps/nptl/dl-tls_init_tp.c > @@ -45,8 +45,10 @@ rtld_mutex_dummy (pthread_mutex_t *lock) > #endif > > const unsigned int __rseq_flags; > -const unsigned int __rseq_size attribute_relro; > -const ptrdiff_t __rseq_offset attribute_relro; > + > +/* The variables are in .data.relro but are not yet write-protected. */ > +extern unsigned int _rseq_size attribute_relro attribute_hidden; > +extern ptrdiff_t _rseq_offset attribute_relro attribute_hidden; er, extern *and* hidden? And relro? In theory the relro one is harmless but meaningless, as externs don't have sections in the local compilation unit. The hidden one will mark the symbol hidden, but does that really matter as long as it's marked hidden where it's defined? > void > __tls_pre_init_tp (void) > @@ -105,10 +107,7 @@ __tls_init_tp (void) > do_rseq = TUNABLE_GET (rseq, int, NULL); > if (rseq_register_current_thread (pd, do_rseq)) > { > - /* We need a writable view of the variables. They are in > - .data.relro and are not yet write-protected. */ > - extern unsigned int size __asm__ ("__rseq_size"); > - size = sizeof (pd->rseq_area); > + _rseq_size = sizeof (pd->rseq_area); > } Ok. > #ifdef RSEQ_SIG > @@ -117,8 +116,7 @@ __tls_init_tp (void) > all targets support __thread_pointer, so set __rseq_offset only > if the rseq registration may have happened because RSEQ_SIG is > defined. */ > - extern ptrdiff_t offset __asm__ ("__rseq_offset"); > - offset = (char *) &pd->rseq_area - (char *) __thread_pointer (); > + _rseq_offset = (char *) &pd->rseq_area - (char *) __thread_pointer (); > #endif > } Ok.