什么是大会%GS [英] What is %gs in Assembly

查看:351
本文介绍了什么是大会%GS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


无效return_input(无效)
{
   字符数组[30];   得到(阵列);
   的printf(%S \\ n,数组);
}

在GCC编译它之后,该函数转换为以下大会code:


推%EBP
MOV%ESP,EBP%
子$ 0x28,ESP%
MOV%GS:0x14的,EAX%
MOV EAX%,-0x4(EBP%)
XOR%EAX,EAX%
LEA -0x22(EBP%),%EAX
MOV EAX%(%ESP)
调用0x8048374
LEA -0x22(EBP%),%EAX
MOV EAX%(%ESP)
调用0x80483a4
MOV -0x4(EBP%),%EAX
XOR%GS:0x14的,EAX%
JE 0x80484ac
调用0x8048394
离开
RET

我不明白两行:


MOV%GS:0x14的,EAX%
XOR%GS:0x14的,EAX%

什么是GS%,而究竟这两行吗?

这是编译命令:


CC -c -m preferred堆栈边界= 2 -ggdb file.c中


解决方案

GS是段寄存器,其在Linux中使用可的这里(它基本上是每个进程的数据使用)。

  MOV%GS:0x14的,EAX%
XOR%GS:0x14的,EAX%

这code是用来验证堆栈未爆炸或被corupted,使用存储在GS + 0x14的金丝雀值,看的

void return_input (void)
{ 
   char array[30]; 

   gets (array); 
   printf("%s\n", array); 
}

After compiling it in gcc, this function is converted to the following Assembly code:

push   %ebp
mov    %esp,%ebp
sub    $0x28,%esp
mov    %gs:0x14,%eax
mov    %eax,-0x4(%ebp)
xor    %eax,%eax
lea    -0x22(%ebp),%eax
mov    %eax,(%esp)
call   0x8048374 
lea    -0x22(%ebp),%eax
mov    %eax,(%esp)
call   0x80483a4 
mov    -0x4(%ebp),%eax
xor    %gs:0x14,%eax
je     0x80484ac 
call   0x8048394 
leave  
ret  

I don't understand two lines:

mov    %gs:0x14,%eax
xor    %gs:0x14,%eax

What is %gs, and what exactly these two lines do?

This is compilation command:

cc -c -mpreferred-stack-boundary=2 -ggdb file.c

解决方案

GS is a segment register, its use in linux can be read up on here (its basically used for per process data).

mov    %gs:0x14,%eax
xor    %gs:0x14,%eax

this code is used to validate that the stack hasn't exploded or been corupted, using a canary value stored at GS+0x14, see this.

这篇关于什么是大会%GS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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