Bug 1470701 - Use run-time page size when changing mapping permissions in elfhack...
authorMike Hommey <mh@glandium.org>
Sun, 24 Jun 2018 00:02:38 +0000 (09:02 +0900)
committerMike Hommey <glandium@debian.org>
Tue, 9 Jul 2019 22:13:23 +0000 (23:13 +0100)
commitafb7305b258cb655341583bbf06faf7083998021
tree09156dec7aebe2fee58477fbcb68fc9b22827376
parenta171a59e9e016d89c0c05d02b1aa6285e1c06f63
Bug 1470701 - Use run-time page size when changing mapping permissions in elfhack injected code. r?froydnj

When a binary has a PT_GNU_RELRO segment, the elfhack injected code
uses mprotect to add the writable flag to relocated pages before
applying relocations, removing it afterwards. To do so, the elfhack
program uses the location and size of the PT_GNU_RELRO segment, and
adjusts it to be aligned according to the PT_LOAD alignment.

The problem here is that the PT_LOAD alignment doesn't necessarily match
the actual page alignment, and the resulting mprotect may end up not
covering the full extent of what the dynamic linker has protected
read-only according to the PT_GNU_RELRO segment. In turn, this can lead
to a crash on startup when trying to apply relocations to the still
read-only locations.

Practically speaking, this doesn't end up being a problem on x86, where
the PT_LOAD alignment is usually 4096, which happens to be the page
size, but on Debian armhf, it is 64k, while the run time page size can be
4k.

Gbp-Pq: Topic fixes
Gbp-Pq: Name Bug-1470701-Use-run-time-page-size-when-changing-map.patch
build/unix/elfhack/elfhack.cpp
build/unix/elfhack/inject.c
build/unix/elfhack/test.c