linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] fcntl: add fcntl(F_CHECK_ORIGINAL_MEMFD)
@ 2023-08-31 20:36 Michal Clapinski
  2023-08-31 20:36 ` [PATCH 1/2] " Michal Clapinski
  2023-08-31 20:36 ` [PATCH 2/2] selftests: test fcntl(F_CHECK_ORIGINAL_MEMFD) Michal Clapinski
  0 siblings, 2 replies; 9+ messages in thread
From: Michal Clapinski @ 2023-08-31 20:36 UTC (permalink / raw)
  To: Jeff Layton, Chuck Lever, Alexander Viro, Christian Brauner,
	Shuah Khan, Andrew Morton, Jeff Xu, Aleksa Sarai, Daniel Verkamp,
	Kees Cook, Marc Dionne, linux-fsdevel, linux-kernel,
	linux-kselftest
  Cc: Michal Clapinski

This change introduces a new fcntl to check if an fd points to a memfd's
original open fd (the one created by memfd_create).

We encountered an issue with migrating memfds in CRIU (checkpoint
restore in userspace - it migrates running processes between
machines). Imagine a scenario:
1. Create a memfd. By default it's open with O_RDWR and yet one can
exec() to it (unlike with regular files, where one would get ETXTBSY).
2. Reopen that memfd with O_RDWR via /proc/self/fd/<fd>.

Now those 2 fds are indistinguishable from userspace. You can't exec()
to either of them (since the reopen incremented inode->i_writecount)
and their /proc/self/fdinfo/ are exactly the same. Unfortunately they
are not the same. If you close the second one, the first one becomes
exec()able again. If you close the first one, the other doesn't become
exec()able. Therefore during migration it does matter which is recreated
first and which is reopened but there is no way for CRIU to tell which
was first.

Michal Clapinski (2):
  fcntl: add fcntl(F_CHECK_ORIGINAL_MEMFD)
  selftests: test fcntl(F_CHECK_ORIGINAL_MEMFD)

 fs/fcntl.c                                 |  3 ++
 include/uapi/linux/fcntl.h                 |  9 ++++++
 tools/testing/selftests/memfd/memfd_test.c | 32 ++++++++++++++++++++++
 3 files changed, 44 insertions(+)

-- 
2.42.0.283.g2d96d420d3-goog


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

end of thread, other threads:[~2023-09-05 15:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-31 20:36 [PATCH 0/2] fcntl: add fcntl(F_CHECK_ORIGINAL_MEMFD) Michal Clapinski
2023-08-31 20:36 ` [PATCH 1/2] " Michal Clapinski
2023-09-01 12:56   ` Christian Brauner
2023-09-01 14:50     ` Michał Cłapiński
2023-09-01 18:34       ` Kees Cook
2023-09-04  7:29         ` Christian Brauner
2023-09-04 17:57           ` Michał Cłapiński
2023-09-05  8:37             ` Christian Brauner
2023-08-31 20:36 ` [PATCH 2/2] selftests: test fcntl(F_CHECK_ORIGINAL_MEMFD) Michal Clapinski

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