Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a logical address with an FS or GS base in gdb?

gdb provides functionality to read or write to a specific linear address, for example:

(gdb) x/1wx 0x080483e4
0x80483e4 <main>:       0x83e58955
(gdb) 

but how do you specify a logical address ? I came accross the following instruction:

   0x0804841a <+6>:     mov    %gs:0x14,%eax

how can i read the memory at "%gs:0x14" in gdb, or translate this logical address to a linear address that i could use in x command ?

note: i know that i could simply read %eax after this instruction, but that is not my concern

like image 678
user368507 Avatar asked Apr 27 '12 16:04

user368507


People also ask

What is FS and GS?

The registers FS and GS are segment registers. They have no processor-defined purpose, but instead are given purpose by the OS's running them. In Windows 64-bit the GS register is used to point to operating system defined structures. FS and GS are commonly used by OS kernels to access thread-specific memory.

What does GS mean in assembly?

GS is a segment register, its use in linux can be read up on here (its basically used for per thread data). mov %gs:0x14,%eax xor %gs:0x14,%eax. this code is used to validate that the stack hasn't exploded or been corrupted, using a canary value stored at GS+0x14, see this.

What is FS register used for in Linux?

On the x86-64 architecture, two registers have a special purpose: FS and GS. In linux 2.6. *, the FS register seem to be used to store thread-local information.


2 Answers

As answered in Using GDB to read MSRs, this is possible with gdb 8, using the registers $fs_base and $gs_base.

like image 83
ObsequiousNewt Avatar answered Oct 21 '22 18:10

ObsequiousNewt


I think the easiest way to do this is to read the content of EAX register as you can see the value of %gs:0x14 is moved to EAX.

In GDB, set a breakpoint at the address right after 0x0804841a with break. For example

break *0x0804841e

Then run the program and you can print the contents of EAX register with

info registers eax
like image 21
Thien Phan Avatar answered Oct 21 '22 18:10

Thien Phan