-
Notifications
You must be signed in to change notification settings - Fork 72
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
DTrace support for OS X #6
base: master
Are you sure you want to change the base?
Conversation
Thanks a lot for this work! I have some friends that where complaining about this exact problem. cc @BestPig maybe you want to look at this? |
The dtrace script is now capable of detecting crash of a function call.
@dyjakan why did you set the destructive mode? Why did you set the buffer size to 256m, it is slow at the beginning, because dtrace allocate all the buffer before starting the debug process, are they really required? |
Destructive is not required, IIRC it was a left-over from the prototype. Removing. Extended buffer can decrease drops. However, as I already am mentioning this in the main comment I will get rid of it as the default option. Removing. |
@BestPig I've been thinking about your previous commit. Do we really need/want a trade off between thread-local variables and potential crash in-between malloc/calloc/etc Let's assume memory allocators exposed via Apple's libc are thread-safe, then we don't need to care about crashing in-between On the other hand, if memory allocators exposed via Apple's libc are not thread-safe, then the bigger issue is IMO data corectness which is lost by usage of global variables. This is interesting. |
I didn't thought about thread-safety. An ugly solution to avoid problem can be to duplicate variable as global and local, so Of course, if two malloc is called at the "same" time, the crashed value read in global may be wrong, but I'm not sure it possible to have more "stable" way. |
Sorry for the confussion. I did not properly reviewed your commit. I've read This is the code responsible for translating return values: if ret is None:
state.errors.append("%s = <error>" % call)
else:
state.info.append("%s = %#x" % (call, ret)) For free()'s def sanitize(x):
if x is None:
return None
if x == "<void>":
return 0
return int(x, 0) However for We can add sanitization but more elegant fix is to just go back to the initial version of However, one new issue presented itself -- if |
@BestPig @wapiflapi I'm back with some more testing:
So, for now |
Handling of error in a call is not working with your method if a function segfault. |
Explain to me why would a malloc/calloc/etc call segfault in the middle? In what specific situation? |
Corrupted metadata due to bugs/exploitation. Which is when you would want to use villoc to see what is going on and how you could exploit the heap. On 05/16/2015 12:21 PM, Andrzej Dyjak wrote:
|
@wapiflapi True, but aren't segfaults due to heap metadata corruption happen when freeing, not when allocating? Then this should be handled by |
But ofc we would somehow need to mark the |
Both cases occur. It's possible to corrupt the data in order to control the result of the next malloc for example, when done incorrectly (or caused by a bug) this can easily cause malloc & friends to crash. It is definitely a possibility and it would be sad if we couldn't see it. |
I agree that it would be sad if we would miss things, that's why I'm still involved in this problem, and ready to solve the issues. However, I've never encountered vulnerabilities that crash inside of memory allocation functions. Could you provide some examples in the form of code or articles? In the case of |
It's the same with |
Could you elaborate on how exactly the attacker would control fastbins? Does it require another write4? Does it require specific heap kung-foo before binning is taking place upon |
A discussion about the exploitability of #include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main(int argc, char **argv)
{
(void) argc, (void) argv;
void *a, *b, *c;
a = malloc(48);
b = malloc(48);
c = malloc(48);
free(a);
// Let's say we have an underflow on c. This
// is far from the only way to trigger a crash.
memset(c-128, 0xff, 0x200);
printf("A crash in malloc will be triggered *after* this print.\n");
malloc(48);
malloc(48);
return 0;
} (tested on x86_64, libc 2.19) |
Thanks for the example. Right now I don't have much time to focus on this merge, I will get back to it ASAP. |
No rush :) I'm busy as well. |
Following commits enable usage of DTrace on OS X platform as
ltrace
replacement.