Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp835375imm; Fri, 12 Oct 2018 07:27:56 -0700 (PDT) X-Google-Smtp-Source: ACcGV63Jd1UJKscq6huLdGURaaGHn9AA9C60OqlSa3N3DCQDFX6X9WgViWBoR3xjssJnb97tQsdQ X-Received: by 2002:a63:fe44:: with SMTP id x4-v6mr5813239pgj.152.1539354476862; Fri, 12 Oct 2018 07:27:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539354476; cv=none; d=google.com; s=arc-20160816; b=pUsarTUnisrwqajoboRixYHu0z9/lIgrakXmOToO5Uhqt7/zLO1EJ4qo+2rNG5q8MM y5mgKzyMgOEg9MI8YChS7DTYU8bKTx2LAvaBEuhGhfoSupXYyQDutnASLDd6sTOvG0VP GGZmqE2xU6DIBoYhAlak+Y1Kd0Ml61/hmpRXWr/l2hFBcZU6GBRpD2M7aJV8VvkVFLXj /LHjRJuVu7aJcX93f4/pbusOVCnTeDB6HnqBv9j9ewKm4GGv6Q2imTBYCbC6DoG1HN5Z 0LFlmp75N9hBRjJ+Iii7rK6olVop84ZwmN+Xuy/BC1jlFK8ujAN6+bgf7LoQ2elSfVqg gLWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:subject:from:dkim-signature; bh=NCNQY6m01P3Qy3qr1yUlO29yse9SurNKF1zdUJ7E+Ro=; b=m/ogTYntN5Jewu1lImmwcZvmUPAOUTtHkHQy0vJ3bXMwmdyud+NZqrW/y1QTa20PPM iLDCitZ6uE04RmhY4nsoEElJpEwn5JEOkxImwOmAwyee7X7i2Gp0WieWj1FOhJNvqDWG jZrlgQnD7Z2SBtvrkAuqIICYfrRkWnQCpE755DTk0QnGjFNgxM5X+l3lVQmFSAfEy9ai JX1VZMkUQh+MwyyKJ3WpPaQWk5JN1byj51vqY06OKTk14E1A7LF0SK8/D3Jdz4qaqXrm EwS65BK+ba4fyd3d7J9HJIZWmluQvLaFxfVfB4oPdFCe8ad3NPREuo+MhevdY3LR5Zsh To1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PNPdUUvp; 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 f89-v6si1595285plb.37.2018.10.12.07.27.42; Fri, 12 Oct 2018 07:27:56 -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=PNPdUUvp; 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 S1728968AbeJLV60 (ORCPT + 99 others); Fri, 12 Oct 2018 17:58:26 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:55278 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728577AbeJLV60 (ORCPT ); Fri, 12 Oct 2018 17:58:26 -0400 Received: by mail-wm1-f67.google.com with SMTP id r63-v6so12511625wma.4; Fri, 12 Oct 2018 07:25:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=NCNQY6m01P3Qy3qr1yUlO29yse9SurNKF1zdUJ7E+Ro=; b=PNPdUUvpB3IoCSeWg7HFRrHEbXyZZthIROOO7LG0z4oyDfrDZbA2YL2b+Mu5rDcZ9f yHBEnMO7PvmBbKdduRZBf4nVNZWXx4ulTUl76DoTTZmhlFK5BmKMfNVWGnjyl16n9HP3 FOUJQXL6u9NXIsozj8AUc4ElRAEvxJCCd/ApliUFyr7LD+fYi+GzbWcQ+76kJ0Ys740h /3EeCtnfwBYEjxlgIxbhbvlkzHMSW30s1HzZWKZzmTl8ABqqwhA45s26+MmIgwgvmZcn 7MnkpU5SYWCEZDWoWLE7TtpJW395O2P+GXu7IFhQnHV2kyzmU7FhuRiP9EFWa7yVleOL wR4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=NCNQY6m01P3Qy3qr1yUlO29yse9SurNKF1zdUJ7E+Ro=; b=gEmFc97r0juIcJRGDhze7OiXD+dype8WvCQvSVnQwW6ecbAynzOxPxMcp57J3HlCyB f/oDkWMTVZkcG8njT4PgJHGrYYOIcATgkP1t5nt7YIwaV+fXFk2YGrXJvD0xgHBVIALQ gZeekij3vkUZ9tu3CnDJm1mxO9MuMT7FSFyC/cBjLT39OCvEbb5ll4KmGVng1qun0cnS BHSw1sJLnVTkktM6yMXQYmu9MGtQ9kZDFKeGQiulMLOL0F74iTx+Zu/Mkq8i3XKWW7lP XSZXaxF4Kb4UdYA2BnV/nKMVML9gJ9eUKcAcfesYKi00y/XbO1JJeG1Ek9jKNh5FvNUl cHvQ== X-Gm-Message-State: ABuFfojZIQh9bIcbT/TGhp1I5ZCym7WhBEO4F89CcZyOn1X55T8u1bgy ris+sE9ztQ6G7fAfYBZAbAzKoV/J2x0= X-Received: by 2002:a1c:3b89:: with SMTP id i131-v6mr5303372wma.27.1539354343940; Fri, 12 Oct 2018 07:25:43 -0700 (PDT) Received: from [172.16.1.192] (host-89-243-172-161.as13285.net. [89.243.172.161]) by smtp.gmail.com with ESMTPSA id z8-v6sm1066164wrp.63.2018.10.12.07.25.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 07:25:43 -0700 (PDT) From: Alan Jenkins Subject: Re: [PATCH 03/33] teach move_mount(2) to work with OPEN_TREE_CLONE [ver #11] To: David Howells , viro@zeniv.linux.org.uk Cc: torvalds@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org References: <153313703562.13253.5766498657900728120.stgit@warthog.procyon.org.uk> <153313706468.13253.16771852721230651938.stgit@warthog.procyon.org.uk> Message-ID: <3fa048b0-896e-238f-0ba3-0e4e4f5a7157@gmail.com> Date: Fri, 12 Oct 2018 15:25:42 +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: <153313706468.13253.16771852721230651938.stgit@warthog.procyon.org.uk> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/08/2018 16:24, 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(-) > > diff --git a/fs/namespace.c b/fs/namespace.c > index e2934a4f342b..3981fd7b13f5 100644 > --- a/fs/namespace.c > +++ b/fs/namespace.c > @@ -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; Technically, I think the comment should say "mustn't allow rootfs to be moved". "rootfs", as in Documentation/filesystems/ramfs-rootfs-initramfs.txt. Moving "/" is allowed. # unshare -m # cd /mnt # mount -ttmpfs none / # mount --move --no-canonicalize /.. /mnt # (Or if you want to quibble about "/.." v.s. "/" - # unshare -m # cd /mnt # mount --rbind / / # chroot --skip-chdir /.. # mount --move --no-canonicalize / .