-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
musl and glibc dynamic stubs are deeply flawed #8896
Comments
I wasn't able to locate the symbol size in the abilist files. E.g. on glibc-2.32, looking for symbol size of
Can you help locate it? |
Aye, look here. |
This is the result of the work on tools/gen_stubs.zig. It now uses the preprocessor to emit different symbols and sizes depending on the architecture. The data is collected directly from multiple libc.so files on disk built with upstream musl. Closes #8178 Addresses #8896 for musl There is still room for further improvement to this, which is to put `.ds` directives after symbols that are not followed by aliases, to avoid the potential problem of a linker believing that all symbols are aliases of each other.
musl stubs addressed in 01cb0bd. There is still room for further improvement to this, which is to put |
This commit upgrades glibc shared library stub-creating code to use the new abilists file which is generated by the new glibc-abi-tool project: https://github.com/ziglang/glibc-abi-tool/ The abilists file is different in these ways: * It additionally encodes whether a symbol is a function or an object, and if it is an object, it additionally encodes the size in bytes. * It additionally encodes migrations of symbols from one library to another between glibc versions. * It is binary data instead of ascii. * It is one file instead of three. * It is 165 KB instead of 200 KB. This solves a handful of bugs. Fixes #5882 Fixes #7667 Fixes #8714 Fixes #8896
This commit upgrades glibc shared library stub-creating code to use the new abilists file which is generated by the new glibc-abi-tool project: https://github.com/ziglang/glibc-abi-tool/ The abilists file is different in these ways: * It additionally encodes whether a symbol is a function or an object, and if it is an object, it additionally encodes the size in bytes. * It additionally encodes migrations of symbols from one library to another between glibc versions. * It is binary data instead of ascii. * It is one file instead of three. * It is 165 KB instead of 200 KB. This solves three bugs: Fixes #7667 Fixes #8714 Fixes #8896
This commit upgrades glibc shared library stub-creating code to use the new abilists file which is generated by the new glibc-abi-tool project: https://github.com/ziglang/glibc-abi-tool/ The abilists file is different in these ways: * It additionally encodes whether a symbol is a function or an object, and if it is an object, it additionally encodes the size in bytes. * It additionally encodes migrations of symbols from one library to another between glibc versions. * It is binary data instead of ascii. * It is one file instead of three. * It is 165 KB instead of 200 KB. This solves three bugs: Fixes #7667 Fixes #8714 Fixes #8896
F
in the abilist files) and variables (marked withD
) and treating them as if they were functions (STT_FUNC
entries). This is a huge problem when the linker performs copy relocations (eg. a static library references__stack_chk_guard
using absolute addresses, even though that symbol is provided by an external shared object). Upon seeing aSTT_FUNC
symbol lld processes it as if it were a function, creating a PLT (!!!) entry instead of emitting a copy relocation or a GOT indirection (afaics the latter is not really used).To understand the implications of this error here's a small snippet of ARM assembly, showing a typical function prologue where we load the stack cookie from
__stack_chk_guard
and store it on stack:And, guess what, that address points to a PLT entry:
In short the program is using garbage for stack cookie and, what's worse, it's not even random data!
The fix is simple, the abilist files contain the symbol size, it's only a matter of passing this info to the
.txt
files used to synthesize the.s
file.STT_OBJECT
) but are zero-sized, makinglld
promptly reject those when attempting to do a copy relocation. The fix is, again, to emit.size <sym>, <size>
for the symbols marked as%object
.Note that the symbol sizes may be different across platforms (eg. 32 vs 64 bit), getting the symbol size wrong is dangerous.
cc @flyx, this is the problem you were hitting.
The text was updated successfully, but these errors were encountered: