fs: Establish locking order for unrelated directories
authorJan Kara <jack@suse.cz>
Thu, 1 Jun 2023 10:58:24 +0000 (12:58 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Jul 2023 14:22:12 +0000 (16:22 +0200)
commit10c159f994b985cf0c8b8eb8b851ae9d46a820a8
tree1707715a1f149e9cd70309a8a04aa27dd9596879
parent6654d2a165e4f36f68a20b9fe988874c4ea1c9da
fs: Establish locking order for unrelated directories

commit f23ce757185319886ca80c4864ce5f81ac6cc9e9 upstream.

Currently the locking order of inode locks for directories that are not
in ancestor relationship is not defined because all operations that
needed to lock two directories like this were serialized by
sb->s_vfs_rename_mutex. However some filesystems need to lock two
subdirectories for RENAME_EXCHANGE operations and for this we need the
locking order established even for two tree-unrelated directories.
Provide a helper function lock_two_inodes() that establishes lock
ordering for any two inodes and use it in lock_two_directories().

CC: stable@vger.kernel.org
Signed-off-by: Jan Kara <jack@suse.cz>
Message-Id: <20230601105830.13168-4-jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/inode.c
fs/internal.h
fs/namei.c