[0/3] Compatibility improvement for underlinked objects

Message ID cover.1700829130.git.fweimer@redhat.com
Headers
Series Compatibility improvement for underlinked objects |

Message

Florian Weimer Nov. 24, 2023, 12:56 p.m. UTC
  The current default dependency sorting may place objects without
explicit dependencies differently than before, which results in a
relocation order that historically was not used.  This in turn may cause
an underlinked object without dependencies to be relocated before
libc.so.6, which causes problems if the underlinked object refers to
IFUNC resolvers.

The fix is to use the machinery that was introduced alongside with
__libc_early_init to relocate libc.so early.

Tested on x86_64-linux-gnu and i686-linux-gnu.

Thanks,
Florian

Florian Weimer (3):
  elf: In _dl_relocate_object, skip processing if object is relocated
  elf: Introduce the _dl_open_relocate_one_object function
  elf: Relocate libc.so early during startup and dlmopen (bug 31083)

 elf/Makefile          | 21 ++++++++++
 elf/dl-open.c         | 95 ++++++++++++++++++++++++++-----------------
 elf/dl-reloc.c        |  6 +--
 elf/rtld.c            | 10 ++++-
 elf/tst-nodeps1-mod.c | 25 ++++++++++++
 elf/tst-nodeps1.c     | 23 +++++++++++
 elf/tst-nodeps2-mod.c |  1 +
 elf/tst-nodeps2.c     | 29 +++++++++++++
 8 files changed, 167 insertions(+), 43 deletions(-)
 create mode 100644 elf/tst-nodeps1-mod.c
 create mode 100644 elf/tst-nodeps1.c
 create mode 100644 elf/tst-nodeps2-mod.c
 create mode 100644 elf/tst-nodeps2.c


base-commit: 2e0c0ff95ca0e3122eb5b906ee26a31f284ce5ab
  

Comments

Carlos O'Donell Nov. 24, 2023, 5:04 p.m. UTC | #1
On 11/24/23 07:56, Florian Weimer wrote:
> The current default dependency sorting may place objects without
> explicit dependencies differently than before, which results in a
> relocation order that historically was not used.  This in turn may cause
> an underlinked object without dependencies to be relocated before
> libc.so.6, which causes problems if the underlinked object refers to
> IFUNC resolvers.

Agreed.

> 
> The fix is to use the machinery that was introduced alongside with
> __libc_early_init to relocate libc.so early.

I agree that treating libc.so as a special case is OK.

Thanks for looking at this and bug 31083.

> Tested on x86_64-linux-gnu and i686-linux-gnu.
> 
> Thanks,
> Florian
> 
> Florian Weimer (3):
>   elf: In _dl_relocate_object, skip processing if object is relocated
>   elf: Introduce the _dl_open_relocate_one_object function
>   elf: Relocate libc.so early during startup and dlmopen (bug 31083)
> 
>  elf/Makefile          | 21 ++++++++++
>  elf/dl-open.c         | 95 ++++++++++++++++++++++++++-----------------
>  elf/dl-reloc.c        |  6 +--
>  elf/rtld.c            | 10 ++++-
>  elf/tst-nodeps1-mod.c | 25 ++++++++++++
>  elf/tst-nodeps1.c     | 23 +++++++++++
>  elf/tst-nodeps2-mod.c |  1 +
>  elf/tst-nodeps2.c     | 29 +++++++++++++

This reminded me of the following changes...

commit 0e6d3adc60d8073397af6a320e594d98d7fbedde
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Oct 28 09:11:55 2016 -0700

    Check IFUNC definition in unrelocated shared library [BZ #20019]
    
    Calling an IFUNC function defined in unrelocated shared library may
    lead to segfault.  This patch issues an error message to request
    relinking the shared library if it references IFUNC function defined
    in the unrelocated shared library.
    
            [BZ #20019]
            * sysdeps/i386/dl-machine.h (elf_machine_rel): Check IFUNC
            definition in unrelocated shared library.
            * sysdeps/x86_64/dl-machine.h (elf_machine_rela): Likewise.


My opinion is that commit 0e6d3adc60d8073397af6a320e594d98d7fbedde is 
still needed and useful even if it was related to this same problem.

With your changes it should never trigger for libc.so.6.

... and I see that #20019 is linked into bug 31083, perfect!

>  8 files changed, 167 insertions(+), 43 deletions(-)
>  create mode 100644 elf/tst-nodeps1-mod.c
>  create mode 100644 elf/tst-nodeps1.c
>  create mode 100644 elf/tst-nodeps2-mod.c
>  create mode 100644 elf/tst-nodeps2.c
> 
> 
> base-commit: 2e0c0ff95ca0e3122eb5b906ee26a31f284ce5ab
  
Florian Weimer Nov. 24, 2023, 5:10 p.m. UTC | #2
* Carlos O'Donell:

> This reminded me of the following changes...
>
> commit 0e6d3adc60d8073397af6a320e594d98d7fbedde
> Author: H.J. Lu <hjl.tools@gmail.com>
> Date:   Fri Oct 28 09:11:55 2016 -0700
>
>     Check IFUNC definition in unrelocated shared library [BZ #20019]
>     
>     Calling an IFUNC function defined in unrelocated shared library may
>     lead to segfault.  This patch issues an error message to request
>     relinking the shared library if it references IFUNC function defined
>     in the unrelocated shared library.
>     
>             [BZ #20019]
>             * sysdeps/i386/dl-machine.h (elf_machine_rel): Check IFUNC
>             definition in unrelocated shared library.
>             * sysdeps/x86_64/dl-machine.h (elf_machine_rela): Likewise.
>
>
> My opinion is that commit 0e6d3adc60d8073397af6a320e594d98d7fbedde is 
> still needed and useful even if it was related to this same problem.
>
> With your changes it should never trigger for libc.so.6.

Agreed, it's still needed for other shared objects, including other
parts of glibc.

Thank you for the reviews.

Florian