Skip to content

Remove in-tree usage of MAP_DENYWRITE

David Hildenbrand linux-api linux-fsdevel linux-mm linux-unionfs lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest7 patches 10 repliesIn review
  2. v17 patches 76 repliesSuperseded

Changes in v2 from the cover letter

- "kernel/fork: factor out replacing the current MM exe_file" -- Call the function "replace_mm_exe_file()" instead
-- Add some doc, similar to set_mm_exe_file()
-- Update patch subject/description
- "kernel/fork: always deny write access to current MM exe_file" -- Introduce dup_mm_exe_file()
-- Make set_mm_exe_file() return an error to make the code easier to
grasp.
-- Improve comments
- Added ACKs
- Mention "sys_prctl(PR_SET_MM_MAP/EXE_FILE)" everywhere instead of only "sys_prctl(PR_SET_MM_EXE_FILE)".

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7binfmt: don't use MAP_DENYWRITE when loading shared libraries via uselib()arch/x86/ia32/ia32_aout.c fs/binfmt_aout.c fs/binfmt_elf.c+3 -33 replies
2/7kernel/fork: factor out replacing the current MM exe_fileinclude/linux/mm.h kernel/fork.c kernel/sys.c+43 -354 replies
3/7kernel/fork: always deny write access to current MM exe_filefs/exec.c include/linux/mm.h kernel/fork.c+48 -80 replies
4/7binfmt: remove in-tree usage of MAP_DENYWRITEarch/x86/ia32/ia32_aout.c fs/binfmt_aout.c fs/binfmt_elf.c +1 more+7 -100 replies
5/7mm: remove VM_DENYWRITEfs/proc/task_mmu.c include/linux/mm.h include/linux/mman.h +5 more+5 -360 replies
6/7mm: ignore MAP_DENYWRITE in ksys_mmap_pgoff()include/linux/mman.h mm/mmap.c mm/nommu.c+2 -50 replies
7/7fs: update documentation of get_write_access() and friendsinclude/linux/fs.h+12 -70 replies

Reviews trailers per patch

All 7 patches have a Reviewed-by or Acked-by.

PatchEric W. BiedermanChristian Brauner
1/7A-b
2/7A-b A-b
3/7A-b
4/7A-b
5/7A-b
6/7A-b
7/7A-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/7] Remove in-tree usage of MAP_DENYWRITE

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 (well, we actually add code and comments), I think the cleanup in mmap() is quite nice.

There are some (minor) user-visible changes with this series:
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_MAP/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, sys_prctl(PR_SET_MM_MAP/EXE_FILE)) -- just as if exec'ing the file.

There is a related problem [2] with overlayfs, that should at least partly be tackled by this series. I don't quite understand the interaction of overlayfs and deny_write_access()/allow_write_access() at exec time:

If we end up denying write access to the wrong file and not to the realfile, that would be fundamentally broken. We would have to reroute our deny_write_access()/ allow_write_access() calls for the exec file to the realfile -- but I leave figuring out the details to overlayfs guys, as that would be a related but different issue.

There was a lengthy discussion in [3] whether to remove deny_write_access() completely; however, if we decide to go that way, it would ideally be done on top, because it could be that some applications even rely on the current behavior.

v1 -> v2:
- "kernel/fork: factor out replacing the current MM exe_file" -- Call the function "replace_mm_exe_file()" instead
-- Add some doc, similar to set_mm_exe_file()
-- Update patch subject/description
- "kernel/fork: always deny write access to current MM exe_file" -- Introduce dup_mm_exe_file()
-- Make set_mm_exe_file() return an error to make the code easier to
grasp.
-- Improve comments
- Added ACKs
- Mention "sys_prctl(PR_SET_MM_MAP/EXE_FILE)" everywhere instead of only "sys_prctl(PR_SET_MM_EXE_FILE)".

RFC -> v1:
- "binfmt: remove in-tree usage of MAP_DENYWRITE"
-- Add a note that this should fix part of a problem with overlayfs

[1] https://lore.kernel.org/r/[email protected]/
[2] https://lore.kernel.org/r/[email protected]/
[3] https://lkml.kernel.org/r/[email protected]

Cc Linus Torvalds <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Alexander Viro <[email protected]>
Cc Alexey Dobriyan <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Petr Mladek <[email protected]>
Cc Sergey Senozhatsky <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Rasmus Villemoes <[email protected]>
Cc Kees Cook <[email protected]>
Cc "Eric W. Biederman" <[email protected]>
Cc Greg Ungerer <[email protected]>
Cc Geert Uytterhoeven <[email protected]>
Cc Mike Rapoport <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Vincenzo Frascino <[email protected]>
Cc Chinwen Chang <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc "Matthew Wilcox (Oracle)" <[email protected]>
Cc Huang Ying <[email protected]>
Cc Jann Horn <[email protected]>
Cc Feng Tang <[email protected]>
Cc Kevin Brodsky <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Shawn Anastasio <[email protected]>
Cc Steven Price <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Jens Axboe <[email protected]>
Cc Gabriel Krisman Bertazi <[email protected]>
Cc Peter Xu <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Shakeel Butt <[email protected]>
Cc Marco Elver <[email protected]>
Cc Daniel Jordan <[email protected]>
Cc Nicolas Viennot <[email protected]>
Cc Thomas Cedeno <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Miklos Szeredi <[email protected]>
Cc Chengguang Xu <[email protected]>
Cc "Christian König" <[email protected]>
Cc Florian Weimer <[email protected]>
Cc Al Viro <[email protected]>
Cc David Laight <[email protected]>

David Hildenbrand (7):
binfmt: don't use MAP_DENYWRITE when loading shared libraries via
uselib()
kernel/fork: factor out 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/exec.c                      |  4 +-
 fs/proc/task_mmu.c             |  1 -
 include/linux/fs.h             | 19 ++++---
 include/linux/mm.h             |  4 +-
 include/linux/mman.h           |  4 +-
 include/trace/events/mmflags.h |  1 -
 kernel/events/core.c           |  2 -
 kernel/fork.c                  | 95 ++++++++++++++++++++++++++++++----
 kernel/sys.c                   | 33 +-----------
 lib/test_printf.c              |  5 +-
 mm/mmap.c                      | 29 ++---------
 mm/nommu.c                     |  2 -
 16 files changed, 119 insertions(+), 103 deletions(-)

base-commit: 7c60610d476766e128cc4284bb6349732cbd6606

Signature · 1 line
2.31.1