From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by sourceware.org (Postfix) with ESMTPS id 754773858D39 for ; Tue, 14 Dec 2021 02:49:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 754773858D39 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R101e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=e01e04394; MF=rongwei.wang@linux.alibaba.com; NM=1; PH=DS; RN=2; SR=0; TI=SMTPD_---0V-Zl.M-_1639450146; Received: from 30.240.97.50(mailfrom:rongwei.wang@linux.alibaba.com fp:SMTPD_---0V-Zl.M-_1639450146) by smtp.aliyun-inc.com(127.0.0.1); Tue, 14 Dec 2021 10:49:07 +0800 Message-ID: <3e6b30a4-cf8a-49c9-7382-3f3255c8201a@linux.alibaba.com> Date: Tue, 14 Dec 2021 10:49:06 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:95.0) Gecko/20100101 Thunderbird/95.0 From: Rongwei Wang Subject: Re: [PATCH] elf: Align argument of __munmap to page size [BZ #28676] To: "H.J. Lu" , libc-alpha@sourceware.org References: <20211213152057.151438-1-hjl.tools@gmail.com> Content-Language: en-US In-Reply-To: <20211213152057.151438-1-hjl.tools@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-22.0 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL 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: Tue, 14 Dec 2021 02:49:16 -0000 Hi, HJ Thanks for your help to fix this bug. And I just found out that the patch "elf: Properly align PT_LOAD segments" had been merged into glibc/master. And I saw Florian's email: > 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. It seems rollback initial PROT_NONE mapping when munmap fails is good idea. Nice to have. Of course, IMO, this your patch is also can fix this munmap failure well. what do you think? When this fix is stable in glibc upstream, I will backport it into our internal glibc repo. So, if you have any improve this fix suggestions, I will respond immediately. Sorry for my speed is much slower than your. Thanks. On 12/13/21 11:20 PM, H.J. Lu via Libc-alpha wrote: > On Linux/x86-64, for elf/tst-align3, we now get > > munmap(0x7f88f9401000, 1126424) = 0 > > instead of > > munmap(0x7f1615200018, 544768) = -1 EINVAL (Invalid argument) > --- > elf/dl-map-segments.h | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h > index 70a4c40695..54e606aa87 100644 > --- a/elf/dl-map-segments.h > +++ b/elf/dl-map-segments.h > @@ -55,6 +55,7 @@ _dl_map_segment (const struct loadcmd *c, ElfW(Addr) mappref, > if (delta) > __munmap ((void *) map_start, delta); > ElfW(Addr) map_end = map_start_aligned + maplength; > + map_end = ALIGN_UP (map_end, GLRO(dl_pagesize)); > delta = map_start + maplen - map_end; > if (delta) > __munmap ((void *) map_end, delta); >