-
Notifications
You must be signed in to change notification settings - Fork 28
Perf improvements 3 26 #237
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,7 +61,7 @@ When enabled, the `CPU_PIN` feature will restrict allocations from a given zone | |
| * A chunk can be permanently free'd with a call to `iso_free_permanently`. | ||
| * If `SANITIZE_CHUNKS` is set all user chunks are cleared when passed to `iso_free` with the constant `0xde`. | ||
| * When freeing a chunk the canary in adjacent chunks above/below are verified. | ||
| * Some important zone metadata pointers are masked in-between `iso_alloc` and `iso_free` operations. | ||
| * When `MASK_PTRS` is enabled (default) the `user_pages_start` and `bitmap_start` pointers stored in zone metadata are XOR'd with a per-zone random secret between alloc and free operations, making them useless to an attacker who reads or corrupts zone metadata. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to explicit where the "per-zone random secret" is stored. |
||
| * Passing a pointer to `iso_free` that was not allocated with `iso_alloc` will abort. | ||
| * Pointers passed to `iso_free` must be 8 byte aligned, and a multiple of the zone chunk size. | ||
| * The free bit slot cache provides a chunk quarantine or delayed free mechanism. | ||
|
|
@@ -76,6 +76,7 @@ When enabled, the `CPU_PIN` feature will restrict allocations from a given zone | |
| * Randomized hints are passed to `mmap` to ensure contiguous page ranges are not allocated. | ||
| * When `ABORT_ON_NULL` is enabled IsoAlloc will abort instead of returning `NULL`. | ||
| * By default `NO_ZERO_ALLOCATIONS` will return a pointer to a page marked `PROT_NONE` for all `0` sized allocations. | ||
| * When `ABORT_ON_UNOWNED_PTR` is enabled (default) IsoAlloc will abort whenever it is passed a pointer it does not own. | ||
| * When `ABORT_NO_ENTROPY` is enabled IsoAlloc will abort when it can't gather enough entropy. | ||
| * When `RANDOMIZE_FREELIST` is enabled IsoAlloc will randomize the free list upon creation. May have a perf hit. | ||
| * Zones are retired and replaced after they've allocated and freed a specific number of chunks. This is calculated as `ZONE_ALLOC_RETIRE * max_chunk_count_for_zone`. | ||
|
|
@@ -94,6 +95,8 @@ The Makefile targets are very simple: | |
|
|
||
| `make library` - Builds a release version of the library without C++ support | ||
|
|
||
| `make library_less_strict` - Builds a release library with `ABORT_ON_UNOWNED_PTR=0`. Recommended when using IsoAlloc via `LD_PRELOAD`. | ||
|
|
||
| `make library_debug` - Builds a debug version of the library | ||
|
|
||
| `make library_debug_no_output` - Builds a debug version of the library with no logging output | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |
| #define SZ_TO_ZONE_LOOKUP_IDX(size) size >> 4 | ||
|
|
||
| #define CHUNK_TO_ZONE_TABLE_SZ (65535 * sizeof(uint16_t)) | ||
| #define ADDR_TO_CHUNK_TABLE(p) (((uintptr_t) p >> 32) & 0xffff) | ||
| #define ADDR_TO_CHUNK_TABLE(p) (((uintptr_t) p >> 22) & 0xffff) | ||
|
|
||
| typedef int64_t bit_slot_t; | ||
| typedef int64_t bitmap_index_t; | ||
|
|
@@ -36,7 +36,7 @@ typedef struct { | |
| int64_t next_free_bit_slot; /* The last bit slot returned by get_next_free_bit_slot */ | ||
| uint64_t canary_secret; /* Each zone has its own canary secret */ | ||
| uint64_t pointer_mask; /* Each zone has its own pointer protection secret */ | ||
| bitmap_index_t max_bitmap_idx; /* Max bitmap index for this bitmap */ | ||
| uint16_t max_bitmap_idx; /* Max bitmap index for this bitmap */ | ||
| uint32_t chunk_size; /* Size of chunks managed by this zone */ | ||
| free_bit_slot_t free_bit_slots_usable; /* The oldest members of the free cache are served first */ | ||
| free_bit_slot_t free_bit_slots_index; /* Tracks how many entries in the cache are filled */ | ||
|
|
@@ -50,7 +50,7 @@ typedef struct { | |
| uint8_t cpu_core; /* What CPU core this zone is pinned to */ | ||
| #endif | ||
| /* Warm/cold fields: accessed less frequently */ | ||
| uint32_t bitmap_size; /* Size of the bitmap in bytes */ | ||
| uint16_t bitmap_size; /* Size of the bitmap in bytes */ | ||
| uint32_t af_count; /* Increment/Decrement with each alloc/free operation */ | ||
| uint32_t chunk_count; /* Total number of chunks in this zone */ | ||
| uint32_t alloc_count; /* Total number of lifetime allocations */ | ||
|
|
@@ -133,9 +133,12 @@ typedef struct { | |
| * it can find the next zone that holds the same size | ||
| * chunks. The lookup table helps us find the first zone | ||
| * that holds a specific size in O(1) time */ | ||
| zone_lookup_table_t zone_lookup_table[ZONE_LOOKUP_TABLE_SZ]; | ||
| /* Array sized to cover indices 0..(SMALL_SIZE_MAX>>4) inclusive, then | ||
| * rounded to a multiple of 4 entries so the array occupies a whole | ||
| * number of 8-byte words and bitmaps[] remains naturally aligned. */ | ||
| zone_lookup_table_t zone_lookup_table[(SMALL_SIZE_MAX >> 4) + 4]; | ||
| /* For chunk sizes >= 1024 our bitmap size is smaller | ||
| * than a page. This optimization preallocates pages to | ||
| * than a page. This optimization preallocates pages tog | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tog? |
||
| * hold multiple bitmaps for these zones */ | ||
| iso_alloc_bitmap_t bitmaps[sizeof(small_bitmap_sizes) / sizeof(int)]; | ||
| uint64_t zone_handle_mask; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hey, sounds like cheating to me :P