[PATCH v5 2/4] elf: Do not change stack permission on dlopen/dlmopen
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Fri Dec 20 17:20:12 GMT 2024
On 02/12/24 17:45, Florian Weimer wrote:
> * Adhemerval Zanella Netto:
>
>>> Huh. Hurd doesn't even use that, presumably because stacks are always
>>> executable?
>>
>> No idea of default Hurd ABI, but I would guess it is default to
>> executable since the glibc build sets GNU_STACK to RWE.
>
> I assumed it's heavily using nested functions which have their address
> taken.
>
>>> Okay. We only need this for the main thread because pthread_create
>>> creates new stacks directly with the right permissions.
>>
>> Yes, using GL(dl_stack_flags) that should be set only during loading
>> (maybe move it to GLRO, not sure if we can).
>
> I think we can move it to GLRO, I was about to suggest that in a
> follow-up patch.
>
>>>> diff --git a/sysdeps/unix/sysv/linux/mips/Makefile b/sysdeps/unix/sysv/linux/mips/Makefile
>>>> index d5725c69d8..05ec9150b2 100644
>>>> --- a/sysdeps/unix/sysv/linux/mips/Makefile
>>>> +++ b/sysdeps/unix/sysv/linux/mips/Makefile
>>>> @@ -61,6 +61,7 @@ ifeq ($(subdir),elf)
>>>> # this test is expected to fail.
>>>> ifneq ($(mips-has-gnustack),yes)
>>>> test-xfail-check-execstack = yes
>>>> +CFLAGS-tst-execstack.c += -DDEFAULT_RWX_STACK=1
>>>> endif
>>>> endif
>>>
>>> Is the xfail still needed?
>>
>> Without --enable-kernel=4.8, the mips seems to require an executable stack for
>> some fp emulation:
>>
>> sysdeps/unix/sysv/linux/mips/configure.ac
>> 138 # Check if we are supposed to run on kernels older than 4.8.0. If so,
>> 139 # force executable stack to avoid potential runtime problems with fpu
>> 140 # emulation.
>>
>> And kernel seems to still enforce it some, even on some recent kernels (6.3.0-2-5kc-malta):
>>
>> $ readelf -lW elf/tst-execstack | grep GNU_STACK
>> GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10
>>
>> $ gdb --args ./elf/tst-execstack --direct
>> [...]
>> (gdb) b __start
>> (gdb) r
>> [...]
>
> Ahh, different test (check-execstack vs tst-execstack).
>
>>> Why is setting DEFAULT_RWX_STACK only needed on MIPS, but not on i386?
>>> Does it reflect the combined kernel/toolchain default?
>>
>> Yes, and DEFAULT_RWX_STACK is only needed on mips because during
>> _dl_map_object_from_fd mips without $(mips-force-execstack) will have
>> GL(dl_stack_flags) equal to PF_X|PF_W|PF_R (due the -Wa,-execstack);
>> different than i686 (where with a recent toolchain by default it will
>> be just PF_W|PF_R).
>
> Okay.
Florian, do you think this patch still required additional work?
More information about the Libc-alpha
mailing list