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 ESMTPS id 690BF3858D39 for ; Mon, 13 Dec 2021 17:50:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 690BF3858D39 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-586-LX86FaTMOUOmYPLotcPWPg-1; Mon, 13 Dec 2021 12:50:07 -0500 X-MC-Unique: LX86FaTMOUOmYPLotcPWPg-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 50BED3E741; Mon, 13 Dec 2021 17:50:05 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.17.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 48BD15ED25; Mon, 13 Dec 2021 17:50:03 +0000 (UTC) From: Florian Weimer To: Szabolcs Nagy Cc: Rongwei Wang , Andreas Schwab , xuyu@linux.alibaba.com, Rongwei Wang via Libc-alpha , gavin.dg@linux.alibaba.com Subject: Re: [PATCH v6 1/2] elf: Properly align PT_LOAD segments [BZ #28676] References: <20211204045848.71105-1-rongwei.wang@linux.alibaba.com> <20211213025103.48472-1-rongwei.wang@linux.alibaba.com> <20211213025103.48472-2-rongwei.wang@linux.alibaba.com> <87h7bczq0q.fsf@igel.home> <20211213115211.GV3294453@arm.com> <20211213173720.GX3294453@arm.com> Date: Mon, 13 Dec 2021 18:50:00 +0100 In-Reply-To: <20211213173720.GX3294453@arm.com> (Szabolcs Nagy's message of "Mon, 13 Dec 2021 17:37:20 +0000") Message-ID: <8735mwxulz.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 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: Mon, 13 Dec 2021 17:50:12 -0000 * Szabolcs Nagy: > The 12/13/2021 22:51, Rongwei Wang wrote: >> On 12/13/21 7:52 PM, Szabolcs Nagy via Libc-alpha wrote: >> > The 12/13/2021 12:46, Andreas Schwab wrote: >> > > On Dez 13 2021, Rongwei Wang via Libc-alpha wrote: >> > > >> > > > + else >> > > > + { >> > > > + /* Unmap the unused regions. */ >> > > > + ElfW(Addr) delta = map_start_aligned - map_start; >> > > > + if (delta) >> > > > + __munmap ((void *) map_start, delta); >> > > > + ElfW(Addr) map_end = map_start_aligned + maplength; >> > > > + delta = map_start + maplen - map_end; >> > > > + if (delta) >> > > > + __munmap ((void *) map_end, delta); >> > > >> > > I don't think map_end is guaranteed to be page-aligned. >> > >> > indeed i see failing munmap syscalls in strace >> Hi, Szabolcs >> >> Thanks for your test! I have no arm32 environment, and ignoring this test. >> >> It seems the 'map_end' need to be page-aligned before calling munmap. >> The following code only update the first line to fix this bug: >> >> + ElfW(Addr) map_end = ALIGN_UP(map_start_aligned + maplength, >> GLRO(dl_pagesize)); >> + delta = map_start + maplen - map_end; >> + if (delta) >> + __munmap ((void *) map_end, delta); >> >> Can you help me test this new code again if available? > > yes, the ALIGN_UP works. > > note that the issue is observable on aarch64 too (with 4k pagesize) > and likely x86_64 too, it just does not cause enough vm fragmentation > there to run out of memory. > > you can verify it by using strace -e munmap before and after. We should check munmap failure though and rollback everything if necessary. It's possible we can undo the initial PROT_NONE mapping even if future munmap calls fail because unmapping the first mapping does not need to split a mapping. Thanks, Florian