I'm debugging an ELF 64-bit binary using gdb and I notice that the %fs register is set to 0x63. For some testing that I'd like to perform I'd like to set the %fs register to 0x00.

I tried doing a set $fs=0x0 but the value wouldn't change. In some cases I got a:

Couldn't write registers: Input/output error.

Is there any way I could set the value for the %fs register? I'm also open to modifying the binary, adding inline assembly to the source, etc.

EDIT : Currently, I'm trying this out by attaching to a process rather than running it from within gdb.

A screenshot to illustrate the problem : enter image description here

1 Answer 1


Low 2 bits have to be set or you will get an EIO error. Only the low 16 bits manage to get set anyways.

Snippet from arch/x86_64/kernel/ptrace.c:

case offsetof(struct user_regs_struct,fs):
    if (value && (value & 3) != 3)
        return -EIO;
    child->thread.fsindex = value & 0xffff; 
    return 0;

That said, setting to 0x00 shouldn't be problematic per the code and per my testing.

(gdb) set $fs=3
(gdb) info register fs
fs             0x3      3
(gdb) set $fs=1
Couldn't write registers: Input/output error.
(gdb) set $fs=0
(gdb) info register fs
fs             0x0      0
(gdb) set $fs=0xffffffff
(gdb) info register fs
fs             0xffff   65535
  • would this behavior vary if a process were being traced?
    – user1743
    Apr 15, 2014 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.