p**********g 发帖数: 9385 | 1 今天被问了一个问题
"When a function call in C will return to wrong place?"
完全不知所云,有谁知道吗? |
l******4 发帖数: 431 | 2 有可能是栈溢出什么的,把保存的现场给改写了,这样函数返回时找不到刚才的PC指针
了?
【在 p**********g 的大作中提到】 : 今天被问了一个问题 : "When a function call in C will return to wrong place?" : 完全不知所云,有谁知道吗?
|
p**********g 发帖数: 9385 | 3 这个”保存的现场“是存在stack里面吗?为啥stack overflow会改写”保存的现场“
呢?
【在 l******4 的大作中提到】 : 有可能是栈溢出什么的,把保存的现场给改写了,这样函数返回时找不到刚才的PC指针 : 了?
|
q*z 发帖数: 13362 | 4 胖胖同学C语言学的还不到家呀
【在 p**********g 的大作中提到】 : 这个”保存的现场“是存在stack里面吗?为啥stack overflow会改写”保存的现场“ : 呢?
|
d*****d 发帖数: 2449 | 5
Before entering a function, the code push the current execution pointer onto
the stack, when it returns from the function, pops the pointer out and
assign it to the execution pointer so that the code can continue from where
it left. If the stack overflows, then it's hard to say where you will end up
with.
Many malicious code deliberately causes stack overflow, and makes the code
to execute what it wants to do.
【在 p**********g 的大作中提到】 : 这个”保存的现场“是存在stack里面吗?为啥stack overflow会改写”保存的现场“ : 呢?
|
p**********g 发帖数: 9385 | 6 惭愧啊!
【在 q*z 的大作中提到】 : 胖胖同学C语言学的还不到家呀
|
B***n 发帖数: 1214 | 7 Great explanation.
stack corruption can also have the same result. For example, a stack string
is written with more bytes than it is declared and as a result, the stack
frame is over-written.
onto
where
up
【在 d*****d 的大作中提到】 : : Before entering a function, the code push the current execution pointer onto : the stack, when it returns from the function, pops the pointer out and : assign it to the execution pointer so that the code can continue from where : it left. If the stack overflows, then it's hard to say where you will end up : with. : Many malicious code deliberately causes stack overflow, and makes the code : to execute what it wants to do.
|
p**********g 发帖数: 9385 | 8 Thanks for the input! Can this happen in C?
string
【在 B***n 的大作中提到】 : Great explanation. : stack corruption can also have the same result. For example, a stack string : is written with more bytes than it is declared and as a result, the stack : frame is over-written. : : onto : where : up
|
P*x 发帖数: 1576 | 9 C是最常见的。
我写过一个中文的讲栈溢出的文章,不过我估计你看英文更方便些。推荐你看一片经典
文章,吧这个问
题解释的很透:"Smashing The Stack For Fun And Profit".
【在 p**********g 的大作中提到】 : Thanks for the input! Can this happen in C? : : string
|
p**********g 发帖数: 9385 | 10 老大,你们是不是每天都干这个活啊?
【在 P*x 的大作中提到】 : C是最常见的。 : 我写过一个中文的讲栈溢出的文章,不过我估计你看英文更方便些。推荐你看一片经典 : 文章,吧这个问 : 题解释的很透:"Smashing The Stack For Fun And Profit".
|
|
|
P*x 发帖数: 1576 | 11 还真是差不多,想不到你也对这个有兴趣。
【在 p**********g 的大作中提到】 : 老大,你们是不是每天都干这个活啊?
|
p**********g 发帖数: 9385 | 12 昨天被人羞辱了,想搞明白他到底想问啥。
看了你推荐的文章的第一段,算是有了一点认识。
有一个问题,为啥buffer要从low memory address
往high memory address写?而不反向写呢?
反向写出现buffer overrun的概率大大降低啊。
【在 P*x 的大作中提到】 : 还真是差不多,想不到你也对这个有兴趣。
|
S**U 发帖数: 7025 | 13 This is why it's called a stack - growing upwards:-) cpu instruction set
implements push/pop by inc/dec. SP this way.
Changing the direction doesn't really help. As long as stack variables are
accessible by pointers, C allows a program to write past it (in the right
direction) to corrupt return address. In short, pointers in C allow a
malicious program to do all kinds of bad things. If you want to avoid it
completely, use a pointer-free language like Java.
【在 p**********g 的大作中提到】 : 昨天被人羞辱了,想搞明白他到底想问啥。 : 看了你推荐的文章的第一段,算是有了一点认识。 : 有一个问题,为啥buffer要从low memory address : 往high memory address写?而不反向写呢? : 反向写出现buffer overrun的概率大大降低啊。
|
p**********g 发帖数: 9385 | 14 我的问题其实跟pix推荐的文章有关。
我明白stack是从high address到low address。那片文章里的例子
是用一个local array来override return pointer。我的问题是
local array如果反向操作,会不会降低buffer overrun的概率?
反向操作是指a[0]存在high address而a[1]存在low address。
【在 S**U 的大作中提到】 : This is why it's called a stack - growing upwards:-) cpu instruction set : implements push/pop by inc/dec. SP this way. : Changing the direction doesn't really help. As long as stack variables are : accessible by pointers, C allows a program to write past it (in the right : direction) to corrupt return address. In short, pointers in C allow a : malicious program to do all kinds of bad things. If you want to avoid it : completely, use a pointer-free language like Java.
|
P*x 发帖数: 1576 | 15 理论上可以,可是实践上不好操作。这个是C编译器的问题。
其实有很多简单的方法的。有一种Stack Protection的技术,是说在call指令前把返回
地址压栈的
时候,压的不是真正的返回地址,而是一个校验码。回头return的时候,系统检查这个
校验码,正确的
话才去把真正的返回地址给你。Windows XP和server2003开始实行了这个技术。
另外还有说强行规定栈不可执行。这样的话你overflow之后,栈里面的shellcode也不
能被执行。
类似的安全防范的技术有很多都已经被实现在现在的操作系统里面了。
现在,栈溢出越来越少了,多的是堆溢出和整数溢出等等。而且现在一般都是IE和PDF
的漏洞,所以动
不动都是JavaScript里面搞Heap Spray,或者是Return Oriented Programing等等。所
以说
操作系统的加固是一个never ending battle。所以第三方的安全提供商才有生计啊。
【在 p**********g 的大作中提到】 : 我的问题其实跟pix推荐的文章有关。 : 我明白stack是从high address到low address。那片文章里的例子 : 是用一个local array来override return pointer。我的问题是 : local array如果反向操作,会不会降低buffer overrun的概率? : 反向操作是指a[0]存在high address而a[1]存在low address。
|
p**********g 发帖数: 9385 | 16 哈哈,谢了!我也算是学了些新知识。
你倒是好员工,时刻不忘为公司作广告。
PDF
【在 P*x 的大作中提到】 : 理论上可以,可是实践上不好操作。这个是C编译器的问题。 : 其实有很多简单的方法的。有一种Stack Protection的技术,是说在call指令前把返回 : 地址压栈的 : 时候,压的不是真正的返回地址,而是一个校验码。回头return的时候,系统检查这个 : 校验码,正确的 : 话才去把真正的返回地址给你。Windows XP和server2003开始实行了这个技术。 : 另外还有说强行规定栈不可执行。这样的话你overflow之后,栈里面的shellcode也不 : 能被执行。 : 类似的安全防范的技术有很多都已经被实现在现在的操作系统里面了。 : 现在,栈溢出越来越少了,多的是堆溢出和整数溢出等等。而且现在一般都是IE和PDF
|