为什么堆栈不向上增长(为了安全)? [英] Why don't stacks grow upwards (for security)?

查看:23
本文介绍了为什么堆栈不向上增长(为了安全)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与问题为什么栈通常向下增长?"有关a>,但更多是从安全角度考虑.我一般指的是 x86.

This is related to the question 'Why do stacks typically grow downwards?', but more from a security point of view. I'm generally referring to x86.

当缓冲区通常在内存中向上写入时,堆栈会向下增长,这让我感到奇怪.例如,典型的 C++ 字符串的结尾比开头的内存地址高.

It strikes me as odd that the stack would grow downwards, when buffers are usually written to upwards in memory. For example a typical C++ string has its end at a higher memory address than the beginning.

这意味着如果出现缓冲区溢出,您将进一步覆盖调用堆栈,我认为这是一个安全风险,因为它可能会更改返回地址和局部变量内容.

This means that if there's a buffer overflow you're overwriting further up the call stack, which I understand is a security risk, since it opens the possibility of changing return addresses and local variable contents.

如果堆栈在内存中向上增长,缓冲区溢出不会简单地运行到死内存中吗?这会提高安全性吗?如果是,为什么没有完成?x64 怎么样,这些堆栈是否向上增长,如果不是为什么不增长?

If the stack grew upwards in memory, wouldn't buffer overflows simply run in to dead memory? Would this improve security? If so, why hasn't it been done? What about x64, do those stacks grow upwards and if not why not?

推荐答案

从技术上讲,这取决于 OS/CPU,但通常这是因为堆栈和堆以相反的方向和地址空间的两端增长.

Technically this is OS/CPU dependant, but typically this is because the stack and heap grow in opposite directions and from opposite ends of the address space.

这种安排为您在堆和堆栈之间拆分/分配内存提供了最大的灵活性,而不会导致它们发生冲突.如果它们都朝同一个方向增长,那么您将需要一个堆栈的起始地址,该地址将硬限制堆的最大大小(以及对堆栈大小的硬限制)

This arrangement gives you the most flexibility to split/allocate memory between the heap and the stack without causing them to collide. If they were both to grow in the same direction, then you would need to have a starting address for the stack that would put a hard limit the maximum size of the heap (and a hard limit on the size of the stack)

预计到达时间:

在维基百科上找到了一个 有趣的文章,关于为什么使堆栈向上增长并不一定防止堆栈溢出 - 只是让它们的工作方式有所不同.

Found an interesting piece on wikipedia about why making a stack grow upwards does not necessarily prevent stack overflows - it just makes them work a bit differently.

这篇关于为什么堆栈不向上增长(为了安全)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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