gpt4 book ai didi

linux - x86-64 架构上的 gnu 汇编 RET 指令失败

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:25:24 25 4
gpt4 key购买 nike

下面的程序会导致段错误。 RET 指令不会恢复系统的返回地址。

使用 gdb 调试 session ,我可以读到返回地址不在堆栈上。在第一条指令 pushq %rbp 之前,%rsp 堆栈指针引用了 0x00000000 地址,该地址不是返回地址并导致了 SEGMENTATION DEFAULT。

在调试 session 中,当我在 _start 标签上设置断点时,要执行的第一条指令不是结语....它是序言。

很明显,系统调用操作没有正确操作堆栈指针,也没有保存返回地址。

我在旧的 32 位平台上没有这个问题。

¿一些想法?提前致谢。

gdb session :

Reading symbols from /home/candido/tutoriales/as_tutorial/examples/basicos_64/nada/ret_fault...done.
(gdb) b _start
Breakpoint 1 at 0x40007c: file ret_fault.s, line 15.
(gdb) run
Starting program: /home/candido/tutoriales/as_tutorial/examples/basicos_64/nada/ret_fault
(gdb) x /x $rsp
0x7fffffffe068: 0x00000000
(gdb)

作为源代码:

###  Simple Prologue Epilogue Module
### System call don't save the RETURN ADDRESS
### Assembling: as -gstabs -o ret_fault.o ret_fault.s
### Linking: ld -o ret_fault ret_fault.o
### Execution: ./ret_fault
### System warning: SEGMENTATION FAULT
### System platform: Linux lur 3.2.0-33-generic #52-Ubuntu SMP x86_64 GNU/Linux
.text
.globl _start
_start:
## Epilogue
pushq %rbp # save calling frame pointer
movq %rsp, %rbp # set called frame pointer
## Prologue
movl $0, %eax # set return value
popq %rbp # restore calling frame pointer
ret # return to system. Get return address from stack and load on RIP register.
.end

最佳答案

您不能使用ret 来结束程序。你可以使用例如。 系统调用:

movq $0x60, %rax
xorq %rdi, %rdi
syscall

关于linux - x86-64 架构上的 gnu 汇编 RET 指令失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13629010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com