问题说明
C ++服务器在同一堆栈帧中发生了几次崩溃,如下所示
研究
一次崩溃中使用的堆栈空间
(gdb) f 0
#0 0xb717f616 in WDMS_Byte_Stream::write (this=Cannot access memory at
address 0xbfa16b1c) at wdms_bs.cpp:63 in wdms_bs.cpp
(gdb) set $top=$esp
(gdb) f 38
#38 0xb6a1bcbf in main (argc=1, argv=0xbfa5a8b4) at main.cpp:66
main.cpp: No such file or directory.
in main.cpp
(gdb) p $esp-$top
$1 = 277728
(gdb)
堆栈和堆之间的距离 分配内存 enter image description here
靠近堆栈空间的一个堆段,0xb8a8f000-> 0xbf917000 enter image description here
堆栈空间0xbfa18000-> 0xbfa5c000 enter image description here
他们之间的距离 (gdb)p 0xbfa18000- 0xbf917000 $ 3 = 1052672
为什么崩溃
程序需要在最后一帧分配8268字节(0x204c)的堆栈大小 操作系统只将堆栈大小扩展到0xbfa18000,实际大小为 (gdb)p $ esp + 0x204c-0xbfa18000 $ 19 =(void *)0xb4c(2892字节)
所以,执行下一条指令时 调用0xb6a19ec9< __ i686.get_pc_thunk.bx>,需要访问$ esp,这是无法访问的内存空间。
为什么在相同的堆栈帧崩溃?这可能是因为此调用序列具有大多数调用帧并且使用大多数堆栈空间。 enter image description here
问题-1
这是相关的CVE-2017-1000364修复? enter image description here
问题-2
为什么操作系统将堆段分配得如此接近堆栈?它如何避免堆栈和堆冲突而不是分配失败?