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 a minimum delay to free slabs reuse #55

Open
thestinger opened this issue Oct 13, 2018 · 3 comments
Open

add a minimum delay to free slabs reuse #55

thestinger opened this issue Oct 13, 2018 · 3 comments
Labels
enhancement New feature or request security

Comments

@thestinger
Copy link
Member

It already has a queue and just needs to enforce a minimum length.

@thestinger thestinger added enhancement New feature or request security labels Oct 13, 2018
@sempervictus
Copy link

Is there any legitimate concern for DoS under conditions with few available free slabs and a min quarantine time? With high churn, it seems like there's a window for recently freed slabs to be in the queue, but still unavailable for allocation. Using allocation requests as units of measurement (counter vs clock) might be of use there, especially if the calling threads are tracked for race reduction and entropy purposes.

@thestinger
Copy link
Member Author

The delay is measured in terms of deallocation cycles (for the future slab allocation quarantine), or in this case number of free slabs.

There's the concept of a partial slab (partially filled) which are filled before falling back to empty slabs (very limited cache size - 64k at the moment) and then free slabs which have been purged and memory protected and need to be unprotected to use them.

Keeping more free slabs is very cheap since the only cost is the slab metadata (56 bytes, but it could be reduced to 32 bytes) and potentially an extra 2 VMAs (but not necessarily).

@thestinger
Copy link
Member Author

This is the existing quarantine for large allocations, which are memory mappings with randomly sized guard regions: https://github.com/AndroidHardening/hardened_malloc/blob/3db3e167ede6a9bd035f9145b5cb817954e150dd/malloc.c#L551-L584. It uses a randomized array and a ring buffer as a queue.

Slab metadata (which is out-of-line, like all metadata) has prev / next pointers for the partial / empty / free slab lists, so no ring buffer is needed. It already had a queue simply for the baseline implementation without a real quarantine. I added a randomized array, so it just needs an enforced minimum size on the queue to have a comparable quarantine:

https://github.com/AndroidHardening/hardened_malloc/blob/3db3e167ede6a9bd035f9145b5cb817954e150dd/malloc.c#L424-L442

There will also be a quarantine for slab allocations themselves, but that's more complicated since it needs to have a way of preserving double-free detection unlike large allocations where that's all provided by the page -> region_info hash table regardless. It could also potentially avoid delaying the slabs becoming free slabs if it's implemented cleverly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request security
Projects
None yet
Development

No branches or pull requests

2 participants