Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1618651ybf; Sun, 1 Mar 2020 13:57:51 -0800 (PST) X-Google-Smtp-Source: ADFU+vshvncuJDaRGAmQMh/IYPRljXZ1dlM+bZmsZnxVoNeXraw+hv/UhhMifypP2OGW6yKKZ4Fu X-Received: by 2002:aca:130c:: with SMTP id e12mr1714255oii.6.1583099871422; Sun, 01 Mar 2020 13:57:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583099871; cv=none; d=google.com; s=arc-20160816; b=HvSkn1A7auiE3DBZEOZnPaFSlpcF9LOp4RUoSqQsTdVY1bSxHmnG58udz2XsFmMeGq 7HTv+1l+OOnDF5nbVi0FcQNWdWcZBVpeZupZmrorik9Am11mQ3o0Q6pzbZ+o32gQIB7l WspS+mNJXgWcm2NqKI1O7CvaCVkaZugWVlu+ny+ofuMbBTo1/n7kHkdqdZ1pfO+zzUE0 UAWBEjZuk4op35LK0SvkE3kxZw3pkZSrqyNPQlVRpS6qkc/rpdi8AasAnXj5P4U4zwhH /QdG+6eRe4aC/2c3Hl1yklnATjZa6XUuZF0V8kj5rtgUxIk0Id4lMojybiLE9jkpzZR6 FMdA== 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=yiWm3i7jmZoMW97RWuZhyWKb6Yd+bd3FMxIqipxKnOuqHrmCygHunWUIXDdqJfS+Y+ Nltwd0Hpwk3MLqP6K9sGUdXOUXXjJ0BtJq+sqQRPVxeTQ6VI1U4L9nkPZJXY2Q1g7auN EGcctXyFSRSTCPV2JMfjVRudgj5P66NUTzh+ndX7Ih9NWhg2Ii1AqpPBK1RStd3MxQt5 lAxVgoyp4vHutk7i7NmbozmDztcOAt56rxhR2UwZJ4SE4lN9BbrIOiaL37SKvwRfwdnz uvM8i/ioeCl9Jbk/8BWObn4ZFXJS45Grr4UARk9fKQgs8+sDIadtz+MTQ15559NKO0gz UvtA== 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 t12si4201171oih.257.2020.03.01.13.57.39; Sun, 01 Mar 2020 13:57:51 -0800 (PST) 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 S1726688AbgCAVwl (ORCPT + 99 others); Sun, 1 Mar 2020 16:52:41 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:41544 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726050AbgCAVwl (ORCPT ); Sun, 1 Mar 2020 16:52:41 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j8WVs-003fLp-7h; Sun, 01 Mar 2020 21:52:40 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Linus Torvalds Subject: [RFC][PATCH v3 01/55] do_add_mount(): lift lock_mount/unlock_mount into callers Date: Sun, 1 Mar 2020 21:51:46 +0000 Message-Id: <20200301215240.873899-1-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200301215125.GA873525@ZenIV.linux.org.uk> References: <20200301215125.GA873525@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