-
Notifications
You must be signed in to change notification settings - Fork 5
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
Use shadowstack in SWT cloned module #224
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to change:
if (F.getName() == MAIN || F.getName().startswith(YK_CLONE_PREFIX) == false) {
a97d80f
to
459fc46
Compare
459fc46
to
78c196a
Compare
We can skip inserting shadowstacks into unopt version once we'll have the cp transition in place. |
// If we have two control points, we need to update the cloned main | ||
// function as well. | ||
if (controlPointCount == 2) { | ||
Function *MainClone = M.getFunction(YK_UNOPT_MAIN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still use the word clone
in a couple of variables and comments here. I think we should get rid of it entirely and always say if we are talking about opt or unopt. Clone is just too confusing, especially as we've changed at least once which one the clone is and I can never remember.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced.
// Load the current shadow stack pointer from the global variable. | ||
LoadInst *LoadedSSPtr = BuilderClone.CreateLoad(Int8PtrTy, SSGlobal); | ||
// Replace all allocas in MainClone with the loaded shadow stack pointer. | ||
rewriteAllocas(DL, MainCloneAllocas, LoadedSSPtr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need at the very least a comment explaining why we believe that allocas in unopt will match the allocas in opt. But ideally we have asserts here that make sure. We might want to optimise the opt
version slightly in the future which could change the variable order and then things will go wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added assertions 👉 fabd8f9
I'm a dummy, so the updated PR description is still too sparse for me. Can we see why we're doing this (not just how) please? |
It's been updated, is it clear? |
for (size_t i = 0; i < MainAllocas.size(); i++) { | ||
auto &[optAI, optOffset] = MainAllocas[i]; | ||
auto &[unoptAI, unoptOffset] = UnoptMainAllocas[i]; | ||
assert(optOffset == unoptOffset && "Alloca offsets must match"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any other values that need to be asserted here?
I noticed that the types are not always the same...
This assertion fails:
assert(optAI->getAllocatedType() == unoptAI->getAllocatedType() &&
"Alloca types must match");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that should do. But it's weird that the types don't match. I wasn't expecting that to happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, yeah it's only in on specific yk test ang_tests::sdiv.c
Mismatched alloca types at index 7:
Optimized alloca type: 0x70
Unoptimized alloca type: 0x55e49c008e90
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's weird. If you do Instr->dump()
it will give your more information which two instructions aren't matching.
It will do for now. Though I believe you got the two code blocks the wrong way around. Personally, I probably would have described the change more, rather than showing the code blocks, to give a little more context what is going on. Although a small example certainly doesn't hurt. For example, I might have written something like: The shadowstack pass, which turns With this PR, we use the shadow stack for the optimised |
Thank you, updated. |
Excellent. This looks good now. |
The ShadowStack pass, which transforms allocas into shadow stack pointers, is currently ignoring all unoptimised functions (code reference). However, we require these functions to utilise shadow stack pointers, as tracing is performed within them.
Furthermore, the unoptimised main function must be adjusted to use the same shadow stack instance as the optimised main function. This adjustment is essential because the unoptimised and optimised main functions need to share variables stored on the stack, facilitating the transitions between the versions.
This pull request ensures that both the optimised and unoptimised main functions use the same shadow stack. There is no need to establish a mapping between the allocas of the two functions, as the ordering of allocas remains consistent by definition; the functions are direct copies of one another.
Note: once we have the control point transition implemented, we can remove the shadow stack pointers from the optimised functions completely.
Example of variables in
__yk_unopt_main
declared before this change:Variables in
__yk_unopt_main
declared after this change: