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

Misalinged stack on syscall wrapper calls #24

Open
difcsi opened this issue Nov 8, 2024 · 1 comment
Open

Misalinged stack on syscall wrapper calls #24

difcsi opened this issue Nov 8, 2024 · 1 comment

Comments

@difcsi
Copy link

difcsi commented Nov 8, 2024

I ran into compilation issues with the do_syscall implementations, resulting in runtime SEGfaults.

I drafted a PR fixing this in #22, but that doesn't solve the root cause, just happens to trigger a lucky emission change from GCC.

Instantiation of generic_syscall structs, the first thing in raw_syscall functions, may result in a segfault due to a misaligned stack at the beginning of a function. As per ABI, the compiler expects 16-byte alignment at the start of the function calls and optimises by emitting movaps instructions that fail due to an apparent 8-byte offset.

I suspect the alignment macros at raw_syscalls_impl.h have something to do with this, I'll investigate when I find some time for it.

As for why this worked so far, I suspect an emission change in GCC. Its worth noting that the issue occurred whilst upgrading xed and mbuild submodules in contrib, but I don't immediately see how that may be relevant.

@stephenrkell
Copy link
Owner

Well done on debugging this. Yes, if modern GCC is using movaps where older versions didn't, it would surface a stack pointer misalignment bug.

Remember that if the stack pointer is misaligned at the very beginning of the function, that indicates a bug in the caller (or its caller, or...).

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

No branches or pull requests

2 participants