linux系统crash问题练习四:栈溢出

从ulimit的结果知道,系统设定的stack size为8192kbytes,
sh-# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 2293
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 2293
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
sh-#

所以我们写出如下的测试程序来进行测试,
static int g_value = 0;

static void _recursive_test(void)
{
    char s_str[1024] = {0};
   
    while(g_value < 8*1024)
    {
        g_value++;
        _recursive_test();
    }
   
    return;
}

int main(int argc, char *argv[])
{
    _recursive_test();
   
    while(1)
    {
        sleep(1);
    }
   
    exit(0);
}

运行测试程序,test_main程序会崩溃掉,
sh-# ./test_main &
4969
sh-#

从core dump查看callstack,可以看到有一个函数在被递归调用并且系统产生了SIGSEGV信号,
所以从直观上推测有可能是栈溢出引起的段非法访问。
sh-# ./gdb -c ./core_test_main_sig11_pid2491 ./test_main
GNU gdb (GDB) 7.1
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <
http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-linux".
For bug reporting instructions, please see:
<
http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from ./test_main...done.

warning: exec file is newer than core file.
[New Thread 2491]
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.3...(no debugging symbols found)...done.
Loaded symbols for /lib/ld-linux.so.3
Core was generated by `/test_main'.
Program terminated with signal 11, Segmentation fault.
#0  0x401882c0 in memset () from /lib/libc.so.6
(gdb) bt 20
#0  0x401882c0 in memset () from /lib/libc.so.6
#1  0x000083e4 in _recursive_test ()
#2  0x00008400 in _recursive_test ()
#3  0x00008400 in _recursive_test ()
#4  0x00008400 in _recursive_test ()
#5  0x00008400 in _recursive_test ()
#6  0x00008400 in _recursive_test ()
#7  0x00008400 in _recursive_test ()
#8  0x00008400 in _recursive_test ()
#9  0x00008400 in _recursive_test ()
#10 0x00008400 in _recursive_test ()
#11 0x00008400 in _recursive_test ()
#12 0x00008400 in _recursive_test ()
#13 0x00008400 in _recursive_test ()
#14 0x00008400 in _recursive_test ()
#15 0x00008400 in _recursive_test ()
#16 0x00008400 in _recursive_test ()
#17 0x00008400 in _recursive_test ()
#18 0x00008400 in _recursive_test ()
#19 0x00008400 in _recursive_test ()
(More stack frames follow...)
(gdb)

问题:
需要学习进程的虚拟地址空间布局。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值