RFC Remove in-tree usage of MAP_DENYWRITE
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest7 patches 0 repliesNew
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/7 | binfmt: don't use MAP_DENYWRITE when loading shared libraries via uselib()arch/ fs/ fs/ | +3 | 0 replies | |
| 2/7 | kernel/fork: factor out atomcially replacing the current MM exe_fileinclude/ kernel/ kernel/ | +36 | 0 replies | |
| 3/7 | kernel/fork: always deny write access to current MM exe_filekernel/ | +34 | 0 replies | |
| 4/7 | binfmt: remove in-tree usage of MAP_DENYWRITEarch/ fs/ fs/ +1 more | +7 | 0 replies | |
| 5/7 | mm: remove VM_DENYWRITEfs/ include/ include/ +5 more | +5 | 0 replies | |
| 6/7 | mm: ignore MAP_DENYWRITE in ksys_mmap_pgoff()include/ mm/ mm/ | +2 | 0 replies | |
| 7/7 | fs: update documentation of get_write_access() and friendsinclude/ | +12 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH RFC 0/7] Remove in-tree usage of MAP_DENYWRITE
This series is based on [1]
[PATCH v1 0/3] perf/binfmt/mm: remove in-tree usage of MAP_EXECUTABLE
and [2]
[PATCH v2] mm, thp: Relax the VM_DENYWRITE constraint on file-backed THPs
This series removes all in-tree usage of MAP_DENYWRITE from the kernel and removes VM_DENYWRITE. We stopped supporting MAP_DENYWRITE for user space applications a while ago because of the chance for DoS. The last renaming user is binfmt binary loading during exec and legacy library loading via uselib().
With this change, MAP_DENYWRITE is effectively ignored throughout the kernel. Although the net change is small, I think the cleanup in mmap() is quite nice.
There are some (minor) user-visible changes with this series, that's why I am flagging this as RFC and cc-ing linux-api:
1. We no longer deny write access to shared libaries loaded via legacy uselib(); this behavior matches modern user space e.g., via dlopen().
2. We no longer deny write access to the elf interpreter after exec completed, treating it just like shared libraries (which it often is).
3. We always deny write access to the file linked via /proc/pid/exe:
sys_prctl(PR_SET_MM_EXE_FILE) will fail if write access to the file cannot be denied, and write access to the file will remain denied until the link is effectivel gone (exec, termination, PR_SET_MM_EXE_FILE) -- just as if exec'ing the file.
I was wondering if we really care about permanently disabling write access to the executable, or if it would be good enough to just disable write access while loading the new executable during exec; but I don't know the history of that -- and it somewhat makes sense to deny write access at least to the main executable. With modern user space -- dlopen() -- we can effectively modify the content of shared libraries while being used.
I'm not 100% sure if the race documented in patch #3 applies (forking while another thread is doing a PR_SET_MM_EXE_FILE), but I assume this is possible.
[1] https://lkml.kernel.org/r/[email protected]
[2] https://lkml.kernel.org/r/[email protected]
David Hildenbrand (7):
binfmt: don't use MAP_DENYWRITE when loading shared libraries via
uselib()
kernel/fork: factor out atomcially replacing the current MM exe_file kernel/fork: always deny write access to current MM exe_file
binfmt: remove in-tree usage of MAP_DENYWRITE
mm: remove VM_DENYWRITE
mm: ignore MAP_DENYWRITE in ksys_mmap_pgoff()
fs: update documentation of get_write_access() and friends
arch/x86/ia32/ia32_aout.c | 8 ++-- fs/binfmt_aout.c | 7 ++-- fs/binfmt_elf.c | 6 +-- fs/binfmt_elf_fdpic.c | 2 +- fs/proc/task_mmu.c | 1 - include/linux/fs.h | 19 +++++---- include/linux/mm.h | 3 +- include/linux/mman.h | 4 +- include/trace/events/mmflags.h | 1 - kernel/events/core.c | 2 - kernel/fork.c | 75 ++++++++++++++++++++++++++++++---- kernel/sys.c | 33 +-------------- lib/test_printf.c | 5 +-- mm/mmap.c | 29 ++----------- mm/nommu.c | 2 - 15 files changed, 98 insertions(+), 99 deletions(-)
Signature · 1 line
2.30.2