-
Notifications
You must be signed in to change notification settings - Fork 123
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 stack organization #268
base: master
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.
Hello! Thanks for your PR.
I am leaving couple of questions to get a bit of context for these changes.
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.
Were you observing any strange behavior before making these changes? If so, what were you experiencing?
Could you provide a PoC of an unexpected result you had and how this fix is solving the problem?
This will really help us understand what is going on.
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.
Hello @dledda-r7 , for testing it is possible to use the follow code (print_stack.c
):
#include <stdio.h>
extern char **environ;
int main(int argc, char **argv)
{
int cnt;
size_t *stack = (size_t *)argv - 1;
printf("argc: %d\n", argc);
printf("\n");
for (cnt = 0; argv[cnt] != NULL; cnt++) {
printf("argv[%d]: %s\n", cnt, argv[cnt]);
}
printf("\n");
for (cnt = 0; environ[cnt] != NULL; cnt++) {
printf("envv[%d]: %s\n", cnt, environ[cnt]);
}
printf("Stack:\n");
for (cnt = 0; stack[cnt] || stack[cnt + 1]; cnt++) {
printf(" 0x%08zx\n", stack[cnt]);
}
return 0;
}
Compile as follow:
gcc print_stack.c -o print_stack
Testing:
./print_stack hello this is a test
From the libreflect it is possible to use the follow code:
./noexec print_stack hello this is a test
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.
Ah yes, off-by-one errors, the bane of long nights and blurry debugger sessions. This one is made even worse by the debug output looking correct as it mangles the stack it's trying to produce and that stack mostly working 😈 . Thanks for the catch, cheers!
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.
Thanks, the code tests correctly and looks good to me! As a heads up, Rapid7 usually requires PRs to be made from unique topic branches, though I'll let the current team members take it from here
@rafajunio It'd be great to rebase this PR, we had to make some changes for CI to run: #272 |
Wrong calculation near the limits of argv, envv and auxv
Lesson learned, not use master to create PR anymore =) (my fork) Thank you, I hope that now is everything good. I merge the commits in the rebase as well. |
Wrong calculation near the limits of argv, envv and auxv