Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp57846ybh; Fri, 13 Mar 2020 17:00:29 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtgjKtzYBCrvmwO6AQoL3u0wpA3yrb5WZrLvnRWS42QeB5tRUs8lh/O7IYO3mj4uPMckOTh X-Received: by 2002:a9d:5d07:: with SMTP id b7mr13828433oti.209.1584144028852; Fri, 13 Mar 2020 17:00:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584144028; cv=none; d=google.com; s=arc-20160816; b=Y+oxodJMkywyoSKiqdh+NnAlsa6EPWl1AWvleO/UnXxAHbzQNny6m2RtnGkTSZ8wHE pQGZU/G8kNyawFNk2/AzD9+IoxjubSo+JNNrY2ZQQ6LeoutoFCLsDyEM2fTyQsYMGDpf D19NQTrTUc7LYIwzd/n98FmktDL3aPMR6in6Nx5AFWuzctoaBYeJEbkemZqARPDiLPHq bYziFXbHyQSerUyJliDRVpZo7IRuZcQdz5lLUNzZXOhtIHD03s6WxWXt+5UjuutLf3Eh jNAvwqd/wkkPshQBQe72hfd9/q8IOs23m9UusznsracD8Cpl2LCFp3L3jzciB60yhmnF ruYQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=VJAxj7l3tZ1SpGc8h9OziXlaeqh7ctV6Upyw/wO3XAc=; b=EAPb91s83XOOG+8Kuqkflfx3WqshYX8kmwcsRKxnSMOUJy+aI2kgDil9mJzAfD6Cau Wd2SzQ3HvT9CsEspBZYSuXyKGPMOtybX2dHuhjZHrjq5f+QQE4qbh44f535QIU3o4Xm3 YH5vyk3+BtLY+L/b7G4knGrSWs+3T+NSoIa74JZEVqvI5jz0PiH/G7Ci2xCD5Sk+A7Jh yfhwoZ6SRkd7EQgyEntv5KGRzVjpVGkyP06NHz7eRw5twSlUc2pRbVpe87Wiebuf+33V KK6LYb/nr3i05ty6hJMFdxDiBh7P3A9KbFOAgANOatq8O6UyQG7tpfgrZX2vI7REL2g+ bjSA== 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 e8si768281oiy.103.2020.03.13.17.00.16; Fri, 13 Mar 2020 17:00:28 -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 S1728152AbgCMX6e (ORCPT + 99 others); Fri, 13 Mar 2020 19:58:34 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:49946 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbgCMXx7 (ORCPT ); Fri, 13 Mar 2020 19:53:59 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCu7p-00B6YH-7p; Fri, 13 Mar 2020 23:53:57 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Linus Torvalds Subject: [RFC][PATCH v4 01/69] do_add_mount(): lift lock_mount/unlock_mount into callers Date: Fri, 13 Mar 2020 23:52:49 +0000 Message-Id: <20200313235357.2646756-1-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200313235303.GP23230@ZenIV.linux.org.uk> References: <20200313235303.GP23230@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro preparation to finish_automount() fix (next commit) Signed-off-by: Al Viro --- fs/namespace.c | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index 85b5f7bea82e..dcd015fafe01 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2697,45 +2697,32 @@ static int do_move_mount_old(struct path *path, const char *old_name) /* * add a mount into a namespace's mount tree */ -static int do_add_mount(struct mount *newmnt, struct path *path, int mnt_flags) +static int do_add_mount(struct mount *newmnt, struct mountpoint *mp, + struct path *path, int mnt_flags) { - struct mountpoint *mp; - struct mount *parent; - int err; + struct mount *parent = real_mount(path->mnt); mnt_flags &= ~MNT_INTERNAL_FLAGS; - mp = lock_mount(path); - if (IS_ERR(mp)) - return PTR_ERR(mp); - - parent = real_mount(path->mnt); - err = -EINVAL; if (unlikely(!check_mnt(parent))) { /* that's acceptable only for automounts done in private ns */ if (!(mnt_flags & MNT_SHRINKABLE)) - goto unlock; + return -EINVAL; /* ... and for those we'd better have mountpoint still alive */ if (!parent->mnt_ns) - goto unlock; + return -EINVAL; } /* Refuse the same filesystem on the same mount point */ - err = -EBUSY; if (path->mnt->mnt_sb == newmnt->mnt.mnt_sb && path->mnt->mnt_root == path->dentry) - goto unlock; + return -EBUSY; - err = -EINVAL; if (d_is_symlink(newmnt->mnt.mnt_root)) - goto unlock; + return -EINVAL; newmnt->mnt.mnt_flags = mnt_flags; - err = graft_tree(newmnt, parent, mp); - -unlock: - unlock_mount(mp); - return err; + return graft_tree(newmnt, parent, mp); } static bool mount_too_revealing(const struct super_block *sb, int *new_mnt_flags); @@ -2748,6 +2735,7 @@ static int do_new_mount_fc(struct fs_context *fc, struct path *mountpoint, unsigned int mnt_flags) { struct vfsmount *mnt; + struct mountpoint *mp; struct super_block *sb = fc->root->d_sb; int error; @@ -2768,7 +2756,13 @@ static int do_new_mount_fc(struct fs_context *fc, struct path *mountpoint, mnt_warn_timestamp_expiry(mountpoint, mnt); - error = do_add_mount(real_mount(mnt), mountpoint, mnt_flags); + mp = lock_mount(mountpoint); + if (IS_ERR(mp)) { + mntput(mnt); + return PTR_ERR(mp); + } + error = do_add_mount(real_mount(mnt), mp, mountpoint, mnt_flags); + unlock_mount(mp); if (error < 0) mntput(mnt); return error; @@ -2830,6 +2824,7 @@ static int do_new_mount(struct path *path, const char *fstype, int sb_flags, int finish_automount(struct vfsmount *m, struct path *path) { struct mount *mnt = real_mount(m); + struct mountpoint *mp; int err; /* The new mount record should have at least 2 refs to prevent it being * expired before we get a chance to add it @@ -2842,7 +2837,13 @@ int finish_automount(struct vfsmount *m, struct path *path) goto fail; } - err = do_add_mount(mnt, path, path->mnt->mnt_flags | MNT_SHRINKABLE); + mp = lock_mount(path); + if (IS_ERR(mp)) { + err = PTR_ERR(mp); + goto fail; + } + err = do_add_mount(mnt, mp, path, path->mnt->mnt_flags | MNT_SHRINKABLE); + unlock_mount(mp); if (!err) return 0; fail: -- 2.11.0