From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3B682D5425 for ; Wed, 3 Sep 2025 04:55:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756875345; cv=none; b=IeUs4oDLgyqcbV2N5Cd/kCQi7Z/bo0Z4iGE8fNbqEo+rMixeQO7fWWaaAtO14QkrL6QYmAysWwMXdZOYqRK51PduGigRKYtAqwjsnsfKvYwR5Y/mvc3JvIL4pUTi2pvhoR9SJXsC8cqCOwGYH8d/ir4Vhq2a5BoyPrcJmm/+lGU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756875345; c=relaxed/simple; bh=Q7p4SD142cFbXzyNxdrTt5RZGRMFM9SysR498AfP8Ok=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ui7++lZNS3SINsSTkFqavsu2eNOzd6AuO7zw7SxlBDgvNtO7TJHJ3dIbbG2lyYVtYoRFQQjjBax/z2Le7ogYU82dPMZIWc2JkipjuqCf5M2ESkzTsxDlbW0g91j9XqdFJhwmasrdP8t8/tAcHrdihO8YU9INRuR30xMWcrV/Yoc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=RMmFUlNG; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="RMmFUlNG" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=njWj+GcfEyRq+frFnQ6t2M9QiISsKg7YGVKp2sWhKSI=; b=RMmFUlNGZAykYJJt/L9VCczf3T Qn66Yo0gxtP62euQlO/E4J/UFKzwteafSANKJdBzCuiFKclkJkMFjZ+Uk2Vwu5sYNsFlZw1dgcnZD WbX+znUqqMhkdNvOM/I6zs7cKRNl1vMcgPRSF7wtpYRwe8Zd8kXo5LHNVjqJI+nACy075IYo03oMm thQmpxb3R9j1rujACWJrarkkvB50brq4+mMtb9rS4JykXn55FnNQlbu9+oUdAKGPNc2rdFUcKULjC Xpnjxs9I9rnqqW4kIhHm9lbA5jo1jell4+1BobbAnlhx1MTUGSMC/USaT45Xg8/svsGzcAaD6+4r0 WJ+X4Grg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.98.2 #2 (Red Hat Linux)) id 1utfX2-0000000Ap86-3mAn; Wed, 03 Sep 2025 04:55:40 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: brauner@kernel.org, jack@suse.cz, torvalds@linux-foundation.org Subject: [PATCH v3 18/65] switch do_new_mount_fc() to fc_mount() Date: Wed, 3 Sep 2025 05:54:39 +0100 Message-ID: <20250903045537.2579614-18-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250903045537.2579614-1-viro@zeniv.linux.org.uk> References: <20250903045432.GH39973@ZenIV> <20250903045537.2579614-1-viro@zeniv.linux.org.uk> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Al Viro Prior to the call of do_new_mount_fc() the caller has just done successful vfs_get_tree(). Then do_new_mount_fc() does several checks on resulting superblock, and either does fc_drop_locked() and returns an error or proceeds to unlock the superblock and call vfs_create_mount(). The thing is, there's no reason to delay that unlock + vfs_create_mount() - the tests do not rely upon the state of ->s_umount and fc_drop_locked() put_fs_context() is equivalent to unlock ->s_umount put_fs_context() Doing vfs_create_mount() before the checks allows us to move vfs_get_tree() from caller to do_new_mount_fc() and collapse it with vfs_create_mount() into an fc_mount() call. Reviewed-by: Christian Brauner Signed-off-by: Al Viro --- fs/namespace.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index 0474b3a93dbf..9b575c9eee0b 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -3705,25 +3705,20 @@ static bool mount_too_revealing(const struct super_block *sb, int *new_mnt_flags static int do_new_mount_fc(struct fs_context *fc, struct path *mountpoint, unsigned int mnt_flags) { - struct vfsmount *mnt; struct pinned_mountpoint mp = {}; - struct super_block *sb = fc->root->d_sb; + struct super_block *sb; + struct vfsmount *mnt = fc_mount(fc); int error; + if (IS_ERR(mnt)) + return PTR_ERR(mnt); + + sb = fc->root->d_sb; error = security_sb_kern_mount(sb); if (!error && mount_too_revealing(sb, &mnt_flags)) error = -EPERM; - - if (unlikely(error)) { - fc_drop_locked(fc); - return error; - } - - up_write(&sb->s_umount); - - mnt = vfs_create_mount(fc); - if (IS_ERR(mnt)) - return PTR_ERR(mnt); + if (unlikely(error)) + goto out; mnt_warn_timestamp_expiry(mountpoint, mnt); @@ -3731,10 +3726,12 @@ static int do_new_mount_fc(struct fs_context *fc, struct path *mountpoint, if (!error) { error = do_add_mount(real_mount(mnt), mp.mp, mountpoint, mnt_flags); + if (!error) + mnt = NULL; // consumed on success unlock_mount(&mp); } - if (error < 0) - mntput(mnt); +out: + mntput(mnt); return error; } @@ -3788,8 +3785,6 @@ static int do_new_mount(struct path *path, const char *fstype, int sb_flags, err = parse_monolithic_mount_data(fc, data); if (!err && !mount_capable(fc)) err = -EPERM; - if (!err) - err = vfs_get_tree(fc); if (!err) err = do_new_mount_fc(fc, path, mnt_flags); -- 2.47.2