热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

堆栈上的内存分配和缓冲区溢出,x86ISA32-AllocationofmemoryonthestackandBufferOverflow,x86ISA32

SoIvebeenlearningaboutBufferOverflowaswellastheProcedureforsavingmemoryontothestac

So I've been learning about Buffer Overflow as well as the Procedure for saving memory onto the stack and ive been bothered/ I dont understand certain conventions. When saving local variables/ arrays why is that we allocate memory from the stack pointer to the base pointer

所以我一直在学习缓冲区溢出以及将内存保存到堆栈的过程,并且我一直困扰/我不理解某些约定。保存局部变量/数组时,为什么我们将堆栈指针中的内存分配给基指针

(array[0] would be closer to the top of the stack and array[1] to array [n-1] would be closer to the base pointer of your frame)

(array [0]将更靠近堆栈顶部,array [1]到array [n-1]将更接近于帧的基本指针)

Why not the other way around? if array[n-1] was allocated towards the stack pointer there would be no threat to the saved registers/ return addresses in the previous frame.

为什么不相反呢?如果将array [n-1]分配给堆栈指针,则不会对前一帧中保存的寄存器/返回地址构成威胁。

I've read the wiki article and the stacks that grow up section, but they assume the return address is there before the buffer is allocated, which would mean the buffer overwrites the return. But shouldnt it be the other way around? Shouldnt the return address be written in the stack only after the local variables are declared?

我已经阅读了wiki文章和成长部分的堆栈,但他们假设在分配缓冲区之前返回地址,这意味着缓冲区会覆盖返回。但不应该是相反的方式吗?只有在声明了局部变量之后,才能将返回地址写入堆栈中吗?

2 个解决方案

#1


2  

The x86 architecture was heavily influenced by Intel 8080, which had a similar stack architecture (one shared call and data stack growing downward). At the time this was seen as a significant advance, given that the 8080's predecessor, the 8008, had a call stack that was built into the CPU and that was only seven levels deep.

x86架构受到英特尔8080的严重影响,英特尔8080具有类似的堆栈架构(一个共享呼叫和数据堆栈向下增长)。当时这被认为是一个重大的进步,因为8080的前身8008有一个内置在CPU中的调用堆栈,只有七个级别。

Intel 8080 was released in 1974. Given that not a lot of stuff was networked (for example, Ethernet was just being developed), potential stack smashing attacks were probably not a major concern. Flexibility, and making good use the of the available RAM, on the other hand, were.

英特尔8080于1974年发布。鉴于没有很多东西被联网(例如,以太网刚刚开发),潜在的堆栈粉碎攻击可能不是主要问题。另一方面,灵活性,并充分利用可用的RAM。

It was much later that stack smashing became a major concern. For example, the first high-quality step-by-step guide was published in 1996.

很久以后,堆栈粉碎成为一个主要问题。例如,第一份高质量的逐步指南于1996年出版。

#2


1  

Historically, stack and heap occupied the same memory space. Heap was allocated from the bottom, while stack from the top. When you overflow... you would just overwrite the other space memory and soon lead to a crash.

从历史上看,堆栈和堆占用了相同的内存空间。堆从底部分配,而堆栈从顶部分配。当你溢出......你只会覆盖其他空间内存并很快导致崩溃。

Nowdays, I believe, it is no longer the case, but the x86 instruction set for managing stack remained so that it consumes memory from top.

我相信,现在已经不再是这样,但是用于管理堆栈的x86指令集依然存在,以至于它从顶层消耗内存。

But arrays are indexed from the bottom. For that reason array[0] is closer to the "top" of the stack (which is below), and array[n-1] is further away.

但阵列是从底部索引的。因此,array [0]更接近堆栈的“顶部”(在下面),而array [n-1]更远。


推荐阅读
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
  • Go语言实现堆排序的详细教程
    本文主要介绍了Go语言实现堆排序的详细教程,包括大根堆的定义和完全二叉树的概念。通过图解和算法描述,详细介绍了堆排序的实现过程。堆排序是一种效率很高的排序算法,时间复杂度为O(nlgn)。阅读本文大约需要15分钟。 ... [详细]
  • 使用圣杯布局模式实现网站首页的内容布局
    本文介绍了使用圣杯布局模式实现网站首页的内容布局的方法,包括HTML部分代码和实例。同时还提供了公司新闻、最新产品、关于我们、联系我们等页面的布局示例。商品展示区包括了车里子和农家生态土鸡蛋等产品的价格信息。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • LeetCode笔记:剑指Offer 41. 数据流中的中位数(Java、堆、优先队列、知识点)
    本文介绍了LeetCode剑指Offer 41题的解题思路和代码实现,主要涉及了Java中的优先队列和堆排序的知识点。优先队列是Queue接口的实现,可以对其中的元素进行排序,采用小顶堆的方式进行排序。本文还介绍了Java中queue的offer、poll、add、remove、element、peek等方法的区别和用法。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • 本文介绍了如何在给定的有序字符序列中插入新字符,并保持序列的有序性。通过示例代码演示了插入过程,以及插入后的字符序列。 ... [详细]
  • 本文讨论了clone的fork与pthread_create创建线程的不同之处。进程是一个指令执行流及其执行环境,其执行环境是一个系统资源的集合。在调用系统调用fork创建一个进程时,子进程只是完全复制父进程的资源,这样得到的子进程独立于父进程,具有良好的并发性。但是二者之间的通讯需要通过专门的通讯机制,另外通过fork创建子进程系统开销很大。因此,在某些情况下,使用clone或pthread_create创建线程可能更加高效。 ... [详细]
  • 本文介绍了一种轻巧方便的工具——集算器,通过使用集算器可以将文本日志变成结构化数据,然后可以使用SQL式查询。集算器利用集算语言的优点,将日志内容结构化为数据表结构,SPL支持直接对结构化的文件进行SQL查询,不再需要安装配置第三方数据库软件。本文还详细介绍了具体的实施过程。 ... [详细]
  • 本文介绍了在go语言中利用(*interface{})(nil)传递参数类型的原理及应用。通过分析Martini框架中的injector类型的声明,解释了values映射表的作用以及parent Injector的含义。同时,讨论了该技术在实际开发中的应用场景。 ... [详细]
  • 本文介绍了一道经典的状态压缩题目——关灯问题2,并提供了解决该问题的算法思路。通过使用二进制表示灯的状态,并枚举所有可能的状态,可以求解出最少按按钮的次数,从而将所有灯关掉。本文还对状压和位运算进行了解释,并指出了该方法的适用性和局限性。 ... [详细]
  • JVM:33 如何查看JVM的Full GC日志
    1.示例代码packagecom.webcode;publicclassDemo4{publicstaticvoidmain(String[]args){byte[]arr ... [详细]
  • 原文地址http://balau82.wordpress.com/2010/02/28/hello-world-for-bare-metal-arm-using-qemu/最开始时 ... [详细]
  • vb.net面试题,请大家帮忙,谢谢。如果需要讲详细一点,那就加我QQ531412815第4题,潜在的错误,这里的错误不是常规错误,属于那种只有在运行是才知道的错误:Catchex ... [详细]
  • html结构 ... [详细]
author-avatar
没有结果的爱请你收好
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有