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>
Wed, 30 Jan 2019 00:53:01 +0000 (00:53 +0000)
commit5d3990df43f9ad1d8ac805910ac17d57c4f59db9
tree45151fb28e013417949daef8c9738e90bf879cdb
parentd1523a75c96d4796b7d25cdc1c1505e8e6c52ccd
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