Skip to content
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

Fix support for amd64 x32 ABI #2305

Merged
merged 2 commits into from Dec 4, 2023
Merged

Fix support for amd64 x32 ABI #2305

merged 2 commits into from Dec 4, 2023

Conversation

peace-maker
Copy link
Member

x32 detection was broken since fbf2727
There is special handling in the plt emulation for this, which cannot be reached anymore.

# x32 uses 64-bit instructions, just restricts itself to a 32-bit
# address space.
if elf.arch == 'amd64' and elf.bits == 32:
emulation_bits = 64

Setting context.arch while loading a x32 ELF caused an exception in the LocalContext.__enter__ function, which caused the context not getting reset while leaving the contextmanager. This causes the behavior seen in #2304, where the log_level is reset to the default INFO and not reset to the old one after leaving the context. (Python context managers not to be confused with pwntools context class)

pwntools/pwnlib/elf/elf.py

Lines 278 to 285 in 65f9d57

# Is this a native binary? Should we be checking QEMU?
try:
with context.local(arch=self.arch):
#: Whether this ELF should be able to run natively
self.native = context.native
except AttributeError:
# The architecture may not be supported in pwntools
self.native = False

Fixes #2304

Recognize x32 ELF files as amd64.
@Arusekk
Copy link
Member

Arusekk commented Nov 24, 2023

Do we want to add a small x32 binary for tests? I think we can do without it, but just curious what's your opinion.

Anyway, just as a note, I think it will be nice to refer to the faulty commit in the message of the merged commit.

@peace-maker
Copy link
Member Author

I've compiled a small program with the different flags to test PLT emulation on x32 too.

gcc test.c -o test-x32 -mx32 -no-pie -Wl,-z,norelro -fstack-protector-all
gcc test.c -o test-x32-pie -mx32 -pie -Wl,-z,norelro -fstack-protector-all
gcc test.c -o test-x32-relro -mx32 -no-pie -Wl,-z,relro,-z,now -fstack-protector-all
gcc test.c -o test-x32-relro-pie -mx32 -pie -Wl,-z,relro,-z,now -fstack-protector-all

@peace-maker peace-maker merged commit b3d4043 into Gallopsled:dev Dec 4, 2023
13 checks passed
@peace-maker peace-maker deleted the x32 branch December 4, 2023 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some binary files cause context.quiet to affect the global scope.
2 participants