***检测到堆栈砸碎***:<未知>已终止中止(核心转储)仅在有时出现错误? [英] *** stack smashing detected ***: <unknown> terminated Aborted (core dumped) Error only occurring sometimes?

查看:139
本文介绍了***检测到堆栈砸碎***:<未知>已终止中止(核心转储)仅在有时出现错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在完成一项作业(因此,我无法发布代码),而且我很少遇到此运行时错误:

I am completing a homework assignment (I can't post the code because of this), and I get this runtime error very infrequently:

*检测到堆栈粉碎** :已终止已中止(核心已弃用)

* stack smashing detected *: terminated Aborted (core dumped)

当我之后再次运行可执行文件时,一切正常.为什么有时仅出现此错误,这是有原因的吗?作为参考,我要完成的任务是让我们将文件中的数据加载到两个向量中,并对数据进行二进制和线性搜索,以查看向量1中的数据是否出现在向量2中.

When I run the executable again after, and everything works fine. Is there a reason why this error only shows up sometimes? For reference, the assignment I am trying to complete has us loading data from files into two vectors, and conducting binary and linear searches on the data, to see if a data from vector 1 appears in vector 2.

谢谢!

附加信息:当我收到此错误时,关于输入数据的任何更改都没有.我可以使用完全相同的输入数据运行完全相同的可执行文件,并使其运行一次,再运行一次,获得堆栈粉碎错误,然后运行完全相同的事物,并使它再次正常运行.

Additional info: When I am getting this error, nothing about the input data changes. I could run the exact same executable, with the exact same input data one time and have it work, run it a second time, get the stack smashing error, and then run the exact same thing, and have it work fine again.

推荐答案

***检测到堆栈粉碎问题*** 错误发生,顾名思义,您粉碎了堆栈,这意味着缓冲区溢出并且 canary 被另一个值覆盖.这是gcc/g ++实施的一种安全机制,可以防止使用 -fstack-protector 的缓冲区溢出漏洞.

*** stack smashing detected *** error occurs when as the name suggests, you smash the stack, meaning that you have a buffer overflow and the canary gets overwritten by a different value. This is a security mechanism implemented by gcc/g++ to prevent buffer overflow exploits using -fstack-protector.

为避免此错误,请在使用

To avoid this error, disable fstack-protector in gcc while compiling the code using

g++ myProgram.c -o myProgram -fno-stack-protector

编辑1
但是,禁用堆栈保护会消除此错误,但是由于覆盖堆栈,您可能会遇到 segmentation fault .

如果这是您要进行缓冲区溢出攻击的计算机安全任务,那么您需要弄清楚这些安全机制,如果您不熟悉它,那么您就以某种方式溢出了缓冲区,而没有查看代码我无法对问题的确切位置发表过多评论.

If it is a computer security assignment where you are working on a buffer overflow exploit then you need to figure out to bybass these security mechanism, if you are not familiar with it, then somehow you are overflowing buffer and without looking at code I can't comment much where exactly the problem is.

以查看向量2中是否出现了向量1中的数据 .该错误并不始终如一的事实,因为有时金丝雀不会被覆盖(程序的精细运行)或被相同的确切值覆盖,有时金丝雀会被不同的值覆盖,从而导致此错误.

to see if a data from vector 1 appears in vector 2 this indeed seems like buffer overflow kind of assignment where you are required to overwrite contents of arrays from one another. The fact this error is not consistent because sometimes the canary does not get overwritten (fine run of program) or overwritten by the same exact value and sometimes the canary gets overwritten with a different value leading to this error.

您需要配置编译器以使其更容易发生缓冲区溢出.

You need to configure your compiler to make it easier for buffer overflow.

编辑2

您的程序行为是随机的,因为您可能尚未禁用ASLR(地址空间布局随机化).编译程序时,编译器gcc/g ++会针对安全性机制优化可执行文件,以防止缓冲区溢出漏洞.

Your program behaviour is random because probably you have not disabled ASLR (Address space layout randomization). When you compile your program your compiler gcc/g++ optimize your executable for security mechanisms to prevent buffer overflow exploits.

地址空间布局随机化(ASLR)是一种计算机安全技术,可防止利用内存损坏漏洞.为了防止攻击者可靠地跳转到内存中的某个特定漏洞利用功能,ASLR随机排列进程的关键数据区域的地址空间位置,包括可执行文件的基础以及堆栈,堆的位置和图书馆.

Address space layout randomization (ASLR) is a computer security technique involved in preventing exploitation of memory corruption vulnerabilities. In order to prevent an attacker from reliably jumping to, for example, a particular exploited function in memory, ASLR randomly arranges the address space positions of key data areas of a process, including the base of the executable and the positions of the stack, heap and libraries.

这意味着地址空间分配是随机的,向量之间的字节每次都不同.有时,溢出的缓冲区没有到达金丝雀,有时到达了.为了每次都能获得一致的行为,还需要禁用ASLR.您的操作系统提供了ASLR支持.要禁用ASLR,在Linux上,可以通过将 randomize_va_space 设置为0来禁用它.

It means the address space allocation is random and the bytes between your vectors is different every time. Sometimes the overflown buffer does not reaches to canary and sometimes it does. To get the consistent behaviour every time, you need to disable ASLR as well. ASLR support is provided by your OS. To disable ASLR, on linux it is disabled by setting randomize_va_space to 0. It can be achieved by

echo 0 > /proc/sys/kernel/randomize_va_space

这篇关于***检测到堆栈砸碎***:<未知>已终止中止(核心转储)仅在有时出现错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆