Bug 2109510

Summary: glibc: Switch to custom linker script using --with-default-link=no for RELRO hardening
Product: Red Hat Enterprise Linux 8 Reporter: Florian Weimer <fweimer>
Component: glibcAssignee: Florian Weimer <fweimer>
Status: CLOSED ERRATA QA Contact: Martin Coufal <mcoufal>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 8.7CC: ashankar, codonell, dj, fweimer, ganandan, mcoufal, mnewsome, pfrankli, sipoyare, skolosov
Target Milestone: rcKeywords: Bugfix, Patch, Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: glibc-2.28-220.el8 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-05-16 09:03:05 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Florian Weimer 2022-07-21 13:01:03 UTC
We need to enable the custom linker script to improve RELRO hardening. Upstream did this with this patch:

commit 198abcbb94618730dae1b3f4393efaa49e0ec8c7
Author: Florian Weimer <fweimer>
Date:   Mon Apr 11 11:30:31 2022 +0200

    Default to --with-default-link=no (bug 25812)
    
    This is necessary to place the libio vtables into the RELRO segment.
    New tests elf/tst-relro-ldso and elf/tst-relro-libc are added to
    verify that this is what actually happens.
    
    The new tests fail on ia64 due to lack of (default) RELRO support
    inbutils, so they are XFAILed there.

Downstream, we can just pass --with-default-link=no in the configure invocation, no new patch required.

The upstream change comes with a test, but it depends on scripts/glibcelf.py, which is unfortunately a backport hazard. We can consider backporting the test as a later stage.

Comment 1 Florian Weimer 2022-07-22 08:46:16 UTC
Note to QE: This can be tested using the *upstream* elf/tst-relro-symbols.py test case, like this:

$ python3 elf/tst-relro-symbols.py /path/to/lib/libc-2.28.so \
            --required=_IO_cookie_jumps \
            --required=_IO_file_jumps \
            --required=_IO_file_jumps_maybe_mmap \
            --required=_IO_file_jumps_mmap \
            --required=_IO_helper_jumps \
            --required=_IO_mem_jumps \
            --required=_IO_obstack_jumps \
            --required=_IO_proc_jumps \
            --required=_IO_str_chk_jumps \
            --required=_IO_str_jumps \
            --required=_IO_strn_jumps \
            --required=_IO_wfile_jumps \
            --required=_IO_wfile_jumps_maybe_mmap \
            --required=_IO_wfile_jumps_mmap \
            --required=_IO_wmem_jumps \
            --required=_IO_wstr_jumps \
            --required=_IO_wstrn_jumps \
            --optional=_IO_old_cookie_jumps \
            --optional=_IO_old_file_jumps \
            --optional=_IO_old_proc_jumps \

See elf/Makefile for the command.

We cannot backport elf/tst-relro-symbols.py at this time because of the way it is written upstream, it creates a backporting hazard: there is a test that checks scripts/glibcelf.py against elf/elf.h, but both are not necessarily updated at the same time upstream. This needs to be fixed upstream at some point.

Comment 2 Florian Weimer 2022-07-22 08:57:45 UTC
eu-readelf -l is another way to check this.  If __libc_IO_vtables appears on a RELRO line, we are good:

   09      [RELRO: .tdata .tbss .init_array __libc_subfreeres __libc_atexit __libc_IO_vtables .data.rel.ro .dynamic .got]

And it turns out that for some reason, the segment layout in ourbuilds has RELRO hardening. So I'm moving this out to 8.8, so that we can backport the fixed upstream test (without the backporting hazard). Given that everything looks alright already, we do not need to make a code change at this time.

Comment 8 errata-xmlrpc 2023-05-16 09:03:05 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (glibc bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:2955