Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "mov rax, QWORD PTR fs:0x28" assembly instruction do? [duplicate]

Immediately before this instruction is executed fs contains 0x0.

Also I'd like to know how I can read from this memory area in GDB, what would the command for that be?

like image 502
ioctlvoid Avatar asked Jan 19 '13 13:01

ioctlvoid


People also ask

What does FS 0x28 mean assembly?

So what you're seeing is a value loaded at an offset from the value held in the FS register, and not bit manipulation of the contents of the FS register. Specifically what's taking place, is that FS:0x28 on Linux is storing a special sentinel stack-guard value, and the code is performing a stack-guard check.

What is Qword PTR in assembly?

qword ptr is a hint for the assembler to create a move op-code (machine code) using a 64bit constant address. The value that is provided is a 32bit value (8 hex-digits => 8 times a hex-digit/letter => 8 * 4bits => 32bit).


1 Answers

The fs and gs registers in modern OSes like Linux and Windows point to thread-specific and other OS-defined structures. Modifying the segment register is a protected instruction, so only the OS can set these up for you.

This question should help explain what exactly the point to: amd64 fs/gs registers in linux.

The actual value of the fs register isn't an address. It is a selector - an offset into the GDT, that describes what that segment can/cannot be used for. You cannot see what the values of the hidden fs base and limit registers are - they are internal CPU registers that are only updated by writing a new "selector" to fs (at which point the base/limit registers are updated from the GDT).

like image 129
Jonathon Reinhart Avatar answered Nov 15 '22 19:11

Jonathon Reinhart