ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [BlackHat Heap] malloc_state structure
    Hack/Pwnable 2016. 11. 29. 22:18
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    struct malloc_state {
     
    mutex_t mutex; /* Serialize access. */
    int flags; /* Flags (formerly in max_fast). */
    #if THREAD_STATS
    /* Statistics for locking. Only used if THREAD_STATS is defined. */
        long stat_lock_direct, stat_lock_loop, stat_lock_wait;
    #endif
     
    mfastbinptr fastbins[NFASTBINS]; /* Fastbins */
    mchunkptr top;
    mchunkptr last_remainder;
    mchunkptr bins[NBIS*2];
    unsigned int binmap[BINMAPSIZE];    /* Bitmap of bins */
    struct malloc_state *next;            /* Linked list */
     
    INTERNAL_SIZE_T system_mem; 
    INTERNAL_SIZE_T max_system_mem;
    };
    cs


    mutex_t mutex : ptmalloc 구현에서 사용되는 다양한 구조체에 대한 액세스를 보장하기위해 사용된다,
    일반적으로 free()같은 함수를 호출할때와 같이 _int_xxx() 함수를 호출하기전에 일반적으로 사용된다.
    실제로는 public_free()를 호출한다. mutex lock을 걸어놓으면 다른 스레드에서 그쪽으로 접근을 할려고하면 못쓰고 _int_free()를 호출한다.

    int flags : 현재 arena의 특성을 나타내기위해 사용된다. 예를들어 fast bin 청크가있거나 메모리가 연속적적일때의 경우 사용된다.


    long stat_lock_direct
    long stat_lock_loop
    long stat_lock_wait

    - lock을 하는데 사용된다.


    mfastbinptr fastbins[...] : 이 배열은 할당되고, free 청크를 수용하기위한 fastbin의 배열이다. 수행되는 작업이 적어 연산이빠르다.

    mchunkptr top : top은 사용가능한 메모리의 끝과 인접한 특별한 덩어리이다. bin list에 속해있지않고, 지정된 영역의 할당되지않은 총 공간을 나타낸다.

    mchunkptr last_remainder : 주어진 메모리 덩어리에 정확히 맞지않는 메모리에 대한 small chunk 요청이있을때 사용된다.

    mchunkptr bins[...] : bins 배열은 fastbin 배열과 비슷하지만, 더 큰 normal chunk에서 사용된다.

    unsigned int binmap[...] : 사용중인 bin이 있는지 확인하는데 사용된다. 이것은 allocate가 확인된 bin을 건너뛰어 빠르게하는데 도움이된다.

    struct malloc_state *next : 다음 영역에 대한 포인터이다. single linked list로 돌아간다.

    INTERNAL_SIZE_T system_mem,max_system_mem : 현재 할당된 메모리 양을 추적하는데 사용된다. 대부분 size_t로 정의됨


    'Hack > Pwnable' 카테고리의 다른 글

    [BlackHat Heap] Binning  (0) 2016.11.29
    [BlackHat Heap] Chunks of memory  (0) 2016.11.29
    [BlackHat Heap] heap_info structure  (0) 2016.11.29
    Allocate Heap with fgets  (0) 2016.11.17
    [Heap Exploit] Unsafe_unlink - how2heap ver  (5) 2016.11.08

    댓글

Designed by Tistory.