-
Notifications
You must be signed in to change notification settings - Fork 899
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
Potential security issues in mimalloc-secure #372
Comments
Hi Insu & @ironore15 -- thank you for finding these issues! quite ingenious :-)
Best, Daan |
Hi, Dann. Thanks to your quick response.
I think this issue can have several potential security problems. More generally, I believe that it weakens ASLR. Best, |
@insuyun @daanx - It might be best to take this offline through MSRC. Here is an example process for MSVC STL: https://github.com/microsoft/STL/blob/main/SECURITY.md |
Thanks Insu -- and thanks for the link, looks like an interesting paper. I have been wanting to do better ASLR anyways -- I feel just using a random base address may be too weak and it would be better to randomly spread out even more. Fixing this issue may be a good opportunity to revise this. |
Thank you @bhardwajs and Dann. |
Thanks for mentioning MSRC and providing a link Sumit. That is the proper channel to report severe issues (although it might still be better to contact me first over email). I think in this particular case it seems ok to keep discussing here though as the current issue would be not easy to exploit. Also, often with security issues for allocators it is debatable whether the behavior is ok or not (see here for example). |
Oh. I thought that you have an internal line for communicating with msrc. As Daan said, its not a big issue that msrc officially handles. I totally agree with Daan that it is often debatable which behavior is fine in a secure allocator. That is one of our motivations for this research. We have found several interesting behaviors in many allocators. But we selectively reported them if we believe that this can be really problematic For example, we decided to report first issue(metadata) because we found your attempts to limit metadata leakage. So we conclude that it seems to violate your expectation. We also reported the second one(spray) because it is an unique issue in mimalloc, which cannot be observable in other secure allocators that we tested. |
I pushed an initial fix for the second issue -- simply not using hinting for allocations over 1GiB to ensure enough randomness (and falling back to the OS for alignment for larger than 1GiB allocations). Still investigating the first issue but it looks actually ok. |
Hi! @ironore15 and I are working for research on secure allocators.
During research, we have found several potential security issues in mimalloc-secure mode.
We want to get your feedback regarding these issue.s
We found that metadata can be leaked even in secure mode.
Here is the proof of concept code.
If we run the code in Ubuntu 18.04, it shows like this.
As you can see,
((void **)p4)[8]
contains encoded metadata of mimalloc heap.We believe that it breaks your attempt to remove internal data in secure mode.
It happens because
_mi_page_free
doesn't remove metadata of free_list. In the above PoC, when we call malloc(-8), which is huge page, mimalloc calls_mi_page_free
to reclaim used pages. A page withxblock_size=64
fromp2
is also one of reclaimed pages. Then, the next malloc(128) will reuse the previous page, which contains an encoded free_list.I think one way to fix this issue is that we can zero-out page in secure mode.
In mimalloc-secure mode, an attacker can allocate a fixed memory address and bypass ASLR.
Here is PoC code.
This always exit successfully without segmentation fault.
It happens because eager commit option and mmap with aligned hint address. When segment is initially allocated, it calls
_mi_mem_alloc_aligned
. On UNIX system, it internally callsmi_unix_mmapx
with addr is NULL, andmi_os_get_aligned_hint
to get address for segment. In the following the code, (1 << 42) ~ (1 << 43) are only valid segment address. Since Eager commit is enabled default, very large allocation, e.g.,malloc(1 << 42)
, will always alloc memory address between 0x7FFFFFFF000 ~ 0x80000000000.We believe that one easy way to mitigate this is to disable eager commit in secure mode.
But I am not sure that it fits with mimalloc's design descision.
Best,
Insu Yun
The text was updated successfully, but these errors were encountered: