Memory Allocation Flashcards

1
Q

Tcache bins

A

Thread specific.
Stack.
Singly Linked.
Heads are in thread local storage.
It has chunks of fixed size s_i.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Arenas

A

Division of the heap.
Access requires synchronization.
At most, one thread can allocate.
Metadata is stored in a struct malloc_state.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Fastbins

A

Every arena has N_f fastbins of equally sized chunks.
Thread locks the arena when accessing it.
Stack.
Singly Linked.
Heads are found in malloc_state of the arena.
Has chunks of fixed size sf_i.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Smallbins

A

Every arena has N_s smallbins of equally sized chunks.
Queue.
Doubly-Linked.
Heads are found in malloc_state.
Has chunks of fized sizes ss_i.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Unsorted Bin

A

Every arena has one unsorted bin
with chunks of any size.
Queue.
Doubly-Linked.
Head in malloc_state.
Chunks of any size.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Large Bins

A

Every arena has N_l large bins with chunks in a certain size interval.
Stack.
Doubly-Linked list of Doubly-Linked lists of fixed size chunks.
Heads in malloc_state.
Chunk sizes in certain interval.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Malloc procedure

A

Check bins in the following order until we find chunk of exact size and if not, split the next larger chunk:
1. tcache bin
2. fastbin (refill tcache)
3. smallbin (refill tcache)
4. unsorted bin
- exact match (refill tcache)
- sort into small and large bins
5. largebin
6. anybin
7. re-check fastbins
8. top chunk
9. grow arena

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Free procedure

A

If chunk fits, push into:
1. tcache bin
2. fastbin
3. unsorted bin (consolidate chunk if possible)
4. if treshold is surpassed, clean up fastbin and shrink arena

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Invariant

A

A chunk in the unsorted bin, smallbins or largebins never borders another chunk in those bins or the top chunk.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How is the invariant upheld?

A

By performing consolidation of chunks that are moved into the unsorted bin.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Allocated Chunk

A

.
next chunk
|
v
———————————————————————————————————
prev. size or prev. user data | size | AMP | user data | size | AMP |
———————————————————————————————————
[ metadata = 16 bytes ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Free chunk: unsorted, small, large bin

A

metadata| fwd.ptr| bkwd.ptr | nxt.size.ptr | prev.size.ptr | size | AMP |
———————————————————————————————————

prev. size or prev. user data | size | AMP |
————————————————————-
[ metadata = 16 bytes ]

*nxt.size.ptr and prev.size.ptr only used for chunks in large bin that are the first in their size

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Free chunk: tcache, fastbin

A
    metadata              | next ptr|       tcache key |                   junk              |       --------------------------------------------------------------------------------------------------------- [ metadata = 16 bytes ]

*tcache key only for tcache:
process-wide random cookie used to detect double frees

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Safe Linking

A

Next pointer for tcache and fastbins gets xored with the page they are stored before being written into the chunk.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Circumvent Safe Linking

A

Leak a pointer in the program and it can be used to reverse the xor operation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly