Skip to content

aarch64: avoid mprotect(PROT_BTI|PROT_EXEC) [BZ #26831]

Szabolcs Nagy kernel-hardening linux-arm-kernel lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest6 patches 9 repliesIn review
  2. v14 patches 23 repliesSuperseded

Changes in v2 from the cover letter

- [1/6]: New patch that fixes a missed BTI bug found during v2.
- [2-3/6]: New, _dl_map_object_from_fd failure handling improvements, these are independent of the rest of the series.
- [4/6]: Move the note handling to a different place (after l_phdr setup, but before fd is closed).
- [5/6]: Rebased.
- [6/6]: First record errors and only report them later. (this fixes various failure handling issues.)

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6aarch64: Fix missing BTI protection from dependencies [BZ #26926]sysdeps/aarch64/dl-bti.c+17 -42 replies
2/6elf: lose is closely tied to _dl_map_object_from_fdelf/dl-load.c+24 -240 replies
3/6elf: Fix failure handling in _dl_map_object_from_fdelf/dl-load.c+15 -92 replies
4/6elf: Move note processing after l_phdr is updatedelf/dl-load.c+15 -150 replies
5/6elf: Pass the fd to note processingelf/dl-load.c elf/rtld.c sysdeps/aarch64/dl-prop.h +3 more+21 -181 reply
6/6aarch64: Use mmap to add PROT_BTI instead of mprotect [BZ #26831]sysdeps/aarch64/dl-bti.c sysdeps/aarch64/dl-prop.h sysdeps/aarch64/linkmap.h+52 -254 replies

Reviews trailers per patch

2 of 6 patches have a Reviewed-by or Acked-by.

PatchAdhemerval Zanella
1/6
2/6
3/6
4/6
5/6R-b
6/6R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/6] aarch64: avoid mprotect(PROT_BTI|PROT_EXEC) [BZ #26831]

This is v2 of
https://sourceware.org/pipermail/libc-alpha/2020-November/119305.html

To enable BTI support, re-mmap executable segments instead of mprotecting them in case mprotect is seccomp filtered.

I would like linux to change to map the main exe with PROT_BTI when that is marked as BTI compatible. From the linux side i heard the following concerns about this:
- it's an ABI change so requires some ABI bump. (this is fine with me, i think glibc does not care about backward compat as nothing can reasonably rely on the current behaviour, but if we have a new bit in auxv or similar then we can save one mprotect call.)
- in case we discover compatibility issues with user binaries it's better if userspace can easily disable BTI (e.g. removing the mprotect based on some env var, but if kernel adds PROT_BTI and mprotect is filtered then we have no reliable way to remove that from executables. this problem already exists for static linked exes, although admittedly those are less of a compat concern.)
- ideally PROT_BTI would be added via a new syscall that does not interfere with PROT_EXEC filtering. (this does not conflict with the current patches: even with a new syscall we need a fallback.)
- solve it in systemd (e.g. turn off the filter, use better filter):
i would prefer not to have aarch64 (or BTI) specific policy in user code. and there was no satisfying way to do this portably.

Other concerns about the approach:
- mmap is more expensive than mprotect: in my measurements using mmap instead of mprotect is 3-8x slower (and after mmap pages have to be faulted in again), but e.g. the exec time of a program with 4 deps only increases by < 8% due to the 4 new mmaps. (the kernel side resource usage may increase too, i didnt look at that.)
- _dl_signal_error is not valid from the _dl_process_gnu_property hook. The v2 set addresses this problem: i could either propagate the errors up until they can be handled or solve it in the aarch64 backend by first recording failures and then dealing with them in _dl_open_check. I choose the latter, but did some refactorings in _dl_map_object_from_fd that makes the former possible too.

v2:
- [1/6]: New patch that fixes a missed BTI bug found during v2.
- [2-3/6]: New, _dl_map_object_from_fd failure handling improvements, these are independent of the rest of the series.
- [4/6]: Move the note handling to a different place (after l_phdr setup, but before fd is closed).
- [5/6]: Rebased.
- [6/6]: First record errors and only report them later. (this fixes various failure handling issues.)

Szabolcs Nagy (6):
aarch64: Fix missing BTI protection from dependencies [BZ #26926]
elf: lose is closely tied to _dl_map_object_from_fd
elf: Fix failure handling in _dl_map_object_from_fd
elf: Move note processing after l_phdr is updated
elf: Pass the fd to note processing
aarch64: Use mmap to add PROT_BTI instead of mprotect [BZ #26831]

 elf/dl-load.c              | 110 ++++++++++++++++++++-----------------
 elf/rtld.c                 |   4 +-
 sysdeps/aarch64/dl-bti.c   |  74 ++++++++++++++++++-------
 sysdeps/aarch64/dl-prop.h  |  14 +++--
 sysdeps/aarch64/linkmap.h  |   2 +-
 sysdeps/generic/dl-prop.h  |   6 +-
 sysdeps/generic/ldsodefs.h |   5 +-
 sysdeps/x86/dl-prop.h      |   6 +-
 8 files changed, 135 insertions(+), 86 deletions(-)
Signature · 1 line
2.17.1