Skip to content

Instantly share code, notes, and snippets.

@aghosn
Last active August 8, 2019 19:58
Show Gist options
  • Save aghosn/d6428c96e974fd3ca29bb52b337e621a to your computer and use it in GitHub Desktop.
Save aghosn/d6428c96e974fd3ca29bb52b337e621a to your computer and use it in GitHub Desktop.
Description of linux sgx relocation issue

See => for a relevant entries.

$ readelf -l enclave

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  PHDR           0x0000000000000040 0x0000000000000040 0x0000000000000040
                 0x0000000000000188 0x0000000000000188  R E    0x8
  INTERP         0x00000000000001c8 0x00000000000001c8 0x00000000000001c8
                 0x000000000000000f 0x000000000000000f  R      0x1
      [Requesting program interpreter: /lib/ld64.so.1]
=>LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000d8d24d 0x0000000000d8d24d  R E    0x200000
  LOAD           0x0000000000d8d250 0x0000000000f8d250 0x0000000000f8d250
                 0x00000000003476b0 0x0000000000378138  RW     0x200000
  DYNAMIC        0x0000000000dc9498 0x0000000000fc9498 0x0000000000fc9498
                 0x00000000000001c0 0x00000000000001c0  RW     0x8
  TLS            0x0000000000d8d250 0x0000000000f8d250 0x0000000000f8d250
                 0x0000000000000010 0x0000000000000258  R      0x8
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RWE    0x10

$ readelf -r enclave

  Offset          Info           Type           Sym. Value    Sym. Name + Addend
=>000000b2b0a0  000000000008 R_X86_64_RELATIVE                    1049d0
  000000b2b0a8  000000000008 R_X86_64_RELATIVE                    104a30
  000000b2b0b0  000000000008 R_X86_64_RELATIVE                    15e6a0
  000000b2b158  000000000008 R_X86_64_RELATIVE                    1049d0
...

Before the fist call to CLoader::set_memory_protection(false)

$ cat /proc/PID/maps

  7fb53fc00000-7fb540000000 rw-p 00000000 00:00 0 
  7fb560000000-7fb560b2b000 r-xs 00000000 00:3c 66754105                   /dev/isgx
=>7fb560b2b000-7fb560b2c000 rwxs 00b2b000 00:3c 66754105                   /dev/isgx
  7fb560b2c000-7fb560b2d000 rwxs 00b2c000 00:3c 66754105                   /dev/isgx
...

After the first call to CLoader::set_memory_protection(false)

  7fb53fc00000-7fb540000000 rw-p 00000000 00:00 0 
  7fb560000000-7fb560b2b000 r-xs 00000000 00:3c 66754105                   /dev/isgx
=>7fb560b2b000-7fb560b2c000 r-xs 00b2b000 00:3c 66754105                   /dev/isgx
  7fb560b2c000-7fb560b2d000 r-xs 00b2c000 00:3c 66754105                   /dev/isgx
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment