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, 23 Oct 2018 22:08:43 +0000 (23:08 +0100)
commit0056cf1db26e4fbfb3ffc8ae69c1c94b13f496c1
treefa2421c50c77d8a2f6032babeebb6a393133801d
parent7a818c71d099cc76315e82f30edeacc482ac9c40
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