public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Siddhesh Poyarekar <siddhesh@sourceware.org>
Cc: "Carlos O'Donell" <carlos@redhat.com>,
	Florian Weimer <fweimer@redhat.com>,
	GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH] ld.so: Handle read-only dynamic section gracefully [BZ #28340]
Date: Thu, 16 Sep 2021 15:11:24 -0700	[thread overview]
Message-ID: <CAMe9rOqJXj07UT4LMaL9oxS_RBGJd92wFThxtbQR6OdGRQaqTw@mail.gmail.com> (raw)
In-Reply-To: <3bc3dc4b-d39f-c810-d908-5875a098f1f9@sourceware.org>

On Thu, Sep 16, 2021 at 10:59 AM Siddhesh Poyarekar
<siddhesh@sourceware.org> wrote:
>
> On 9/16/21 11:08 PM, H.J. Lu wrote:
> > On Thu, Sep 16, 2021 at 9:45 AM Siddhesh Poyarekar
> > <siddhesh@sourceware.org> wrote:
> >>
> >> On 9/16/21 8:48 PM, H.J. Lu wrote:
> >>> On Thu, Sep 16, 2021 at 7:11 AM Carlos O'Donell <carlos@redhat.com> wrote:
> >>>>
> >>>> On 9/16/21 00:48, Florian Weimer via Libc-alpha wrote:
> >>>>> * H. J. Lu:
> >>>>>
> >>>>>> There is nothing wrong with read-only dynamic segment.
> >>>>>
> >>>>> A relocated DYNAMIC array is part of the ABI for !DL_RO_DYN_SECTION.
> >>>>> ELF requires that DT_STRTAB is present.  DT_STRTAB needs relocation.
> >>>>> This means that for !DL_RO_DYN_SECTION, the dynamic segment cannot be in
> >>>>> a read-ony LOAD segment for a valid ELF file.
> >>>>
> >>>> I agree strongly with this position.
> >>>>
> >>>> Even with PT_GNU_RELRO, we must only go in one direction from RW -> RO (to avoid
> >>>> other security issues e.g. hardening not loosening the restrictions).
> >>>>
> >>>> In theory the vDSO is invalid.
> >>>>
> >>>> In practice it is a DL_RO_DYN_SECTION DSO but selected dynamically at runtime
> >>>> rather than statically at compile time for the target.
> >>
> >> Actually it isn't.  The dynamic section in the vdso is already relocated
> >> by the kernel when it's mapped in.  DL_RO_DYN_SECTION DSOs are not
> >> relocated because of which any references to pointers written in the
> >> .dynamic section need to be relocated.
> >
> > No.  Relocation of vDSO dynamic section is done by elf_get_dynamic_info.
> > Here is a patch to remove the hack for vDSO.
> >
>
> Ahh, I misunderstood the comment in setup_vdso, sorry.  I verified by
> running under the debugger that the kernel doesn't adjust .dynamic
> entries before mapping the vdso.
>
> This updated patch is definitely better IMO but it still doesn't resolve
> the two outstanding questions posed so far.  I'm on the fence about the
> first one (it's imprecise but the cost of imprecision doesn't seem high
> enough to warrant the extra check) but slanted slightly towards
> allocating memory and writing out relocated addresses in the interest of
> keeping the user experience with dl_iterate_phdr and friends consistent.
>
> 1. Should the readonly decision be based solely on DYNAMIC flags or also
> consider flags on the encompassing LOAD segment?

It should purely depend on PT_DYNAMIC segment.

> 2. Do we want to leave .dynamic unrelocated for read-only DYNAMIC or
> should we instead allocate an array to write relocated addresses in
> there, like we did for vdso?

My patch removed the hack for vDSO to leave the read-only
PT_DYNAMIC segment unrelocated.

-- 
H.J.

  reply	other threads:[~2021-09-16 22:12 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-14 19:09 Siddhesh Poyarekar
2021-09-14 19:15 ` Florian Weimer
2021-09-15  1:14   ` Siddhesh Poyarekar
2021-09-15 14:35 ` H.J. Lu
2021-09-15 15:42   ` Siddhesh Poyarekar
2021-09-15 16:13     ` H.J. Lu
2021-09-15 16:24       ` Siddhesh Poyarekar
2021-09-15 16:34         ` H.J. Lu
2021-09-16  1:43           ` Siddhesh Poyarekar
2021-09-16  2:23             ` H.J. Lu
2021-09-16  3:46               ` Siddhesh Poyarekar
2021-09-16  4:26                 ` H.J. Lu
2021-09-16  4:28                   ` Siddhesh Poyarekar
2021-09-16  4:30                     ` H.J. Lu
2021-09-16  4:48               ` Florian Weimer
2021-09-16  5:36                 ` Siddhesh Poyarekar
2021-09-16  5:46                   ` Florian Weimer
2021-09-16  6:04                     ` Siddhesh Poyarekar
2021-09-16 14:11                 ` Carlos O'Donell
2021-09-16 15:18                   ` H.J. Lu
2021-09-16 16:45                     ` Siddhesh Poyarekar
2021-09-16 17:38                       ` H.J. Lu
2021-09-16 17:58                         ` Siddhesh Poyarekar
2021-09-16 22:11                           ` H.J. Lu [this message]
2021-09-17  2:47                             ` Siddhesh Poyarekar
2021-09-17  2:59                               ` H.J. Lu
2021-09-17  3:36                                 ` Siddhesh Poyarekar
2021-09-17  3:42                                   ` H.J. Lu
2021-09-17  3:44                                     ` Siddhesh Poyarekar
2021-09-17  3:44                                   ` Florian Weimer
2021-09-17  3:51                                     ` Siddhesh Poyarekar
2021-09-16 18:03                         ` Florian Weimer
2021-09-16 22:14                           ` H.J. Lu
2021-09-17  2:58                           ` Siddhesh Poyarekar
2021-09-17  3:46                             ` Florian Weimer
2021-09-17  4:00                               ` Florian Weimer
2021-09-17  4:12                                 ` [PATCH] ld.so: Remove DL_RO_DYN_SECTION H.J. Lu
2021-09-17  6:54                                   ` David Abdurachmanov
2021-09-17  9:01                                   ` Siddhesh Poyarekar
2021-09-17 15:40                                     ` H.J. Lu
2021-10-14 12:36                               ` [PATCH] ld.so: Handle read-only dynamic section gracefully [BZ #28340] Maciej W. Rozycki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMe9rOqJXj07UT4LMaL9oxS_RBGJd92wFThxtbQR6OdGRQaqTw@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=carlos@redhat.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=siddhesh@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).