gcc does not apply partial relro

1

I tried compile C source code to apply Partial RELRO, enabling PIE and disabling NX but failed.

Steps to reproduce

I used checksec script to check RELRO option of the binary.

wisedier@ubuntu:~$ gcc --version
gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
wisedier@ubuntu:~$ uname -a
Linux ubuntu 4.15.0-46-generic #49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
wisedier@ubuntu:~$ cat test.c
void main(){}
wisedier@ubuntu:~$ gcc -fPIE -pie -z execstack -Wl,-z,relro -o partial test.c
wisedier@ubuntu:~$ gcc -fPIE -pie -z execstack -Wl,-z,relro -Wl,-z,now -o full test.c
wisedier@ubuntu:~$ objdump -h full > full.log
wisedier@ubuntu:~$ objdump -h partial > partial.log
wisedier@ubuntu:~$ diff full.log partial.log
2c2
< full:     file format elf64-x86-64
---
> partial:     file format elf64-x86-64
wisedier@ubuntu:~$ checksec --file full
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH  Symbols     FORTIFY Fortified   Fortifiable  FILE
Full RELRO      No canary found   NX disabled   PIE enabled     No RPATH   No RUNPATH   66 Symbols     No   0       0   full

wisedier@ubuntu:~$ checksec --file partial
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH  Symbols     FORTIFY Fortified   Fortifiable  FILE
Full RELRO      No canary found   NX disabled   PIE enabled     No RPATH   No RUNPATH   66 Symbols     No   0       0   partial

What is the expected correct behavior?

I expected the result of checksec for the binary compiled with partial RELRO option shows Partial RELRO and there are some differences between objdump results.

Do I missed something? If you know a solution to get partial RELRO binary or related information, please let me know.

junsang

Posted 2019-03-25T13:48:34.970

Reputation: 11

Answers

1

It seems that's if you force the PIE protection (as the default in ubuntu 18.04) it forces full RELRO too. So set -no-pie option instead of -fPIE -pie

gwel

Posted 2019-03-25T13:48:34.970

Reputation: 11

Add more detail what this does and explain. – Pimp Juice IT – 2019-10-19T21:51:49.753

Without PIE option, the compiler applies Full RELRO with partial RELRO options. – junsang – 2019-10-22T07:09:06.907