From: Jonathan Corbet <corbet@lwn.net>
To: Michal Clapinski <mclapinski@google.com>,
Mike Kravetz <mike.kravetz@oracle.com>,
Muchun Song <muchun.song@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
Hugh Dickins <hughd@google.com>, Shuah Khan <shuah@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Arnd Bergmann <arnd@arndb.de>, Yi Liu <yi.l.liu@intel.com>,
Dominik Brodowski <linux@dominikbrodowski.net>,
Hans Verkuil <hverkuil-cisco@xs4all.nl>,
Steve French <stfrench@microsoft.com>,
Simon Ser <contact@emersion.fr>, Jason Gunthorpe <jgg@ziepe.ca>,
Marc Dionne <marc.dionne@auristor.com>,
Jiri Slaby <jirislaby@kernel.org>,
David Howells <dhowells@redhat.com>,
Luca Vizzarro <Luca.Vizzarro@arm.com>,
Jeff Xu <jeffxu@google.com>, Aleksa Sarai <cyphar@cyphar.com>,
Kees Cook <keescook@chromium.org>,
Daniel Verkamp <dverkamp@chromium.org>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, linux-kselftest@vger.kernel.org
Cc: Michal Clapinski <mclapinski@google.com>
Subject: Re: [PATCH v2 0/2] mm/memfd: add ioctl(MEMFD_CHECK_IF_ORIGINAL)
Date: Fri, 08 Sep 2023 14:34:29 -0600 [thread overview]
Message-ID: <87tts4z9nu.fsf@meer.lwn.net> (raw)
In-Reply-To: <20230908175738.41895-1-mclapinski@google.com>
Michal Clapinski <mclapinski@google.com> writes:
> This change introduces a way 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.
So please bear with me...I'll confess that I don't fully understand the
situation here, so this is probably a dumb question.
It seems like you are adding this "original open" test as a way of
working around a quirk with the behavior of subsequent opens. I don't
*think* that this is part of the intended, documented behavior of
memfds, it's just something that happens. You're exposing an artifact
of the current implementation.
Given that the two file descriptors are otherwise indistinguishable,
might a better fix be to make them indistinguishable in this regard as
well? Is there a good reason why the second fd doesn't become
exec()able in this scenario and, if not, perhaps that behavior could be
changed instead?
Thanks,
jon
next prev parent reply other threads:[~2023-09-08 20:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-08 17:57 Michal Clapinski
2023-09-08 17:57 ` [PATCH v2 1/2] " Michal Clapinski
2023-09-08 20:02 ` kernel test robot
2023-09-08 17:57 ` [PATCH v2 2/2] selftests: test ioctl(MEMFD_CHECK_IF_ORIGINAL) Michal Clapinski
2023-09-08 20:34 ` Jonathan Corbet [this message]
2023-09-08 21:55 ` [PATCH v2 0/2] mm/memfd: add ioctl(MEMFD_CHECK_IF_ORIGINAL) Michał Cłapiński
2023-09-08 22:07 ` Jonathan Corbet
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=87tts4z9nu.fsf@meer.lwn.net \
--to=corbet@lwn.net \
--cc=Luca.Vizzarro@arm.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=contact@emersion.fr \
--cc=cyphar@cyphar.com \
--cc=dhowells@redhat.com \
--cc=dverkamp@chromium.org \
--cc=gregkh@linuxfoundation.org \
--cc=hughd@google.com \
--cc=hverkuil-cisco@xs4all.nl \
--cc=jeffxu@google.com \
--cc=jgg@ziepe.ca \
--cc=jirislaby@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux@dominikbrodowski.net \
--cc=marc.dionne@auristor.com \
--cc=mclapinski@google.com \
--cc=mike.kravetz@oracle.com \
--cc=muchun.song@linux.dev \
--cc=shuah@kernel.org \
--cc=stfrench@microsoft.com \
--cc=yi.l.liu@intel.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox