Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp988695imm; Wed, 1 Aug 2018 08:25:44 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfwSOyp9ACSxF45o9bWRJRrQ49U3P/S65v3QlSnxLxDmhd3gj7biVbbmIeFfH3NRCpZf7N/ X-Received: by 2002:a62:41d6:: with SMTP id g83-v6mr27083500pfd.219.1533137144463; Wed, 01 Aug 2018 08:25:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533137144; cv=none; d=google.com; s=arc-20160816; b=jL3WiBlOMTgnb9pyr266XhXyrS5Kgcf6y+zYDgRV6hmM05B+Ncg9vgj7VI7I7Hhoyv 7++vB2KDAl0Uk+t2vpuEFThO0V+EYQxmlCdmMvOx2ufYwREDWOJ2Dhuwr9Ne1Z7ywgZW /tCHZ8gNawg7UEGbufCwUYkqcdUuqC1pet9m53iV3O38T1AzI3VcjpgMwrR6l0mDqxIg aWGf5pGCVUEcrUtR4EgTdQPnnHDV+LEjsLb82vXRMOltSl8FVAWLVfK92w1iVww2bscA ByjnBduNz2uawThKsgZkbLiLFgo5XqSITQIQYYqpIH5rf9ahq49scxsP/WTNB9RmhIfT 2nGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:arc-authentication-results; bh=GqJViCEqmcy8T+Rv4HyqIdQYeX/5gl4P86YB49E9Rbs=; b=Pe+knWoIsNFLc+mykraIqkE9JrVUgFHSqNs7aXlY27jNOVQacWvnzDbO1PKcfoDCsO SxKFKbi8HRb4oSb2twsNZ8z8/mZd2Zt8P8vzTe75DaccyRgHxE8m1ZHBThBpKE8h5tSJ LGjXQqg3hVMzb5P1hUrM1KZhHuVYi2YiNlWOM3ltHPR7/jbNTA697tmNG8t9Ts+TxN6w NPJ5/KRV4nVYdC1EQMzLUb4qyL1TUOt5SOnRmE1N8vArNhDdFfiGWKS6o9p4mlXpOqRI WJCeZgk7/QF8akfY9uoAThxkjGEf5P/3y7pe9/WSv7CjriP+uCW+IBNyvCQi5hBHa5zC 5O0A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d7-v6si9386361plr.213.2018.08.01.08.25.30; Wed, 01 Aug 2018 08:25:44 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389854AbeHARKj (ORCPT + 99 others); Wed, 1 Aug 2018 13:10:39 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40966 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2389714AbeHARKj (ORCPT ); Wed, 1 Aug 2018 13:10:39 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C36BF8197005; Wed, 1 Aug 2018 15:24:25 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-116.rdu2.redhat.com [10.10.120.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28E2D10EE77E; Wed, 1 Aug 2018 15:24:25 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 03/33] teach move_mount(2) to work with OPEN_TREE_CLONE [ver #11] From: David Howells To: viro@zeniv.linux.org.uk Cc: torvalds@linux-foundation.org, dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 01 Aug 2018 16:24:24 +0100 Message-ID: <153313706468.13253.16771852721230651938.stgit@warthog.procyon.org.uk> In-Reply-To: <153313703562.13253.5766498657900728120.stgit@warthog.procyon.org.uk> References: <153313703562.13253.5766498657900728120.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 01 Aug 2018 15:24:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 01 Aug 2018 15:24:25 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) diff --git a/fs/namespace.c b/fs/namespace.c index e2934a4f342b..3981fd7b13f5 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -1846,8 +1846,10 @@ void dissolve_on_fput(struct vfsmount *mnt) { namespace_lock(); lock_mount_hash(); - mntget(mnt); - umount_tree(real_mount(mnt), UMOUNT_SYNC); + if (!real_mount(mnt)->mnt_ns) { + mntget(mnt); + umount_tree(real_mount(mnt), UMOUNT_SYNC); + } unlock_mount_hash(); namespace_unlock(); } @@ -2454,6 +2456,7 @@ static int do_move_mount(struct path *old_path, struct path *new_path) struct mount *old; struct mountpoint *mp; int err; + bool attached; mp = lock_mount(new_path); err = PTR_ERR(mp); @@ -2464,10 +2467,19 @@ static int do_move_mount(struct path *old_path, struct path *new_path) p = real_mount(new_path->mnt); err = -EINVAL; - if (!check_mnt(p) || !check_mnt(old)) + /* The mountpoint must be in our namespace. */ + if (!check_mnt(p)) + goto out1; + /* The thing moved should be either ours or completely unattached. */ + if (old->mnt_ns && !check_mnt(old)) goto out1; - if (!mnt_has_parent(old)) + attached = mnt_has_parent(old); + /* + * We need to allow open_tree(OPEN_TREE_CLONE) followed by + * move_mount(), but mustn't allow "/" to be moved. + */ + if (old->mnt_ns && !attached) goto out1; if (old->mnt.mnt_flags & MNT_LOCKED) @@ -2482,7 +2494,7 @@ static int do_move_mount(struct path *old_path, struct path *new_path) /* * Don't move a mount residing in a shared parent. */ - if (IS_MNT_SHARED(old->mnt_parent)) + if (attached && IS_MNT_SHARED(old->mnt_parent)) goto out1; /* * Don't move a mount tree containing unbindable mounts to a destination @@ -2496,7 +2508,7 @@ static int do_move_mount(struct path *old_path, struct path *new_path) goto out1; err = attach_recursive_mnt(old, real_mount(new_path->mnt), mp, - &parent_path); + attached ? &parent_path : NULL); if (err) goto out1; @@ -3182,6 +3194,8 @@ SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, /* * Move a mount from one place to another. + * In combination with open_tree(OPEN_TREE_CLONE [| AT_RECURSIVE]) it can be + * used to copy a mount subtree. * * Note the flags value is a combination of MOVE_MOUNT_* flags. */