Why does _dl_protect_relro align the end address down?

Joel Molin joelmolin@gmail.com
Tue Jan 17 15:56:28 GMT 2023


Thanks, I think I understand the challenge. Maybe I should have realized
when I saw the external bug I linked.

For as much as my opinion is worth, I guess I would also agree that
ALIGN_UP on the start would at least be consistent. Coupled with an
explanation such as "// Protect pages that are entirely within the relro
region. Since the runtime page size can vary, we can not trust linkers to
get this right and must be conservative." I would not have sent my email
(though I would have continued being sad). Right now it looks like a worst
of both worlds scenario.

Joel

On Tue, Jan 17, 2023 at 7:49 AM H.J. Lu <hjl.tools@gmail.com> wrote:

> On Tue, Jan 17, 2023 at 6:30 AM Adhemerval Zanella Netto
> <adhemerval.zanella@linaro.org> wrote:
> >
> >
> >
> > On 17/01/23 11:16, Florian Weimer wrote:
> > > * Adhemerval Zanella Netto:
> > >
> > >> On 17/01/23 04:57, Florian Weimer via Libc-help wrote:
> > >>> * Joel Molin via Libc-help:
> > >>>
> > >>>> Since mprotect will protect entire pages anyway, wouldn't it make a
> lot
> > >>>> more sense here to say `end = ALIGN_UP(...)`? Apart from feeling
> more
> > >>>> intuitive, it also seems like it would avoid page size
> inconsistencies
> > >>>> between runtime and link editing like the one above.
> > >>>
> > >>> ALIGN_UP might make memory read-only that should not be.
> > >>>
> > >>> There's some discussion about the alignment here:
> > >>>
> > >>>   PT_GNU_RELRO is somewhat broken
> > >>>   <https://sourceware.org/pipermail/libc-alpha/2022-May/138638.html>
> > >>>
> > >>> I still think this is fairly broken, but there does not seem to be
> much
> > >>> desire to fix it.
> > >>
> > >> It was not clear to me from that discussion what you think it is still
> > >> broken with PT_GNU_RELRO.
> > >
> > > Using ALIGN_DOWN for the start address can't be right.
> > >
> >
> > Do we have a bug report for this? Because H.J explanation [1] only
> describes
> > ld support for the end of the RO segment.
> >
> > [1] https://sourceware.org/pipermail/libc-alpha/2022-May/138642.html
>
> If the end of the PT_GNU_RELRO segment isn't page aligned,
> ALIGN_UP may change the executable page to read-only.
>
> --
> H.J.
>


More information about the Libc-help mailing list