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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTPS id 7058D3858D28 for ; Fri, 5 Nov 2021 15:51:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7058D3858D28 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-585-N_Kjd4xhNiibc_yhfGqjAQ-1; Fri, 05 Nov 2021 11:51:39 -0400 X-MC-Unique: N_Kjd4xhNiibc_yhfGqjAQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EB07614DEBA; Fri, 5 Nov 2021 15:50:39 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0554D5DD68; Fri, 5 Nov 2021 15:50:38 +0000 (UTC) From: Florian Weimer To: "H.J. Lu" Cc: GNU C Library Subject: Re: [PATCH 2/2] elf: Detect PT_LOAD segments that extend beyond EOF and refuse loading References: <27f078539ae2a5b390705ac6fa1a7437ae8ce97c.1636120354.git.fweimer@redhat.com> <87r1buu10l.fsf@oldenburg.str.redhat.com> <87ilx6u0kj.fsf@oldenburg.str.redhat.com> Date: Fri, 05 Nov 2021 16:50:37 +0100 In-Reply-To: (H. J. Lu's message of "Fri, 5 Nov 2021 08:03:11 -0700") Message-ID: <87cznetxde.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.14 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=-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_H2, 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, 05 Nov 2021 15:51:44 -0000 * H. J. Lu: > On Fri, Nov 5, 2021 at 7:41 AM Florian Weimer wrote: >> >> * H. J. Lu: >> >> > So dlopen should reject it. Can you identify the broken tools which >> > generate such input files and black list them for this test? >> >> It's objcopy --only-keep-debug, and it behaves as expted Separated >> debuginfo is broken by design. The program headers do not correspond to >> the file contents, but match the original ELF file. > > So the current checks aren't sufficient and your patch also checks > file size. On x86-64, where is the first failed check? Why doesn't it > need to check file size? Excellent question. I should have checked this as the first thing. On x86-64, dlopen fails with =E2=80=9Ctst-debug1mod1.so: object file has no dynamic section.=E2=80=9D This is because the file size is 0: Type Offset VirtAddr PhysAddr FileSiz Me= mSiz Flg Align DYNAMIC 0x000df8 0x0000000000003e10 0x0000000000003e10 0x000000 0x= 0001d0 RW 0x8 The dynamic segment has file size zero on aarch64, as well. But _dl_map_segments is called before the l->l_ld check in _dl_map_object_from_fd. Due to 64 KiB page alignment, it is more likely that we hit the memset call there to clear a partially mapped page, hence the crash. We I think we can move the l->l_ld check earlier and avoid the crash. I'll send a completely different patch. Thanks, Florian