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

Add stack traces to permissive mode logs #434

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ayrtonm
Copy link
Contributor

@ayrtonm ayrtonm commented Oct 7, 2024

This turned out to be easier to implement than labeling the /proc/pid/maps entries w/o changes across the runtime codebase so I pushed it separately since these changes are contained to permissive_mode.h. @randomPoison I tested manually by tweaking our tests but permissive mode doesn't interact well with criterion so it was pretty limited testing. Could you run this on the zlib demo and post the result? Closes #406.

@ayrtonm ayrtonm requested a review from randomPoison October 7, 2024 16:40
@ayrtonm
Copy link
Contributor Author

ayrtonm commented Oct 7, 2024

Also you may need to build with -fno-omit-frame-pointer.

@ayrtonm
Copy link
Contributor Author

ayrtonm commented Oct 7, 2024

huh CI broke because the address of the return address that I'm deriving from the frame pointer is unaligned. We could "fix" this by replacing the new *(uint64_t *)xs withmemcpys but that's probably just covering up the underlying issue. ret on x86 doesn't require alignment so this should work when disabling ubsan, but I think the SysV ABI says the return address address has to be aligned so something else is wrong here.

@ayrtonm
Copy link
Contributor Author

ayrtonm commented Oct 7, 2024

This only seems to affect things below main on the call stack so it seems like crt stuff deciding to not follow SysV ABI as strictly at times. In this case memcpy would be fine, but I'm not sure whether I should do that or add the additional stopping condition (fp & 0x7) != 0.

@randomPoison
Copy link
Contributor

It seems like permissive mode isn't working when I build against your branch. I'm seeing segfaults on the cross-compartment memory accesses, and nothing is being printed to the log. I tested against main and permissive mode works as expected there, so the issue shouldn't be with my setup, but it's possible I'm doing something wrong still.

@ayrtonm
Copy link
Contributor Author

ayrtonm commented Oct 28, 2024

Just realized I need to grab return addresses while grabbing the frame pointers otherwise the return addresses may be overwritten. nvm I was already doing this. It's probably failing because of the call w/o a frame pointer in the PLT stub.

The local_addr field was used to save the address of the signal handler stack to
debug permissive mode itself.
Seems like crt functions don't follow the SysV ABI as strictly since stack
frames below `main` sometimes lead to dereferencing unaligned frame pointers.
@ayrtonm ayrtonm force-pushed the am/permissive_mode_stacktrace branch from e583149 to c2aaf80 Compare October 29, 2024 02:05
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.

Consider adding stacktraces to permissive mode logs
2 participants