LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: David Hildenbrand <david@redhat.com>, linux-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	Petr Mladek <pmladek@suse.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Kees Cook <keescook@chromium.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Greg Ungerer <gerg@linux-m68k.org>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Mike Rapoport <rppt@kernel.org>, Vlastimil Babka <vbabka@suse.cz>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	Chinwen Chang <chinwen.chang@mediatek.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Huang Ying <ying.huang@intel.com>, Jann Horn <jannh@google.com>,
	Feng Tang <feng.tang@intel.com>,
	Kevin Brodsky <Kevin.Brodsky@arm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Shawn Anastasio <shawn@anastas.io>,
	Steven Price <steven.price@arm.com>,
	Nicholas Piggin <npiggin@gmail.com>,
	Christian Brauner <christian.brauner@ubuntu.com>,
	Jens Axboe <axboe@kernel.dk>,
	Gabriel Krisman Bertazi <krisman@collabora.com>,
	Peter Xu <peterx@redhat.com>,
	Suren Baghdasaryan <surenb@google.com>,
	Shakeel Butt <shakeelb@google.com>,
	Marco Elver <elver@google.com>,
	Daniel Jordan <daniel.m.jordan@oracle.com>,
	Nicolas Viennot <Nicolas.Viennot@twosigma.com>,
	Thomas Cedeno <thomascedeno@google.com>,
	Michal Hocko <mhocko@suse.com>,
	Miklos Szeredi <miklos@szeredi.hu>,
	Chengguang Xu <cgxu519@mykernel.net>,
	Florian Weimer <fweimer@redhat.com>,
	David Laight <David.Laight@ACULAB.COM>,
	linux-unionfs@vger.kernel.org, linux-api@vger.kernel.org,
	x86@kernel.org, linux-fsdevel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH v2 0/7] Remove in-tree usage of MAP_DENYWRITE
Date: Tue, 17 Aug 2021 13:01:12 +0200	[thread overview]
Message-ID: <6e64c3ea-b9c9-decb-36fa-fad713414833@amd.com> (raw)
In-Reply-To: <20210816194840.42769-1-david@redhat.com>

Am 16.08.21 um 21:48 schrieb David Hildenbrand:
> 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

This is unfortunately way beyond my understanding of the fs layer to 
actually review this.

But from the ten mile high view it looks like a really nice cleanup to 
me and makes my live in the DRM subsystem much easier.

Feel free to add a Acked-by: Christian König <christian.koenig@amd.com> 
to the series.

Thanks,
Christian.

>
> [1] https://lore.kernel.org/r/20210423131640.20080-1-david@redhat.com/
> [2] https://lore.kernel.org/r/YNHXzBgzRrZu1MrD@miu.piliscsaba.redhat.com/
> [3] https://lkml.kernel.org/r/20210812084348.6521-1-david@redhat.com
>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Cc: Alexey Dobriyan <adobriyan@gmail.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Jiri Olsa <jolsa@redhat.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Petr Mladek <pmladek@suse.com>
> Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: "Eric W. Biederman" <ebiederm@xmission.com>
> Cc: Greg Ungerer <gerg@linux-m68k.org>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Mike Rapoport <rppt@kernel.org>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
> Cc: Chinwen Chang <chinwen.chang@mediatek.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
> Cc: Huang Ying <ying.huang@intel.com>
> Cc: Jann Horn <jannh@google.com>
> Cc: Feng Tang <feng.tang@intel.com>
> Cc: Kevin Brodsky <Kevin.Brodsky@arm.com>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Shawn Anastasio <shawn@anastas.io>
> Cc: Steven Price <steven.price@arm.com>
> Cc: Nicholas Piggin <npiggin@gmail.com>
> Cc: Christian Brauner <christian.brauner@ubuntu.com>
> Cc: Jens Axboe <axboe@kernel.dk>
> Cc: Gabriel Krisman Bertazi <krisman@collabora.com>
> Cc: Peter Xu <peterx@redhat.com>
> Cc: Suren Baghdasaryan <surenb@google.com>
> Cc: Shakeel Butt <shakeelb@google.com>
> Cc: Marco Elver <elver@google.com>
> Cc: Daniel Jordan <daniel.m.jordan@oracle.com>
> Cc: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
> Cc: Thomas Cedeno <thomascedeno@google.com>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Miklos Szeredi <miklos@szeredi.hu>
> Cc: Chengguang Xu <cgxu519@mykernel.net>
> Cc: "Christian König" <ckoenig.leichtzumerken@gmail.com>
> Cc: Florian Weimer <fweimer@redhat.com>
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> Cc: David Laight <David.Laight@ACULAB.COM>
> Cc: linux-unionfs@vger.kernel.org
> Cc: linux-api@vger.kernel.org
> Cc: x86@kernel.org
> Cc: linux-fsdevel@vger.kernel.org
> Cc: linux-mm@kvack.org
>
> 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


  parent reply	other threads:[~2021-08-17 11:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-16 19:48 David Hildenbrand
2021-08-16 19:48 ` [PATCH v2 1/7] binfmt: don't use MAP_DENYWRITE when loading shared libraries via uselib() David Hildenbrand
2021-09-05 15:32   ` Guenter Roeck
2021-09-05 17:17     ` Linus Torvalds
2021-09-05 19:07       ` David Hildenbrand
2021-08-16 19:48 ` [PATCH v2 2/7] kernel/fork: factor out replacing the current MM exe_file David Hildenbrand
2021-08-19 20:51   ` Linus Torvalds
2021-08-20  8:46     ` David Hildenbrand
2021-08-20 14:36       ` Eric W. Biederman
2021-08-22 17:58         ` Linus Torvalds
2021-08-16 19:48 ` [PATCH v2 3/7] kernel/fork: always deny write access to " David Hildenbrand
2021-08-16 19:48 ` [PATCH v2 4/7] binfmt: remove in-tree usage of MAP_DENYWRITE David Hildenbrand
2021-08-16 19:48 ` [PATCH v2 5/7] mm: remove VM_DENYWRITE David Hildenbrand
2021-08-16 19:48 ` [PATCH v2 6/7] mm: ignore MAP_DENYWRITE in ksys_mmap_pgoff() David Hildenbrand
2021-08-16 19:48 ` [PATCH v2 7/7] fs: update documentation of get_write_access() and friends David Hildenbrand
2021-08-17 11:01 ` Christian König [this message]
2021-09-03  9:45 ` [PATCH v2 0/7] Remove in-tree usage of MAP_DENYWRITE David Hildenbrand
2021-09-03 16:26   ` Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6e64c3ea-b9c9-decb-36fa-fad713414833@amd.com \
    --to=christian.koenig@amd.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=Kevin.Brodsky@arm.com \
    --cc=Nicolas.Viennot@twosigma.com \
    --cc=acme@kernel.org \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=axboe@kernel.dk \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=cgxu519@mykernel.net \
    --cc=chinwen.chang@mediatek.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=daniel.m.jordan@oracle.com \
    --cc=david@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=elver@google.com \
    --cc=feng.tang@intel.com \
    --cc=fweimer@redhat.com \
    --cc=geert@linux-m68k.org \
    --cc=gerg@linux-m68k.org \
    --cc=hpa@zytor.com \
    --cc=jannh@google.com \
    --cc=jolsa@redhat.com \
    --cc=keescook@chromium.org \
    --cc=krisman@collabora.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mark.rutland@arm.com \
    --cc=mhocko@suse.com \
    --cc=miklos@szeredi.hu \
    --cc=mingo@redhat.com \
    --cc=mpe@ellerman.id.au \
    --cc=namhyung@kernel.org \
    --cc=npiggin@gmail.com \
    --cc=peterx@redhat.com \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=shakeelb@google.com \
    --cc=shawn@anastas.io \
    --cc=steven.price@arm.com \
    --cc=surenb@google.com \
    --cc=tglx@linutronix.de \
    --cc=thomascedeno@google.com \
    --cc=torvalds@linux-foundation.org \
    --cc=vbabka@suse.cz \
    --cc=vincenzo.frascino@arm.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    --cc=x86@kernel.org \
    --cc=ying.huang@intel.com \
    --subject='Re: [PATCH v2 0/7] Remove in-tree usage of MAP_DENYWRITE' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).