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)
committerCarsten Schoenert <c.schoenert@t-online.de>
Fri, 21 Jun 2019 16:48:43 +0000 (17:48 +0100)
commitcdd1614f2b5029a37574010c19351397327a569f
tree2bb461886b63b8f92c507edf574847dd6c754830
parentccee3bf0b8a3cbca87030ae43dd0ac2da21ca0ed
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