S
S
Stanislav Timoshko2020-11-21 23:28:54
assembler
Stanislav Timoshko, 2020-11-21 23:28:54

Why doesn't assembler code throw a segmentation fault?

The simplest code is written:

section .data
des     dq       0xffffffffffffffff
section .text
global _start
_start:
mov     qword   [des], 4
mov rax, 1
mov rbx, 0
int 0x80

The first command (mov qword [des], 4) is supposed to write 4 to memory at address 0xffffffffffffffff, which I think should cause a segmentation fault, but in the end the program ends successfully. Why is this happening? Is the variable being dereferenced correctly?([des]).

[[email protected] exploits]# ./a.out
[[email protected] exploits]#

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
G
galaxy, 2020-11-22
@MooTs

I already forgot the Intel syntax of the assembler, but mov qword [des]it mov qword des's the same thing. Operands in x86/x64 can be of type immediate, register and memory (I think it's clear what I'm talking about). You can only dereference operands of type register and immediate, so there would be a segfault on:

mov qword [0xffffffffffffffff], 4

или

mov rax, offset des ; вроде такой синтаксис
mov qword [rax], 4

S
Saboteur, 2020-11-22
@saboteur_kiev

IMHO a 32-bit address is implied, so only the first 4 bytes are taken from des and 4 are entered at address 0xffffffff

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question