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 250DD3858D35 for ; Fri, 10 Dec 2021 04:23:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 250DD3858D35 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-315-9X8SS2VROQiHdzHHs0O6qw-1; Thu, 09 Dec 2021 23:23:23 -0500 X-MC-Unique: 9X8SS2VROQiHdzHHs0O6qw-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 09CA71018720; Fri, 10 Dec 2021 04:23:22 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.193.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5A06D5D740; Fri, 10 Dec 2021 04:23:21 +0000 (UTC) From: Florian Weimer To: "H.J. Lu via Libc-alpha" Subject: Re: [PATCH] elf: Stop with zero entry point value [BZ #28453] References: <20211210023106.3564447-1-hjl.tools@gmail.com> Date: Fri, 10 Dec 2021 05:23:19 +0100 In-Reply-To: <20211210023106.3564447-1-hjl.tools@gmail.com> (H. J. Lu via Libc-alpha's message of "Thu, 9 Dec 2021 18:31:06 -0800") Message-ID: <877dcddr60.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; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.5 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_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Fri, 10 Dec 2021 04:23:28 -0000 * H. J. Lu via Libc-alpha: > Stop with zero entry point value unless we are tracing shared objects > since a zero entry point value in the ELF header indicates there is no > associated entry point. Now we get > > $ ./elf/ld.so /lib64/libstdc++.so.6.0.29 > ./elf/ld.so: cannot execute '/lib64/libstdc++.so.6.0.29' without entry po= int > $ > > instead of > > $ /lib64/ld-linux-x86-64.so.2 /lib64/libstdc++.so.6.0.29 > Segmentation fault (core dumped) > $ > > This fixes [BZ #28453]. Hah. We recently had a downstream request to fix this. > +$(objpfx)tst-rtld-run-dso.out: tst-rtld-run-dso.sh $(objpfx)ld.so \ > +=09=09=09 $(objpfx)testobj1.so > +=09$(SHELL) tst-rtld-run-dso.sh $(objpfx)ld.so $(objpfx)testobj1.so \ > +=09 '$(test-wrapper-env)' '$(run_program_env)' > $@ > +=09$(evaluate-test) > + > diff --git a/elf/rtld.c b/elf/rtld.c > index 6ce1e07dc0..77bcdf8e29 100644 > --- a/elf/rtld.c > +++ b/elf/rtld.c > @@ -1424,6 +1424,14 @@ dl_main (const ElfW(Phdr) *phdr, > =09 implementations which has no real free() function it does not > =09 makes sense to free the old string first. */ > main_map->l_name =3D (char *) ""; > + > + /* Stop if there is no associated entry point and we are not > + tracing shared objects. */ > + if (main_map->l_entry =3D=3D main_map->l_addr > +=09 && state.mode !=3D rtld_mode_trace) > +=09_dl_fatal_printf("%s: cannot execute '%s' without entry point\n", > +=09=09=09 ld_so_name, _dl_argv[_dl_argc -1]); Missing space before 1. Should we say =E2=80=9Ccannot execute shared object=E2=80=9D or =E2=80=9Cca= nnot exe[cute a] shared library directly=E2=80=9D? execve should fail with ELIBEXEC, and th= e error messages should match. Should this check come later, after we have run ELF constructors, to maximize backwards compatibility? ELF constructors might never return. Thanks, Florian