Pwnable/Tech

-Heap- ptmalloc2의 구조

2022. 1. 5. 16:26

bin: free된 청크들이 저장되는 객체

의의: 메모리 낭비를 막음, 해제된 청크를 빠르게 탐색하여 재사용할 수 있게 함.

 

ptmalloc has 128 bin.

 

ALL 128 --

Small bin: 62

Large bin: 63

Unsortedbin: 1

not-used: 2

 

실제 구조

0. not-used

1. unsorted bin

2. small[0]

...

63. smal[61]

64. large[0]

..

126. large[62]

127. not-used

--------------------

small bin: 32byte ~ 1023 byte

small bin[0] : 32byte

..

small bin[61] : 1008byte

small bin structure: circular doubuly-linked list -> FIFO

--> unlink, consolidation

 

##fast bin

fast bin: 32byte~176byte

fastbin: 10 but using 7 / each size: 16byte

Result in linux, 32byte ~ 128byte(using 7 bins)

fast bin structure: singly linked list -> LIFO --> so fast but have unification.

no unlink, no consolidation

Not using BK

 

 

large bin[0]: 1024~1088 .. [32]: 3072 ~ 3583

largebin structure: doubly-linked list

--> unlink, consolidation , 내림차순 정렬

 

unsortedbin

unsortedbin structure: circular doubly-linked list

_. 정렬X

fastbin 외의 모든 청크가 해제되었을때 크기를 구분X --> unsortedbin에 보관.

 

small bin 할당요청 -> Search fastbin or smallbin -> if no detected, Search unstortedbin.

large bin 할당요청 -> Search unstortedbin ->  if no detected, Search fastbin or smallbin.. etc

 

arena : bin들의 정보를 모두 담고 있는 객체.

멀티 스레딩 환경 속 공유 자원 사용으로 인한 레이스 컨디션을 막기 위해 lock을 사용. --> 64개의 arena 가 모두 lock 되어 있으면 "병목 현상"이 생김. 그 결과 ver. gblic 2.26 or over.. 에서 tcache(thread local cache) 객체를 만듬.

*https://rninche01.tistory.com/entry/heap2-glibc-malloc1-feat-Arena 에 잘정리되어있음.

 

tcache

: arena의 단점을 해소시킬 목적으로나온 , 말그대로, 독립적, 할당 캐시 저장소이다.

 

ALL 64

tcache structure: singly linked list -> LIFO

max chunk: 7

tcache range: 32 ~ 1040 --> range of fast and small bin

**First Search object when chunk size is in tcache range.

*if tcache is fully, Chunk allocates bin of own's size.

 

참고로 tcache | arena(some bins..) 형태로 나눠져 있음.

tcache는 보안 검사가 많이 생략되어 있어서 공격자들에게 힙 익스플로잇의 좋은 도구로 활용

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

-Heap- Tcache Poisoning  (0) 2022.01.06
-Heap- DFB(Double Free Bug)  (0) 2022.01.05
Heap Series - Use After Free  (0) 2021.12.25
environ ptr -하나하나 뜯어보기-  (0) 2021.11.29
메모리에 관한 내용 정리(pptx)  (0) 2021.11.14
'Pwnable/Tech' 카테고리의 다른 글
  • -Heap- Tcache Poisoning
  • -Heap- DFB(Double Free Bug)
  • Heap Series - Use After Free
  • environ ptr -하나하나 뜯어보기-
Kon4
Kon4
Kon4
보안 공부하다, 적어보는 노트
Kon4
전체
오늘
어제
  • 분류 전체보기 (46)
    • Pwnable (34)
      • Tech (25)
      • writeup (8)
    • Browser (2)
      • Chrome (2)
    • Forensic (1)
    • Web (0)
    • Crypto (3)
    • Reversing (2)
    • Windows (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

  • 현재 notion 에서 tistory 로 적어 놨던 자료들⋯

인기 글

태그

최근 댓글

최근 글

hELLO · Designed By 정상우.
Kon4
-Heap- ptmalloc2의 구조
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.