From: Michal Clapinski <mclapinski@google.com>
To: Jonathan Corbet <corbet@lwn.net>,
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: [PATCH v2 2/2] selftests: test ioctl(MEMFD_CHECK_IF_ORIGINAL)
Date: Fri, 8 Sep 2023 19:57:38 +0200 [thread overview]
Message-ID: <20230908175738.41895-3-mclapinski@google.com> (raw)
In-Reply-To: <20230908175738.41895-1-mclapinski@google.com>
Signed-off-by: Michal Clapinski <mclapinski@google.com>
---
tools/testing/selftests/memfd/memfd_test.c | 32 ++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
index 3df008677239..1a702af6e01a 100644
--- a/tools/testing/selftests/memfd/memfd_test.c
+++ b/tools/testing/selftests/memfd/memfd_test.c
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include <signal.h>
#include <string.h>
+#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/syscall.h>
@@ -39,6 +40,10 @@
#define MFD_NOEXEC_SEAL 0x0008U
+#ifndef MEMFD_CHECK_IF_ORIGINAL
+#define MEMFD_CHECK_IF_ORIGINAL _IOR(0xB8, 0, int)
+#endif
+
/*
* Default is not to test hugetlbfs
*/
@@ -1567,6 +1572,31 @@ static void test_share_fork(char *banner, char *b_suffix)
close(fd);
}
+static void test_ioctl_check_original(void)
+{
+ int fd, fd2;
+
+ printf("%s IOCTL-CHECK-ORIGINAL\n", memfd_str);
+ fd = sys_memfd_create("kern_memfd_check_original", 0);
+ if (fd < 0) {
+ printf("memfd_create failed: %m\n");
+ abort();
+ }
+ if (ioctl(fd, MEMFD_CHECK_IF_ORIGINAL) != 1) {
+ printf("ioctl(MEMFD_CHECK_IF_ORIGINAL) failed\n");
+ abort();
+ }
+
+ fd2 = mfd_assert_reopen_fd(fd);
+ if (ioctl(fd2, MEMFD_CHECK_IF_ORIGINAL) != 0) {
+ printf("ioctl(MEMFD_CHECK_IF_ORIGINAL) failed\n");
+ abort();
+ }
+
+ close(fd);
+ close(fd2);
+}
+
int main(int argc, char **argv)
{
pid_t pid;
@@ -1609,6 +1639,8 @@ int main(int argc, char **argv)
test_share_open("SHARE-OPEN", "");
test_share_fork("SHARE-FORK", "");
+ test_ioctl_check_original();
+
/* Run test-suite in a multi-threaded environment with a shared
* file-table. */
pid = spawn_idle_thread(CLONE_FILES | CLONE_FS | CLONE_VM);
--
2.42.0.283.g2d96d420d3-goog
next prev parent reply other threads:[~2023-09-08 17:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-08 17:57 [PATCH v2 0/2] mm/memfd: add ioctl(MEMFD_CHECK_IF_ORIGINAL) 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 ` Michal Clapinski [this message]
2023-09-08 20:34 ` [PATCH v2 0/2] " Jonathan Corbet
2023-09-08 21:55 ` 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=20230908175738.41895-3-mclapinski@google.com \
--to=mclapinski@google.com \
--cc=Luca.Vizzarro@arm.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=contact@emersion.fr \
--cc=corbet@lwn.net \
--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=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