Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2812709imm; Sun, 7 Oct 2018 12:22:14 -0700 (PDT) X-Google-Smtp-Source: ACcGV63DP16wKRXa5e0SZSQtSOrU2yff1E3ad0KZh4c1/hEa5Ma5yja7R/o5/dMgjWrmIlxJ9XsF X-Received: by 2002:a63:cc0b:: with SMTP id x11-v6mr4771418pgf.33.1538940134462; Sun, 07 Oct 2018 12:22:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538940134; cv=none; d=google.com; s=arc-20160816; b=rv+fq0j+yfR3mucoU+WtWDjvQhJSGt670LFU4k6KAnRvYh+tSHTBaJ+puTszKQheF3 EKhNhePAttoLO2fLenJee76igvBsgPf3zWMoZeUJWc11b9vx6wqsxJzRCCpPcoxvClLR Vrhp4MP32IGJPKDFaYlOc8LeakBlmSsXRY+Aha+SzM8Xv2X2EmAPdBc54QtdL18c7/DX s0NVdBhVuyoVQTG+Zn3Gzc3CQ4J0Tcb2IDXshkkMcj9C7hBtE8Xrp5V/BdwtyajwvuRM KMFpiyuOKgdzomqFDVUWgxzmHHptksUS4WrC2rlvviCEm2rvOSsDNAXXac9f3P66PkQR u8IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:cc:to:from:subject :dkim-signature; bh=DIdN0ElFW8V7T46BZWUdclI0XkvhY1OTfzBvrEloV50=; b=ifgOIMbQ3HNwuw0cJYM7DTUBqfwwYhiE1cVInQ9e7KeHlR1ESJq5smWXZxAo2k3qE/ SWus5CdRKLfuUOwt327aRD1tEieIKC3Tr6tMP1mpz5qhk3+TLeYbJlBMxvan5I8nHbpg XXhBN1HuscI/AwEe7pTIBMUWYa1MZShWESkigniz02TMXxJ/ZJq4sR28o8ilEKIaFyZX qVxHzCN2u3LwZH7ScgnFgQ/5o2WziwzYaQYduOFmsylMBhx0oN/MBvqOISwFk4pBI2KQ gz6hmByKE5cUWHcxh0zPP3tsIsZFUDVhp/5cVPLAiyFUOVi66ME8V4mxKbEoG+gkxDXC AAbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h6YKD4Ay; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i25-v6si1975226pgi.426.2018.10.07.12.21.29; Sun, 07 Oct 2018 12:22:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h6YKD4Ay; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728340AbeJHC2m (ORCPT + 99 others); Sun, 7 Oct 2018 22:28:42 -0400 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 Received: by mail-wr1-f68.google.com with SMTP id e4-v6so18547415wrs.0; Sun, 07 Oct 2018 12:20:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=DIdN0ElFW8V7T46BZWUdclI0XkvhY1OTfzBvrEloV50=; b=h6YKD4AyGQu7HQ8mMJwMWIUwzvMu3yQY5dJKzyRTFnJygvwuiTcWyjxw4oUwE1Rsxy za5iQ9nZU78DBUdvKqLfyK8WX7zW44FccvkbyWQS0//yhYbNTSoQB8l1syZDEUs8hHDG EaavyJEnWRM2mjJt0aumZTMQgh91ml/35hi1t5l9PFPkJJY6S4mvHZLmN0v12BbJubox kKACy1YPfjSJEsv20kdN/dWOsV0EBNKUmi2++lthASdewhJJOeOf+Hkwclhn3AURJIuG l/zeWHUPXHIMKrlGDG42VZiaVRcJiSKCoNZD+2E8F74YjYCxgt9BI2d7beuLVH7pbma5 lppQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=DIdN0ElFW8V7T46BZWUdclI0XkvhY1OTfzBvrEloV50=; b=S0ar2CTCzP4Biv+CBMkVx/Sww5JNrfF/qx/yPonpHgjFqVt6+JfKFB4/AMKZPO/m4v l2y4voGAeHm3XU7xlB0Vbw565BN8wPgaviqxwzPX7D5s1cv/6blGCU2jr4JyrvkmF3eI T+jHLMN2CipBEjG4xD1HGC0smAQ1JGquUvQu+tGupFwfi/0xFCNntd/jAMtT5fAz78Qk 8z/hfqMtFx2MymI9qGgvtgtN+CB4SWfzP9R4rrwiVE7rNf/vOD+xHfUb0dtDjhh5Hn1q Yq9UIrRSv5Yr7kdRVwsaRwbXz/gyPSAXcUNXQ/CTyxGoF6nlmd1MecMgm+Zk64NDS0Li EPNA== X-Gm-Message-State: ABuFfohYY6H8dy5LP6q3l1+DNfKJUuiGYREyHGfdFTBpgOdWRYcqKHP+ Tg/avO2XTkbkTpI5r2046I8= X-Received: by 2002:adf:81e1:: with SMTP id 88-v6mr15990268wra.19.1538940022144; Sun, 07 Oct 2018 12:20:22 -0700 (PDT) Received: from [172.16.8.139] (host-89-243-172-161.as13285.net. [89.243.172.161]) by smtp.gmail.com with ESMTPSA id f1-v6sm7288353wme.23.2018.10.07.12.20.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 12:20:21 -0700 (PDT) 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 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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