Received: by 10.213.65.68 with SMTP id h4csp1748990imn; Mon, 19 Mar 2018 12:11:33 -0700 (PDT) X-Google-Smtp-Source: AG47ELv572FaoALdGPyiYAVknQzzx+eAWX2kvYDi/2OgOQqVKCVJZ8heyHz14TdP+X40v8mymSj8 X-Received: by 10.99.123.19 with SMTP id w19mr9585884pgc.405.1521486693197; Mon, 19 Mar 2018 12:11:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521486693; cv=none; d=google.com; s=arc-20160816; b=MT+L/GOCgKoNiwJ+VfjzkuLlPiDJz12tRQoTtiUg0ZuPs7dGRQDTgcBzdAR02BqUw4 rfwCzB07rKL25D99N4Zm3OA82n4W/9N6cgVwlvMGZjtih3GENOS62DS621lOlVQ16kJA qIs0qkTwumhfB5I0/g25V8BlCbRjrp8QPtFvi1dmHvQD4GiO26l4zG2kw2HuJWVGXgMw NzaIzc6xHqDBSUy7DDV0ZzYu67HTul5loT4GzXi5X1It+AQm/z0yfVrQ8hlD4eQ3guO3 Zz6sS21NqGzgZ5mDuQyJEncDVZS0yvZxUkJJhbNHQuoNrC85uNKg+oIO6l011rRMLQlI WM0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Cai26+8snd7qFUyVJ4bUmfrarI0gXiE8ulO4sZ3Vxg8=; b=T4+VuzrgN2Q0G56BBEaspmjCFLfGcV3A/lK8A1CQ3glQYaOKIs0zUffb2AVTdFccAL PpjB8Ir0vgxRxdxNL+GiBuqWTajq5m6N73EiDyp3vpHUUmBrbvL+o1ackONdruUHaIJG HvwwIAwl4FzUd3PQmg6Jrr1e0WjQPjUJqPjj207RQBctiW26qBmiSlUdEgmnvyrN+qJe 6TcWFc7hsFXV3NiyiifC0dAkegHC2qOBhjxH7RvyDy8J/vzxmq+k5rdJanZYrjj74c6G Ryo3ZPKKAZTnlr3FRhvX7cG0W5WIQUOAwQcOJZm3QdwcGJdEonPnKIuE+5Dw6oGtEsvX 3hHA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a68si363231pgc.467.2018.03.19.12.11.18; Mon, 19 Mar 2018 12:11:33 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935785AbeCSTIh (ORCPT + 99 others); Mon, 19 Mar 2018 15:08:37 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:51526 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S970090AbeCSS2I (ORCPT ); Mon, 19 Mar 2018 14:28:08 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0317C1270; Mon, 19 Mar 2018 18:28:07 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Al Viro , "Eric W. Biederman" , Al Viro Subject: [PATCH 4.9 228/241] fs: Teach path_connected to handle nfs filesystems with multiple roots. Date: Mon, 19 Mar 2018 19:08:13 +0100 Message-Id: <20180319180800.613855060@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319180751.172155436@linuxfoundation.org> References: <20180319180751.172155436@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric W. Biederman commit 95dd77580ccd66a0da96e6d4696945b8cea39431 upstream. On nfsv2 and nfsv3 the nfs server can export subsets of the same filesystem and report the same filesystem identifier, so that the nfs client can know they are the same filesystem. The subsets can be from disjoint directory trees. The nfsv2 and nfsv3 filesystems provides no way to find the common root of all directory trees exported form the server with the same filesystem identifier. The practical result is that in struct super s_root for nfs s_root is not necessarily the root of the filesystem. The nfs mount code sets s_root to the root of the first subset of the nfs filesystem that the kernel mounts. This effects the dcache invalidation code in generic_shutdown_super currently called shrunk_dcache_for_umount and that code for years has gone through an additional list of dentries that might be dentry trees that need to be freed to accomodate nfs. When I wrote path_connected I did not realize nfs was so special, and it's hueristic for avoiding calling is_subdir can fail. The practical case where this fails is when there is a move of a directory from the subtree exposed by one nfs mount to the subtree exposed by another nfs mount. This move can happen either locally or remotely. With the remote case requiring that the move directory be cached before the move and that after the move someone walks the path to where the move directory now exists and in so doing causes the already cached directory to be moved in the dcache through the magic of d_splice_alias. If someone whose working directory is in the move directory or a subdirectory and now starts calling .. from the initial mount of nfs (where s_root == mnt_root), then path_connected as a heuristic will not bother with the is_subdir check. As s_root really is not the root of the nfs filesystem this heuristic is wrong, and the path may actually not be connected and path_connected can fail. The is_subdir function might be cheap enough that we can call it unconditionally. Verifying that will take some benchmarking and the result may not be the same on all kernels this fix needs to be backported to. So I am avoiding that for now. Filesystems with snapshots such as nilfs and btrfs do something similar. But as the directory tree of the snapshots are disjoint from one another and from the main directory tree rename won't move things between them and this problem will not occur. Cc: stable@vger.kernel.org Reported-by: Al Viro Fixes: 397d425dc26d ("vfs: Test for and handle paths that are unreachable from their mnt_root") Signed-off-by: "Eric W. Biederman" Signed-off-by: Al Viro Signed-off-by: Greg Kroah-Hartman --- fs/namei.c | 5 +++-- fs/nfs/super.c | 2 ++ include/linux/fs.h | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) --- a/fs/namei.c +++ b/fs/namei.c @@ -578,9 +578,10 @@ static int __nd_alloc_stack(struct namei static bool path_connected(const struct path *path) { struct vfsmount *mnt = path->mnt; + struct super_block *sb = mnt->mnt_sb; - /* Only bind mounts can have disconnected paths */ - if (mnt->mnt_root == mnt->mnt_sb->s_root) + /* Bind mounts and multi-root filesystems can have disconnected paths */ + if (!(sb->s_iflags & SB_I_MULTIROOT) && (mnt->mnt_root == sb->s_root)) return true; return is_subdir(path->dentry, mnt->mnt_root); --- a/fs/nfs/super.c +++ b/fs/nfs/super.c @@ -2613,6 +2613,8 @@ struct dentry *nfs_fs_mount_common(struc /* initial superblock/root creation */ mount_info->fill_super(s, mount_info); nfs_get_cache_cookie(s, mount_info->parsed, mount_info->cloned); + if (!(server->flags & NFS_MOUNT_UNSHARED)) + s->s_iflags |= SB_I_MULTIROOT; } mntroot = nfs_get_root(s, mount_info->mntfh, dev_name); --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1319,6 +1319,7 @@ struct mm_struct; #define SB_I_CGROUPWB 0x00000001 /* cgroup-aware writeback enabled */ #define SB_I_NOEXEC 0x00000002 /* Ignore executables on this fs */ #define SB_I_NODEV 0x00000004 /* Ignore devices on this fs */ +#define SB_I_MULTIROOT 0x00000008 /* Multiple roots to the dentry tree */ /* sb->s_iflags to limit user namespace mounts */ #define SB_I_USERNS_VISIBLE 0x00000010 /* fstype already mounted */