public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: Binutils <binutils@sourceware.org>, Alan Modra <amodra@gmail.com>,
	 Nick Clifton <nickc@redhat.com>,
	Richard Earnshaw <rearnsha@arm.com>
Subject: Re: [PATCH v3 2/2] elf: Add GNU_PROPERTY_1_NEEDED check
Date: Mon, 28 Jun 2021 04:55:19 -0700	[thread overview]
Message-ID: <CAMe9rOr9S9iacv3zQNUs+0aUEhS8Z8pk52zMoB9YzYpUCkgpNg@mail.gmail.com> (raw)
In-Reply-To: <87v95yxtp7.fsf@oldenburg.str.redhat.com>

On Mon, Jun 28, 2021 at 1:47 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> >> Should the property be used just for error checking?  We would flip the
> >> default unconditionally.  Such a behavioral change simply based on some
> >> input file is quite surprising.
> >
> > The property is used to to allow compiling sources with
> > -fno-direct-extern-access
> > by pieces.  When creating a shared library, if one input relocatable file
> > is compiled with -fno-direct-extern-access, linker will bind all protected
> > symbols locally before seeing ALL relocations against them in different
> > input relocatables files.
>
> What is the advantage of this behavior?  Why should the presence of one
> such object file in the link cause symbol binding behavior change
> everywhere?  Especially if that one file does not even reference any
> protected symbols?

It makes linker work better.  If there are no protected symbols, there should
be no impact.

> >> For (4), I think we need to set a different flag (or perhaps even
> >> flags), and be really careful about what we do.  I think an output file
> >> that is an executable will never require indirect-extern-access, but it
> >
> > What did you mean by that?  We need to compile executable with
> > -fno-direct-extern-access for the whole scheme to work.
>
> indirect-extern-access imposes a requirement on executables, but
> building an executable to comply with the new requirements will not

That is correct.

> impose anything on the rest of the link.  I do not see the markup
> covering that.

The absence of the marker tells ld.so that copy relocation against
protected symbols in the executable is incompatible with the shared
library with the protected symbol AND the marker.

> >> can be incompatible with indirect-extern-access objects at run time.
> >> Shared objects as output files may themselves depend on
> >> indirect-extern-access objects at run time.  Ideally, markup would be
> >> applied to the relocations that are affected by the changes in the ABI.
> >
> > That is what my glibc changes do:
> >
> > $ ./elf/tst-protected1a
> > ./elf/tst-protected1a: protected1:
> > /export/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/tst-protected1moda.so:
> > copy relocation against non-copyable protected symbol
> > $ readelf -r ./elf/tst-protected1a | grep COPY
> > 0000004071d8  004300000005 R_X86_64_COPY     00000000004071d8 protected1 + 0
> > 0000004071dc  004600000005 R_X86_64_COPY     00000000004071dc protected3 + 0
> >
> > This error happens only if there is a copy relocation against protected symbol
> > definition compiled with -fno-direct-extern-access.
>
> Does this mean that executables do not need any markup at all, and that
> looking at the relocation types is sufficient?  (Same for canonical
> function addresses.)

No.  The key is the absence of the marker:

static inline void __attribute__ ((always_inline))
_dl_check_protected_symbol (const char *undef_name,
    const struct link_map *undef_map,
    const ElfW(Sym) *ref,
    const struct link_map *map,
    int type_class)
{
  if (undef_map != NULL
      && undef_map->l_type == lt_executable
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      && !(undef_map->l_1_needed
   & GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      && (map->l_1_needed
  & GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    {
      if ((type_class & ELF_RTYPE_CLASS_COPY))
/* Disallow copy relocations in executable against protected
   data symbols in a shared object which needs indirect external
   access.  */
_dl_signal_error (0, map->l_name, undef_name,
  N_("copy relocation against non-copyable protected symbol"));
      else if (ref->st_value != 0
       && ref->st_shndx == SHN_UNDEF
       && (type_class & ELF_RTYPE_CLASS_PLT))
/* Disallow non-zero symbol values of undefined symbols in
   executable, which are used as the function pointer, against
   protected function symbols in a shared object with indirect
   external access.  */
_dl_signal_error (0, map->l_name, undef_name,
  N_("non-canonical reference to canonical protected function"));
    }
}

This function is called on each protected symbol lookup.


--
H.J.

  reply	other threads:[~2021-06-28 11:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-24 13:24 [PATCH v3 0/2] elf: Implement indirect external access marker H.J. Lu
2021-06-24 13:24 ` [PATCH v3 1/2] elf: Add GNU_PROPERTY_1_NEEDED H.J. Lu
2021-06-24 13:24 ` [PATCH v3 2/2] elf: Add GNU_PROPERTY_1_NEEDED check H.J. Lu
2021-06-25 14:10   ` Florian Weimer
2021-06-25 18:52     ` H.J. Lu
2021-06-28  8:46       ` Florian Weimer
2021-06-28 11:55         ` H.J. Lu [this message]
2021-07-08  7:27           ` Florian Weimer
2021-07-08 12:26             ` H.J. Lu

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=CAMe9rOr9S9iacv3zQNUs+0aUEhS8Z8pk52zMoB9YzYpUCkgpNg@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=fweimer@redhat.com \
    --cc=nickc@redhat.com \
    --cc=rearnsha@arm.com \
    /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).