From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f68.google.com ([209.85.221.68]:32912 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726976AbeJHC2l (ORCPT ); Sun, 7 Oct 2018 22:28:41 -0400 Subject: Re: [PATCH 03/34] teach move_mount(2) to work with OPEN_TREE_CLONE [ver #12] From: Alan Jenkins To: David Howells , 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 References: <153754740781.17872.7869536526927736855.stgit@warthog.procyon.org.uk> <153754743491.17872.12115848333103740766.stgit@warthog.procyon.org.uk> <862e36a2-2a6f-4e26-3228-8cab4b4cf230@gmail.com> Message-ID: <5c6f3d62-4cec-2aea-4693-62928611c526@gmail.com> Date: Sun, 7 Oct 2018 20:20:20 +0100 MIME-Version: 1.0 In-Reply-To: <862e36a2-2a6f-4e26-3228-8cab4b4cf230@gmail.com> Content-Type: multipart/mixed; boundary="------------FBEF933D0AA4BC2B4A5340DD" Content-Language: en-GB Sender: linux-fsdevel-owner@vger.kernel.org List-ID: This is a multi-part message in MIME format. --------------FBEF933D0AA4BC2B4A5340DD Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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 >>> >>> 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 >>> Signed-off-by: David Howells >>> --- >>> >>>   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 '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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 +#include +#include +#include +#include +#include +#include +#include +#include + +#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