linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] mm/memfd: MFD_NOEXEC for memfd_create
@ 2022-04-01 22:08 Daniel Verkamp
  2022-04-01 22:08 ` [PATCH 1/4] mm/memfd: add F_SEAL_EXEC Daniel Verkamp
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Daniel Verkamp @ 2022-04-01 22:08 UTC (permalink / raw)
  To: linux-mm
  Cc: linux-kernel, linux-kselftest, Andrew Morton, Hugh Dickins,
	Mattias Nissler, Dmitry Torokhov, Kees Cook, Daniel Verkamp

The default file permissions on a memfd include execute bits, which
means that such a memfd can be filled with a executable and passed to
the exec() family of functions. This is undesirable on systems where all
code is verified and all filesystems are intended to be mounted noexec,
since an attacker may be able to use a memfd to load unverified code and
execute it.

Additionally, execution via memfd is a common way to avoid scrutiny for
malicious code, since it allows execution of a program without a file
ever appearing on disk. This attack vector is not totally mitigated with
this new flag, since the default memfd file permissions must remain
executable to avoid breaking existing legitimate uses, but it should be
possible to use other security mechanisms to prevent memfd_create calls
without MFD_NOEXEC on systems where it is known that executable memfds
are not necessary.

This patch series adds a new MFD_NOEXEC flag for memfd_create(), which
allows creation of non-executable memfds, and as part of the
implementation of this new flag, it also adds a new F_SEAL_EXEC seal,
which will prevent modification of any of the execute bits of a sealed
memfd.

I am not sure if this is the best way to implement the desired behavior
(for example, the F_SEAL_EXEC seal is really more of an implementation
detail and feels a bit clunky to expose), so suggestions are welcome
for alternate approaches.

Daniel Verkamp (4):
  mm/memfd: add F_SEAL_EXEC
  mm/memfd: add MFD_NOEXEC flag to memfd_create
  selftests/memfd: add tests for F_SEAL_EXEC
  selftests/memfd: add tests for MFD_NOEXEC

 include/uapi/linux/fcntl.h                 |   1 +
 include/uapi/linux/memfd.h                 |   1 +
 mm/memfd.c                                 |  12 ++-
 mm/shmem.c                                 |   6 ++
 tools/testing/selftests/memfd/memfd_test.c | 114 +++++++++++++++++++++
 5 files changed, 133 insertions(+), 1 deletion(-)

-- 
2.35.1.1094.g7c7d902a7c-goog


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-07-29 22:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-01 22:08 [PATCH 0/4] mm/memfd: MFD_NOEXEC for memfd_create Daniel Verkamp
2022-04-01 22:08 ` [PATCH 1/4] mm/memfd: add F_SEAL_EXEC Daniel Verkamp
2022-04-01 22:08 ` [PATCH 2/4] mm/memfd: add MFD_NOEXEC flag to memfd_create Daniel Verkamp
2022-04-01 22:08 ` [PATCH 3/4] selftests/memfd: add tests for F_SEAL_EXEC Daniel Verkamp
2022-04-07 20:00   ` Shuah Khan
2022-07-29  6:15     ` Jeff Xu
2022-07-29  6:15       ` [PATCH 4/4] selftests/memfd: add tests for MFD_NOEXEC Jeff Xu
2022-07-29  6:29         ` Jeff Xu
2022-07-29 22:00       ` [PATCH 3/4] selftests/memfd: add tests for F_SEAL_EXEC Jeff Xu
2022-04-01 22:08 ` [PATCH 4/4] selftests/memfd: add tests for MFD_NOEXEC Daniel Verkamp
2022-04-07 20:03   ` Shuah Khan

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).