public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elf: Align argument of __munmap to page size [BZ #28676]
@ 2021-12-13 15:20 H.J. Lu
  2021-12-14  2:49 ` Rongwei Wang
  0 siblings, 1 reply; 7+ messages in thread
From: H.J. Lu @ 2021-12-13 15:20 UTC (permalink / raw)
  To: libc-alpha

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);
-- 
2.33.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] elf: Align argument of __munmap to page size [BZ #28676]
  2021-12-13 15:20 [PATCH] elf: Align argument of __munmap to page size [BZ #28676] H.J. Lu
@ 2021-12-14  2:49 ` Rongwei Wang
  2021-12-14  3:34   ` H.J. Lu
  0 siblings, 1 reply; 7+ messages in thread
From: Rongwei Wang @ 2021-12-14  2:49 UTC (permalink / raw)
  To: H.J. Lu, libc-alpha

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);
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] elf: Align argument of __munmap to page size [BZ #28676]
  2021-12-14  2:49 ` Rongwei Wang
@ 2021-12-14  3:34   ` H.J. Lu
  2021-12-14  7:40     ` Florian Weimer
  0 siblings, 1 reply; 7+ messages in thread
From: H.J. Lu @ 2021-12-14  3:34 UTC (permalink / raw)
  To: Rongwei Wang; +Cc: GNU C Library

On Mon, Dec 13, 2021 at 6:49 PM Rongwei Wang
<rongwei.wang@linux.alibaba.com> wrote:
>
> 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.
>
>

Let's wait for a few days.

-- 
H.J.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] elf: Align argument of __munmap to page size [BZ #28676]
  2021-12-14  3:34   ` H.J. Lu
@ 2021-12-14  7:40     ` Florian Weimer
  2021-12-14 13:48       ` H.J. Lu
  0 siblings, 1 reply; 7+ messages in thread
From: Florian Weimer @ 2021-12-14  7:40 UTC (permalink / raw)
  To: H.J. Lu via Libc-alpha

* H. J. Lu via Libc-alpha:

> On Mon, Dec 13, 2021 at 6:49 PM Rongwei Wang
> <rongwei.wang@linux.alibaba.com> wrote:
>>
>> 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.
>>
>>
>
> Let's wait for a few days.

Can we please fix the regression in some way?  It impacts development,
particularly at this late stage during the 2.34 cycle.

Either revert the change, or at least add the unchecked __munmap, and
fix that later.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] elf: Align argument of __munmap to page size [BZ #28676]
  2021-12-14  7:40     ` Florian Weimer
@ 2021-12-14 13:48       ` H.J. Lu
  2021-12-14 14:24         ` Florian Weimer
  0 siblings, 1 reply; 7+ messages in thread
From: H.J. Lu @ 2021-12-14 13:48 UTC (permalink / raw)
  To: Florian Weimer; +Cc: H.J. Lu via Libc-alpha, Rongwei Wang

On Mon, Dec 13, 2021 at 11:40 PM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu via Libc-alpha:
>
> > On Mon, Dec 13, 2021 at 6:49 PM Rongwei Wang
> > <rongwei.wang@linux.alibaba.com> wrote:
> >>
> >> 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.
> >>
> >>
> >
> > Let's wait for a few days.
>
> Can we please fix the regression in some way?  It impacts development,
> particularly at this late stage during the 2.34 cycle.
>
> Either revert the change, or at least add the unchecked __munmap, and
> fix that later.

What is the unchecked __munmap?


-- 
H.J.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] elf: Align argument of __munmap to page size [BZ #28676]
  2021-12-14 13:48       ` H.J. Lu
@ 2021-12-14 14:24         ` Florian Weimer
  2021-12-14 15:15           ` H.J. Lu
  0 siblings, 1 reply; 7+ messages in thread
From: Florian Weimer @ 2021-12-14 14:24 UTC (permalink / raw)
  To: H.J. Lu; +Cc: H.J. Lu via Libc-alpha, Rongwei Wang

* H. J. Lu:

> On Mon, Dec 13, 2021 at 11:40 PM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * H. J. Lu via Libc-alpha:
>>
>> > On Mon, Dec 13, 2021 at 6:49 PM Rongwei Wang
>> > <rongwei.wang@linux.alibaba.com> wrote:
>> >>
>> >> 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.
>> >>
>> >>
>> >
>> > Let's wait for a few days.
>>
>> Can we please fix the regression in some way?  It impacts development,
>> particularly at this late stage during the 2.34 cycle.
>>
>> Either revert the change, or at least add the unchecked __munmap, and
>> fix that later.
>
> What is the unchecked __munmap?

The __munmap at the end:

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);

Thanks,
Florian


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] elf: Align argument of __munmap to page size [BZ #28676]
  2021-12-14 14:24         ` Florian Weimer
@ 2021-12-14 15:15           ` H.J. Lu
  0 siblings, 0 replies; 7+ messages in thread
From: H.J. Lu @ 2021-12-14 15:15 UTC (permalink / raw)
  To: Florian Weimer; +Cc: H.J. Lu via Libc-alpha, Rongwei Wang

On Tue, Dec 14, 2021 at 6:24 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > On Mon, Dec 13, 2021 at 11:40 PM Florian Weimer <fweimer@redhat.com> wrote:
> >>
> >> * H. J. Lu via Libc-alpha:
> >>
> >> > On Mon, Dec 13, 2021 at 6:49 PM Rongwei Wang
> >> > <rongwei.wang@linux.alibaba.com> wrote:
> >> >>
> >> >> 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.
> >> >>
> >> >>
> >> >
> >> > Let's wait for a few days.
> >>
> >> Can we please fix the regression in some way?  It impacts development,
> >> particularly at this late stage during the 2.34 cycle.
> >>
> >> Either revert the change, or at least add the unchecked __munmap, and
> >> fix that later.
> >
> > What is the unchecked __munmap?
>
> The __munmap at the end:
>
> 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);
>

This is

https://sourceware.org/pipermail/libc-alpha/2021-December/134097.html

I am checking it in now.

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-12-14 15:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-13 15:20 [PATCH] elf: Align argument of __munmap to page size [BZ #28676] H.J. Lu
2021-12-14  2:49 ` Rongwei Wang
2021-12-14  3:34   ` H.J. Lu
2021-12-14  7:40     ` Florian Weimer
2021-12-14 13:48       ` H.J. Lu
2021-12-14 14:24         ` Florian Weimer
2021-12-14 15:15           ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).