From: Alan Jenkins <alan.christopher.jenkins@gmail.com>
To: David Howells <dhowells@redhat.com>, viro@zeniv.linux.org.uk
Cc: torvalds@linux-foundation.org, ebiederm@xmission.com,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
mszeredi@redhat.com
Subject: Re: [PATCH 03/34] teach move_mount(2) to work with OPEN_TREE_CLONE [ver #12]
Date: Sun, 7 Oct 2018 20:20:20 +0100 [thread overview]
Message-ID: <5c6f3d62-4cec-2aea-4693-62928611c526@gmail.com> (raw)
In-Reply-To: <862e36a2-2a6f-4e26-3228-8cab4b4cf230@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2922 bytes --]
On 07/10/2018 11:48, Alan Jenkins wrote:
> On 05/10/2018 19:24, Alan Jenkins wrote:
>> On 21/09/2018 17:30, David Howells wrote:
>>> From: Al Viro <viro@zeniv.linux.org.uk>
>>>
>>> Allow a detached tree created by open_tree(..., OPEN_TREE_CLONE) to be
>>> attached by move_mount(2).
>>>
>>> If by the time of final fput() of OPEN_TREE_CLONE-opened file its
>>> tree is
>>> not detached anymore, it won't be dissolved. move_mount(2) is adjusted
>>> to handle detached source.
>>>
>>> That gives us equivalents of mount --bind and mount --rbind.
>>>
>>> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
>>> Signed-off-by: David Howells <dhowells@redhat.com>
>>> ---
>>>
>>> fs/namespace.c | 26 ++++++++++++++++++++------
>>> 1 file changed, 20 insertions(+), 6 deletions(-)
>>> The lockup seems to be a general problem with the cleanup code. Even
>>> if I use this as advertised, i.e. for a simple bind mount.
Ah, I see. The problem is you were expecting me to use the FD from
open_tree() directly. But I did fchdir() into the FD, and then "mount
--move . /mnt" :-).
If I use the FD directly, it avoids the hang. I used two separate C
programs (attached, to avoid my MUA damage)...
> (I was suspicious that being able to pass around detached trees as an
> FD, and re-attach them in any namespace, allows leaking memory by
> creating a namespace loop. I.e. maybe it gives you enough rope to
> skip the test in mnt_ns_loop().
...so here's the memory leak.
# open_tree --help
usage: open_tree 3</source/path FD_NUMBER COMMAND...
# move_mount --help
usage: move_mount 3</from/path 4</to/path
Create a child namespace:
# mount --make-shared /tmp
# cd /tmp
# mkdir private_mnt
# mount -t tmpfs tmp private_mnt
# mount --make-private private_mnt
# touch private_mnt/child_ns
# unshare --mount=private_mnt/child_ns --propagation=shared ls -l /proc/self/ns/mnt
lrwxrwxrwx. 1 root root 0 Oct 7 19:23 /proc/self/ns/mnt -> 'mnt:[4026532334]'
# findmnt | grep /tmp
├─/tmp tmpfs tmpfs rw,nosuid,nodev,seclabel,size=1247640k,nr_inodes=311910
│ └─/tmp/private_mnt tmp tmpfs rw,relatime,seclabel,uid=1000,gid=1000
│ └─/tmp/private_mnt/child_ns nsfs[mnt:[4026532334]] nsfs rw,seclabel
Create a reference cycle:
# ~/test-open_tree 3</tmp/private_mnt 3 \
nsenter --mount=/tmp/private_mnt/child_ns \
sh -c '~/test-move_mount 4</mnt'
Attach 10MB of memory to the cycle:
# grep Shmem: /proc/meminfo
Shmem: 1464 kB
# dd if=/dev/zero of=/tmp/private_mnt/bigfile bs=1M count=10
10+0 records in
10+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.00976358 s, 1.1 GB/s
# grep Shmem: /proc/meminfo
Shmem: 11704 kB
Detach the cycle, and leak all the memory:
# umount -l /tmp/private_mnt/
# grep Shmem: /proc/meminfo
Shmem: 11704 kB
[-- Attachment #2: vfs_samples.diff --]
[-- Type: text/x-patch, Size: 3584 bytes --]
diff --git a/samples/vfs/Makefile b/samples/vfs/Makefile
index 4ac9690fb3c4..13a32e125a74 100644
--- a/samples/vfs/Makefile
+++ b/samples/vfs/Makefile
@@ -1,10 +1,14 @@
# List of programs to build
hostprogs-$(CONFIG_SAMPLE_VFS) := \
test-fsmount \
+ open_tree \
+ move_mount \
test-statx
# Tell kbuild to always build the programs
always := $(hostprogs-y)
HOSTCFLAGS_test-fsmount.o += -I$(objtree)/usr/include
+HOSTCFLAGS_open_tree.o += -I$(objtree)/usr/include
+HOSTCFLAGS_move_mount.o += -I$(objtree)/usr/include
HOSTCFLAGS_test-statx.o += -I$(objtree)/usr/include
diff --git a/samples/vfs/open_tree.c b/samples/vfs/open_tree.c
new file mode 100644
index 000000000000..6222e69048f9
--- /dev/null
+++ b/samples/vfs/open_tree.c
@@ -0,0 +1,54 @@
+/* fd-based mount test.
+ *
+ * Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/prctl.h>
+#include <sys/wait.h>
+#include <linux/fs.h>
+#include <linux/unistd.h>
+
+#ifndef AT_RECURSIVE
+#define AT_RECURSIVE 0x8000
+#endif
+
+#define E(x) do { if ((x) == -1) { perror(#x); exit(1); } } while(0)
+
+static inline int open_tree(int dfd, const char *pathname, unsigned flags)
+{
+ return syscall(__NR_open_tree, dfd, pathname, flags);
+}
+
+int main(int argc, char *argv[])
+{
+ int fd_number;
+ char **command;
+ int mfd;
+
+ if (argc < 3 || !isdigit(argv[1][0])) {
+ fprintf(stderr, "usage: open_tree 3</source/path FD_NUMBER COMMAND...\n");
+ exit(2);
+ }
+ fd_number = atoi(argv[1]);
+ command = argv + 2;
+
+ E( mfd = open_tree(3, "", AT_EMPTY_PATH | OPEN_TREE_CLONE | AT_RECURSIVE) );
+ if (fd_number != mfd) {
+ E( dup2(mfd, fd_number) );
+ E( close(mfd) );
+ }
+ E( execvp(command[0], command) );
+}
diff --git a/samples/vfs/move_mount.c b/samples/vfs/move_mount.c
new file mode 100644
index 000000000000..1bd2122245e2
--- /dev/null
+++ b/samples/vfs/move_mount.c
@@ -0,0 +1,47 @@
+/* fd-based mount test.
+ *
+ * Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/prctl.h>
+#include <sys/wait.h>
+#include <linux/fs.h>
+#include <linux/unistd.h>
+
+#define E(x) do { if ((x) == -1) { perror(#x); exit(1); } } while(0)
+
+static inline int move_mount(int from_dfd, const char *from_pathname,
+ int to_dfd, const char *to_pathname,
+ unsigned int flags)
+{
+ return syscall(__NR_move_mount,
+ from_dfd, from_pathname,
+ to_dfd, to_pathname, flags);
+}
+
+int main(int argc, char *argv[])
+{
+ if (argc != 1) {
+ fprintf(stderr, "usage: move_mount 3</from/path 4</to/path\n");
+ exit(2);
+ }
+
+ if (move_mount(3, "", 4, "", MOVE_MOUNT_F_EMPTY_PATH |
+ MOVE_MOUNT_T_EMPTY_PATH) < 0) {
+ perror("move_mount");
+ exit(1);
+ }
+
+ exit(0);
+}
next prev parent reply other threads:[~2018-10-07 19:20 UTC|newest]
Thread overview: 98+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-21 16:30 [PATCH 00/34] VFS: Introduce filesystem context " David Howells
2018-09-21 16:30 ` [PATCH 01/34] vfs: syscall: Add open_tree(2) to reference or clone a mount " David Howells
2018-10-21 16:41 ` Eric W. Biederman
2018-09-21 16:30 ` [PATCH 02/34] vfs: syscall: Add move_mount(2) to move mounts around " David Howells
2018-09-21 16:30 ` [PATCH 03/34] teach move_mount(2) to work with OPEN_TREE_CLONE " David Howells
2018-10-05 18:24 ` Alan Jenkins
2018-10-07 10:48 ` Alan Jenkins
2018-10-07 19:20 ` Alan Jenkins [this message]
2018-10-10 12:36 ` David Howells
2018-10-12 14:22 ` Alan Jenkins
2018-10-12 14:54 ` David Howells
2018-10-12 14:57 ` Alan Jenkins
2018-10-11 9:17 ` David Howells
2018-10-11 11:48 ` Alan Jenkins
2018-10-11 13:10 ` David Howells
2018-10-11 12:14 ` David Howells
2018-10-11 12:23 ` Alan Jenkins
2018-10-11 15:33 ` David Howells
2018-10-11 18:38 ` Eric W. Biederman
2018-10-11 20:17 ` David Howells
2018-10-13 6:06 ` Al Viro
2018-10-17 17:45 ` Alan Jenkins
2018-10-18 20:09 ` David Howells
2018-10-18 20:58 ` David Howells
2018-10-19 11:57 ` David Howells
2018-10-19 13:37 ` David Howells
2018-10-19 17:35 ` Alan Jenkins
2018-10-19 21:35 ` David Howells
2018-10-19 21:40 ` David Howells
2018-10-19 22:36 ` David Howells
2018-10-20 5:25 ` Al Viro
2018-10-20 11:06 ` Alan Jenkins
2018-10-20 11:48 ` Al Viro
2018-10-20 12:26 ` Al Viro
2018-10-21 0:40 ` David Howells
2018-10-10 11:56 ` David Howells
2018-10-10 12:31 ` David Howells
2018-10-10 12:39 ` Alan Jenkins
2018-10-10 12:50 ` David Howells
2018-10-10 13:02 ` David Howells
2018-10-10 13:06 ` Alan Jenkins
2018-10-21 16:57 ` Eric W. Biederman
2018-10-23 11:19 ` Alan Jenkins
2018-10-23 16:22 ` Al Viro
2018-09-21 16:30 ` [PATCH 04/34] vfs: Suppress MS_* flag defs within the kernel unless explicitly enabled " David Howells
2018-09-21 16:30 ` [PATCH 05/34] vfs: Introduce the basic header for the new mount API's filesystem context " David Howells
2018-09-21 16:30 ` [PATCH 06/34] vfs: Introduce logging functions " David Howells
2018-09-21 16:31 ` [PATCH 07/34] vfs: Add configuration parser helpers " David Howells
2019-03-14 7:46 ` Geert Uytterhoeven
2019-03-14 10:27 ` David Howells
2019-03-14 10:49 ` Geert Uytterhoeven
2018-09-21 16:31 ` [PATCH 08/34] vfs: Add LSM hooks for the new mount API " David Howells
2018-09-21 16:31 ` [PATCH 09/34] vfs: Put security flags into the fs_context struct " David Howells
2018-09-21 16:31 ` [PATCH 10/34] selinux: Implement the new mount API LSM hooks " David Howells
2018-09-21 16:31 ` [PATCH 11/34] smack: Implement filesystem context security " David Howells
2018-09-21 16:31 ` [PATCH 12/34] apparmor: Implement security hooks for the new mount API " David Howells
2018-09-21 16:31 ` [PATCH 13/34] tomoyo: " David Howells
2018-09-21 16:32 ` [PATCH 14/34] vfs: Separate changing mount flags full remount " David Howells
2018-09-21 16:32 ` [PATCH 15/34] vfs: Implement a filesystem superblock creation/configuration context " David Howells
2018-09-21 16:32 ` [PATCH 16/34] vfs: Remove unused code after filesystem context changes " David Howells
2018-09-21 16:32 ` [PATCH 17/34] procfs: Move proc_fill_super() to fs/proc/root.c " David Howells
2018-09-21 16:32 ` [PATCH 18/34] proc: Add fs_context support to procfs " David Howells
2018-09-21 16:32 ` [PATCH 19/34] ipc: Convert mqueue fs to fs_context " David Howells
2018-09-21 16:32 ` [PATCH 20/34] cpuset: Use " David Howells
2018-09-21 16:33 ` [PATCH 21/34] kernfs, sysfs, cgroup, intel_rdt: Support " David Howells
2018-11-19 4:23 ` Andrei Vagin
2018-12-06 17:08 ` Andrei Vagin
2018-09-21 16:33 ` [PATCH 22/34] hugetlbfs: Convert to " David Howells
2018-09-21 16:33 ` [PATCH 23/34] vfs: Remove kern_mount_data() " David Howells
2018-09-21 16:33 ` [PATCH 24/34] vfs: Provide documentation for new mount API " David Howells
2018-09-21 16:33 ` [PATCH 25/34] Make anon_inodes unconditional " David Howells
2018-09-21 16:33 ` [PATCH 26/34] vfs: syscall: Add fsopen() to prepare for superblock creation " David Howells
2018-09-21 16:33 ` [PATCH 27/34] vfs: Implement logging through fs_context " David Howells
2018-09-21 16:33 ` [PATCH 28/34] vfs: Add some logging to the core users of the fs_context log " David Howells
2018-09-21 16:34 ` [PATCH 29/34] vfs: syscall: Add fsconfig() for configuring and managing a context " David Howells
2018-09-21 16:34 ` [PATCH 30/34] vfs: syscall: Add fsmount() to create a mount for a superblock " David Howells
2018-09-21 16:34 ` [PATCH 31/34] vfs: syscall: Add fspick() to select a superblock for reconfiguration " David Howells
2018-10-12 14:49 ` Alan Jenkins
2018-10-13 6:11 ` Al Viro
2018-10-13 9:45 ` Alan Jenkins
2018-10-13 23:04 ` Andy Lutomirski
2018-10-17 13:15 ` David Howells
2018-10-17 13:20 ` David Howells
2018-10-17 14:31 ` Alan Jenkins
2018-10-17 14:35 ` Eric W. Biederman
2018-10-17 14:55 ` Alan Jenkins
2018-10-17 15:24 ` David Howells
2018-10-17 15:38 ` Eric W. Biederman
2018-10-17 15:45 ` David Howells
2018-10-17 17:41 ` Alan Jenkins
2018-10-17 21:20 ` David Howells
2018-10-17 22:13 ` Alan Jenkins
2018-09-21 16:34 ` [PATCH 32/34] afs: Add fs_context support " David Howells
2018-09-21 16:34 ` [PATCH 33/34] afs: Use fs_context to pass parameters over automount " David Howells
2018-09-21 16:34 ` [PATCH 34/34] vfs: Add a sample program for the new mount API " David Howells
2018-12-17 14:12 ` Anders Roxell
2018-12-20 16:36 ` David Howells
2018-10-04 18:37 ` [PATCH 00/34] VFS: Introduce filesystem context " Eric W. Biederman
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=5c6f3d62-4cec-2aea-4693-62928611c526@gmail.com \
--to=alan.christopher.jenkins@gmail.com \
--cc=dhowells@redhat.com \
--cc=ebiederm@xmission.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mszeredi@redhat.com \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®