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 6EC923858D35 for ; Fri, 10 Dec 2021 04:26:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6EC923858D35 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-257-mbHnWaV2M5yLFoTR4J5Anw-1; Thu, 09 Dec 2021 23:26:45 -0500 X-MC-Unique: mbHnWaV2M5yLFoTR4J5Anw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E62EC801962; Fri, 10 Dec 2021 04:26:44 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.193.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 46F36100164A; Fri, 10 Dec 2021 04:26:44 +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> <877dcddr60.fsf@oldenburg.str.redhat.com> Date: Fri, 10 Dec 2021 05:26:42 +0100 In-Reply-To: <877dcddr60.fsf@oldenburg.str.redhat.com> (Florian Weimer's message of "Fri, 10 Dec 2021 05:23:19 +0100") Message-ID: <87zgp9ccfx.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.84 on 10.5.11.22 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:26:49 -0000 * Florian Weimer: > * 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 p= oint >> $ >> >> 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) >> + And I forgot to fill in the blanks: Nick changed binutils very recently to default a zero entry point if _start is not defined. Before ld just used the lowest text address as the entry point (apparently a leftover from the a.out days). This means we need to link testobj1 with -Wl,--entry=3D0 (or use a new test object). >> 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=9C= cannot exe[cute a] > shared library directly=E2=80=9D? execve should fail with ELIBEXEC, and = the > 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