你好,我按照你的过程进行调试,但第一步的结果和你的不一样,释放后的chunk没有放入fast bin管理,调试研究了三天了都没找到问题,能不能帮我看一下?
一. 我按照你帖子中的,先创建4个fast chunk,再创建一个small chunk,然后把第1个fast chunk释放:
alloc(0x10)
alloc(0x10)
alloc(0x10)
alloc(0x10)
alloc(0x80)
free(1)
此时的内存如下(和你帖子里的基本是一样的):
gdb-peda$ x/40wx 0x555555757260-0x10
0x555555757250: 0x00000000 0x00000000 0x00000021 0x00000000 <--- chunk 0 (fastbin, in use)
0x555555757260: 0x00000000 0x00000000 0x00000000 0x00000000
0x555555757270: 0x00000000 0x00000000 0x00000021 0x00000000 <--- chunk 1 (fastbin, free)
0x555555757280: 0x00000000 0x00000000 0x00000000 0x00000000
0x555555757290: 0x00000000 0x00000000 0x00000021 0x00000000 <--- chunk 2 (fastbin, in use)
0x5555557572a0: 0x00000000 0x00000000 0x00000000 0x00000000
0x5555557572b0: 0x00000000 0x00000000 0x00000021 0x00000000 <--- chunk 3 (fastbin, in use)
0x5555557572c0: 0x00000000 0x00000000 0x00000000 0x00000000
0x5555557572d0: 0x00000000 0x00000000 0x00000091 0x00000000 <--- chunk 4 (smallbin, in use)
0x5555557572e0: 0x00000000 0x00000000 0x00000000 0x00000000
这个时候我查看main_arena,在fast bins里并没有找到chunk1:
gdb-peda$ x/20wx &main_arena
0x7ffff7fa8c40 <main_arena>: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff7fa8c50 <main_arena+16>: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff7fa8c60 <main_arena+32>: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff7fa8c70 <main_arena+48>: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff7fa8c80 <main_arena+64>: 0x00000000 0x00000000 0x00000000 0x00000000
gdb-peda$ p main_arena
$1 = {
mutex = 0x0,
flags = 0x0,
have_fastchunks = 0x0,
fastbinsY = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
top = 0x555555757360, (top chunk)
last_remainder = 0x0,
bins = {0x7ffff7fa8ca0 <main_arena+96>, 0x7ffff7fa8ca0 <main_arena+96>,
0x7ffff7fa8cb0 <main_arena+112>, 0x7ffff7fa8cb0 <main_arena+112>,
二. 然后我再释放chunk2, free(2),释放后的内存如下:
gdb-peda$ x/40wx 0x555555757260-0x10
0x555555757250: 0x00000000 0x00000000 0x00000021 0x00000000 <--- chunk 0 (fastbin, in use)
0x555555757260: 0x00000000 0x00000000 0x00000000 0x00000000
0x555555757270: 0x00000000 0x00000000 0x00000021 0x00000000 <--- chunk 1 (fastbin, free)
0x555555757280: 0x00000000 0x00000000 0x00000000 0x00000000
0x555555757290: 0x00000000 0x00000000 0x00000021 0x00000000 <--- chunk 2 (fastbin, free)
0x5555557572a0: 0x55757280 0x00005555 0x00000000 0x00000000
0x5555557572b0: 0x00000000 0x00000000 0x00000021 0x00000000 <--- chunk 3 (fastbin, in use)
0x5555557572c0: 0x00000000 0x00000000 0x00000000 0x00000000
0x5555557572d0: 0x00000000 0x00000000 0x00000091 0x00000000 <--- chunk 4 (smallbin, in use)
0x5555557572e0: 0x00000000 0x00000000 0x00000000 0x00000000
因为是先free(1),再free(2),所以fast bin的头接点应该是chunk2,chunk2的fd指向chunk1,看上面的内存确实有点像,但是chunk2的fd应该是0x555555757270的呀,为什么是0x555555757280了,差了0x10,不明白。
而且这个时候再查看main_arena,发现fastbins里还是空的,要哭了:
gdb-peda$ x/20wx &main_arena
0x7ffff7fa8c40 <main_arena>: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff7fa8c50 <main_arena+16>: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff7fa8c60 <main_arena+32>: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff7fa8c70 <main_arena+48>: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff7fa8c80 <main_arena+64>: 0x00000000 0x00000000 0x00000000 0x00000000
gdb-peda$ p main_arena
$2 = {
mutex = 0x0,
flags = 0x0,
have_fastchunks = 0x0,
fastbinsY = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
top = 0x555555757360, (top chunk)
last_remainder = 0x0,
bins = {0x7ffff7fa8ca0 <main_arena+96>, 0x7ffff7fa8ca0 <main_arena+96>,
0x7ffff7fa8cb0 <main_arena+112>, 0x7ffff7fa8cb0 <main_arena+112>,
0x7ffff7fa8cc0 <main_arena+128>, 0x7ffff7fa8cc0 <main_arena+128>,
0x7ffff7fa8cd0 <main_arena+144>, 0x7ffff7fa8cd0 <main_arena+144>,
三. 我再尝试申请一个大小为0x10的fast chunk,alloc(0x10),按照fast bin的特性,应该是返回刚刚释放的chunk2,但结果并不是这样的,而是从top chunk里分隔出一个新的chunk返回了。
此时的内存如下:
gdb-peda$ x/80wx 0x555555757260-0x10
0x555555757250: 0x00000000 0x00000000 0x00000021 0x00000000 <--- chunk 0 (fastbin, in use)
0x555555757260: 0x00000000 0x00000000 0x00000000 0x00000000
0x555555757270: 0x00000000 0x00000000 0x00000021 0x00000000 <--- chunk 1 (fastbin, free)
0x555555757280: 0x00000000 0x00000000 0x00000000 0x00000000
0x555555757290: 0x00000000 0x00000000 0x00000021 0x00000000 <--- chunk 2 (fastbin, free)
0x5555557572a0: 0x55757280 0x00005555 0x00000000 0x00000000
0x5555557572b0: 0x00000000 0x00000000 0x00000021 0x00000000 <--- chunk 3 (fastbin, in use)
0x5555557572c0: 0x00000000 0x00000000 0x00000000 0x00000000
0x5555557572d0: 0x00000000 0x00000000 0x00000091 0x00000000 <--- chunk 4 (smallbin, in use)
0x5555557572e0: 0x00000000 0x00000000 0x00000000 0x00000000
0x5555557572f0: 0x00000000 0x00000000 0x00000000 0x00000000
0x555555757300: 0x00000000 0x00000000 0x00000000 0x00000000
0x555555757310: 0x00000000 0x00000000 0x00000000 0x00000000
0x555555757320: 0x00000000 0x00000000 0x00000000 0x00000000
0x555555757330: 0x00000000 0x00000000 0x00000000 0x00000000
0x555555757340: 0x00000000 0x00000000 0x00000000 0x00000000
0x555555757350: 0x00000000 0x00000000 0x00000000 0x00000000
0x555555757360: 0x00000000 0x00000000 0x00000021 0x00000000 <--- chunk 5 (fastbin, in use)
0x555555757370: 0x00000000 0x00000000 0x00000000 0x00000000
0x555555757380: 0x00000000 0x00000000 0x00020c81 0x00000000
此时的main_arena如下:
gdb-peda$ x/20wx &main_arena
0x7ffff7fa8c40 <main_arena>: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff7fa8c50 <main_arena+16>: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff7fa8c60 <main_arena+32>: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff7fa8c70 <main_arena+48>: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff7fa8c80 <main_arena+64>: 0x00000000 0x00000000 0x00000000 0x00000000
gdb-peda$ p main_arena
$4 = {
mutex = 0x0,
flags = 0x0,
have_fastchunks = 0x0,
fastbinsY = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
top = 0x555555757380,
last_remainder = 0x0,
bins = {0x7ffff7fa8ca0 <main_arena+96>, 0x7ffff7fa8ca0 <main_arena+96>,
0x7ffff7fa8cb0 <main_arena+112>, 0x7ffff7fa8cb0 <main_arena+112>,
0x7ffff7fa8cc0 <main_arena+128>, 0x7ffff7fa8cc0 <main_arena+128>,
0x7ffff7fa8cd0 <main_arena+144>, 0x7ffff7fa8cd0 <main_arena+144>,
0x7ffff7fa8ce0 <main_arena+160>, 0x7ffff7fa8ce0 <main_arena+160>,
0x7ffff7fa8cf0 <main_arena+176>, 0x7ffff7fa8cf0 <main_arena+176>,
整个过程中fast bin好像并没有生效,好奇怪,求指导~
最后于 2019-1-1 15:23
被liuxucau编辑
,原因: 错别字