New contributor looking for a starting point in elf/ (dynamic linker)
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Fri Oct 30 11:19:01 GMT 2026
On 28/10/26 07:13, 김형원 wrote:
> Hi Adhemerval and Basile
>
> Sorry for the late reply.
>
> I looked at sysdeps/x86_64/tst-cet-legacy-*.c to see the existing test
> cases in glibc.
>
> tst-cet-legacy-4/5/6.c test the case where dlopen() rejects a legacy
> .so (without IBT/SHSTK support).
>
> However, tst-cet-legacy-1.c links a legacy .so at build time and only
> checks that the call succeeds.
>
> There isn't a test that checks a CET related failure in this case.
>
> Is there a reason build-time linking doesn’t have a failure test like
> dlopen does?
>
> Is it because it's not possible to trigger a CET-related failure that way?
Yes, that is my understanding as well. For an object linked at build time there is
no CET loader failure to test. The loader handles the two cases differently on
purpose.
Note first that on Linux only the shadow stack (SHSTK) matters here. The kernel
has no userspace IBT support, and dl_cet_disable_cet and dl_cet_lock_cet
(sysdeps/unix/sysv/linux/x86_64/dl-cet.h) reject anything other than SHSTK.
At startup, rtld first maps the executable and all of its DT_NEEDED objects and
then runs the CET check (_rtld_main_check -> _dl_cet_check, in dl_main).
The shadow stack is only enabled after dl_main returns, in _dl_start_user
(RTLD_START_ENABLE_X86_FEATURES), before any constructor runs. So when the
loader finds a legacy object, nothing has run with a shadow stack yet, and
the full set of initial objects is known. The loader just leaves SHSTK
disabled (dl_cet_check_startup clears the bit), and the program runs without
a shadow stack. Nothing is wrong, so there is no error to report.
dlopen is different. The shadow stack is already active. It is locked with
ARCH_SHSTK_LOCK unless the tunable is 'permissive', and other threads may be
running with it. The loader cannot turn it off for the process, so the only
safe choice is to reject the object with
"rebuild shared object with SHSTK support enabled".
The one exception is x86_shstk=permissive in a single-threaded process, where
it calls ARCH_SHSTK_DISABLE instead. tst-cet-legacy-4*, -5* and -6* test this.
The marking is a claim that the code is compatible, not a requirement for
running it.
If you want to improve coverage of the startup path, what is missing is a check
of the result, not a failure test. tst-cet-legacy-1 sets no GLIBC_TUNABLES, and
SHSTK is not enabled by default. The CPU_FEATURE_SET_ACTIVE for SHSTK i
sysdeps/x86/cpu-features.c is under '#if CET_ENABLED && 0', so you need
glibc.cpu.hwcaps=SHSTK.
This means the test does not exercise the downgrade at all, even on CET hardware.
Two variants would cover it:
- GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK: SHSTK must be inactive
(check CPU_FEATURE_ACTIVE (SHSTK) or _get_ssp () == 0, as
tst-cet-legacy-10 does).
- GLIBC_TUNABLES=glibc.cpu.hwcaps=SHSTK:glibc.cpu.x86_shstk=on:
SHSTK must be active when the CPU and kernel support it, and
in_dso_1/in_dso_2 must still work.
For comparison, AArch64 GCS does have a startup failure. With
glibc.cpu.aarch64_gcs=1 (enforced), ld.so aborts with "not GCS compatible"
when a DT_NEEDED object is not GCS-marked, and tst-gcs-shared-enforced-abort
tests it. x86 has no "require the markings" mode, so there is nothing like
it to test there.
>
> Thanks,
>
> Hyungwon (HW)
>
> 2026년 8월 4일 (화) 오전 3:15, Adhemerval Zanella Netto
> <adhemerval.zanella@linaro.org>님이 작성:
>
>
>>
>>
>>
>> On 30/07/26 20:55, 김형원 via Libc-help wrote:
>>> Hi, I'm Hyungwon Kim.
>>>
>>> I'm interested in contributing to glibc.
>>>
>>> I've practiced writing syscalls and solved some ROP challenges from
>>> pwn.college, so I know some things about the ELF file format and related
>>> topics (ET_EXEC vs ET_DYN, etc).
>>>
>>> I cloned the glibc source and read a bit of code around elf/.
>>>
>>> I also read Patrick Horgan's post on how __libc_csu_init prepares for
>>> main(), and got interested in how (csu/elf-init.c) was removed in glibc
>>> 2.34 because it
>>> contained a convenient ROP gadget which was exploitable with ret2csu.
>>>
>>> That made me curious how dynamic linkers handle program startup as well.
>>>
>>> I'd like to keep learning in that direction, but don't have a good sense of
>>> which parts of elf/ (or the dynamic linker in general) are active and
>>> approachable for a new contributor.
>>>
>>> Does anyone have a recommendation on where to look,
>>> or something I could realistically work to patch on?
>> Hi Hyungwon Kim,
>>
>> The elf/ contains the system generic shared between Hurd and Linux, each
>> OS also have system-specific code at sysdeps (sysdeps/mach/ for Hurd and
>> sysdeps/unix/sysv/linux for Linux). We also have the code at csu/, which
>> is used for static-linking and process initialization.
>>
>> To understand to code better I would start at the elf/rtld.c, which is the
>> main path for the dynamic loader (ld.so). It should give you a good
>> understanding on how the dynamic-linking and process startup works.
>>
>> To a beginner I would recommend check on writing tests for elf/
>> instead of jump into a bug and/or new feature. For instance, we have limited
>> test for sotruss-lib.c + sotruss.sh, and chroot_canon.c, and for old format
>> cache.c (just to name some on top on my mind).
>>
>> If you feel confident on work on patch, we have a somewhat long bug
>> backlog [1]. Some recent issues are being worked, so you might check
>> the patchwork [2] to either see if there is already a proposed fix.
>>
>> [1] https://sourceware.org/bugzilla/buglist.cgi?bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=SUSPENDED&bug_status=WAITING&bug_status=REOPENED&component=dynamic-link&list_id=104448&product=glibc&query_format=advanced
>> [2] https://patchwork.sourceware.org/project/glibc/list/
More information about the Libc-help
mailing list