Time to enable partial relro

Ed Schouten ed at nuxi.nl
Fri Aug 26 14:35:43 UTC 2016


2016-08-26 16:18 GMT+02:00 Warner Losh <imp at bsdimp.com>:
>> GNU RELRO support was committed in r230784 (2012-01-30) but we never enabled
>> it by default.
>
> So what's the summary of why we'd want to do that? What benefit does it bring?
> Sure, other folks do it, but why?

In a nutshell:

ELF files that contain relocations (shared libraries, dynamically
linked and/or position-independent executables) typically contain
pages of memory that can be marked read-only (i.e., they only contain
constants). Unfortunately, they had to be marked for writing, for the
reason that rtld had to walk over them to apply the relocations on
startup. GNU added an extension to their linker, making it group
together all of such constants in consecutive pages, while also making
it add a special record to the ELF file (RELRO). This record can be
used by rtld to mprotect(PROT_READ) the range after relocating is
finished.

In other words, it means that global constants actually become
constant again. It makes it easier to detect programming mistakes
(accidentally discarding const qualifiers and writing).

-- 
Ed Schouten <ed at nuxi.nl>
Nuxi, 's-Hertogenbosch, the Netherlands
KvK-nr.: 62051717


More information about the freebsd-toolchain mailing list