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.133.124]) by sourceware.org (Postfix) with ESMTP id A67643855018 for ; Tue, 22 Jun 2021 07:12:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A67643855018 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-ODndH7UyNr-KvKMxv_3L8g-1; Tue, 22 Jun 2021 03:12:20 -0400 X-MC-Unique: ODndH7UyNr-KvKMxv_3L8g-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C2AAD804152; Tue, 22 Jun 2021 07:12:19 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-112-211.ams2.redhat.com [10.36.112.211]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E6AAD5D6AD; Tue, 22 Jun 2021 07:12:18 +0000 (UTC) From: Florian Weimer To: "H.J. Lu" Cc: "H.J. Lu via Libc-alpha" Subject: Re: [PATCH 3/4] Add run-time chesk for single global definition References: <20210620233620.391576-1-hjl.tools@gmail.com> <20210620233620.391576-4-hjl.tools@gmail.com> <87czsfn0w7.fsf@oldenburg.str.redhat.com> Date: Tue, 22 Jun 2021 09:12:16 +0200 In-Reply-To: (H. J. Lu's message of "Mon, 21 Jun 2021 06:20:16 -0700") Message-ID: <878s32gypb.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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, 22 Jun 2021 07:12:25 -0000 * H. J. Lu: > On Mon, Jun 21, 2021 at 12:16 AM Florian Weimer wrote: >> >> * H. J. Lu via Libc-alpha: >> >> > +static inline void __attribute__ ((always_inline)) >> > +_dl_check_protected_symbol (const char *undef_name, >> > + const struct link_map *undef_map, >> > + const ElfW(Sym) *ref, >> > + const struct link_map *map, >> > + int type_class) >> > +{ >> > + if (undef_map != NULL >> > + && !(undef_map->l_1_needed >> > + & GNU_PROPERTY_1_NEEDED_SINGLE_GLOBAL_DEFINITION) >> > + && (map->l_1_needed >> > + & GNU_PROPERTY_1_NEEDED_SINGLE_GLOBAL_DEFINITION)) >> > + { >> > + if ((type_class & ELF_RTYPE_CLASS_COPY)) >> > + /* Disallow copy relocations against protected data symbols in >> > + an object with single global definition. */ >> > + _dl_fatal_printf ("copy relocation against non-copyable protected symbol=%s in file=%s\n", >> > + undef_name, DSO_FILENAME (map->l_name)); >> > + else if (ref->st_value != 0 >> > + && ref->st_shndx == SHN_UNDEF >> > + && (type_class & ELF_RTYPE_CLASS_PLT)) >> > + /* Disallow non-zero symbol values of undefined symbols, which >> > + are used as the function pointer, against protected function >> > + symbols in an object with single global definition. */ >> > + _dl_fatal_printf ("non-canonical reference to canonical protected function symbol=%s in file=%s\n", >> > + undef_name, DSO_FILENAME (map->l_name)); >> > + } >> > +} >> >> Why are those fatal errors? > > 2 copies of the data symbol can be out of sync between executable and > shared library. We can make them as warnings with tunable to control > it. I meant: Why can't you turn them into regular dlopen errors that are reported to the caller? (Use _dl_signal_error or any of the related functions.) >> I have trouble understanding the second comment (for the >> ELF_RTYPE_CLASS_PLT). > > If st_value is the undefined symbol in executable is not zero, it > is the PLT address in executable and ld.so will use it for function > pointer which is different from the function address in shared > library. Ahh, I wasn't aware of that ELF detail. Thanks, Florian